//+------------------------------------------------------------------+ //| sell.mq4 | //| Copyright © 2008, Silas Palmer. | //| http://www.silaspalmer.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Silas Palmer." #property link "http://www.silaspalmer.com" #include #include // #property show_confirm // Uncomment to enable confirmation //+------------------------------------------------------------------+ //| script "sell at market, using money management as defined below" | //+------------------------------------------------------------------+ int start() { // Change these amounts to suit your needs int lotbucks = 50000; // 1 lot for every x dollars in your account. int Slippage = 3; // Standard amount // Note script auto-detects minimum lot size // It also automatically scales lots based on currency pair // (so that a 1 pip move will be $1 per lotbuck regardless of the pair chosen) //---- int cmd = -1; // Nothing (buy=0 sell=1) int i; double lots,minl,maxl,pipbucks,step; // Calculate lots pipbucks = MarketInfo(Symbol(),MODE_TICKVALUE); minl = MarketInfo(Symbol(),MODE_MINLOT); maxl = MarketInfo(Symbol(),MODE_MAXLOT); step = MarketInfo(Symbol(),MODE_LOTSTEP); // Scale lots so 1 pip = $1 at 1 lot lots = MathFloor( (((10 / pipbucks) * AccountFreeMargin()) / lotbucks) / step) * step; if (lots < minl) lots = minl; if (lots > maxl) lots = maxl; // sell if ( OrderSend( Symbol(), OP_SELL, lots, Bid, Slippage, 0, 0, "Opened Buy Order", 0, 0, Yellow ) > 0 ) Print ( "Opened Sell Order at ",Bid ); else Alert ( "Could not open Sell order for ", Symbol(), " ", lots, " at ", Bid, " Error=", ErrorDescription(GetLastError()) ); //---- return(0); } //+------------------------------------------------------------------+