//+------------------------------------------------------------------+ //| MA envelope exhausting system | //+------------------------------------------------------------------+ #property copyright "TraderSeven" //----------------------- USER INPUT extern double MA_length = 10; extern double slip = 0; extern double Lots = 1; extern double TakeProfit = 30; extern double Stoploss = 2000; //extern double TrailingStop = 5; extern double PipStep = 30; //----------------------- SETUP VARS double PriceTarget; double AveragePrice; double LastPrice; int flag; //----------------------- MAIN PROGRAM LOOP int start() { int cnt=0, total; double Stopper=0; total=OrdersTotal(); OrderSelect(total, SELECT_BY_POS, MODE_TRADES); LastPrice=OrderOpenPrice(); OrderSelect(total, SELECT_BY_POS, MODE_TRADES); flag=0; if(iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*1.02=(LastPrice+(PipStep*Point)))||(total<1)) // Go SHORT -> Only sell if >= 30 pips above previous position entry { OrderSend(Symbol(),OP_SELL,Lots,Bid,slip,Bid+(Stoploss*Point),Bid-(TakeProfit*Point),0,0,HotPink); if(total>0)flag=1; } if(iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*0.98>Ask && (Ask<=(LastPrice-(PipStep*Point)))||total<1) // Go LONG -> Only buy if >= 30 pips below previous position entry { OrderSend(Symbol(),OP_BUY,Lots,Ask,slip,Ask-(Stoploss*Point),Ask+(TakeProfit*Point),0,0,Lime); if(total>0)flag=1; } //----------------------- CALCULATE AVERAGE OPENING PRICE total=OrdersTotal(); AveragePrice=0; for(cnt=0;cnt