This EA takes a short trade when price is below the MA band. What i want it to do is to wait x amount of pips before it takes the trade e.g. 40 pips as a filter.
Does anyone knows how to do this?
In the code you can see i have tried a few things, but it doesn't work.
//double PriceNow = Bid;
//if ((Close[1] < iMA(NULL, NULL,55,0,MODE_EMA,PRICE_CLOSE,1)) && (PriceNow < PriceNow-PriceOffset*Point))
Here is the code:
Does anyone knows how to do this?
In the code you can see i have tried a few things, but it doesn't work.
//double PriceNow = Bid;
//if ((Close[1] < iMA(NULL, NULL,55,0,MODE_EMA,PRICE_CLOSE,1)) && (PriceNow < PriceNow-PriceOffset*Point))
Here is the code:
PHP Code
//---- input parameters extern double TakeProfit=2000; //100pips extern double StopLoss = 400; //10pips extern double Lots=1; extern double PriceOffset = 400; //40pips bool TradeOpenAllowed=false; int MagicNumber=12345; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if(Bars<100) { Print("bars less than 100"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); // check TakeProfit } //double PriceNow = Bid; //if ((Close[1] < iMA(NULL, NULL,55,0,MODE_EMA,PRICE_CLOSE,1)) && (PriceNow < PriceNow-PriceOffset*Point)) if (Close[1] < iMA(NULL, NULL,55,0,MODE_EMA,PRICE_CLOSE,1)) { if (TradeOpenAllowed) { //int ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"EMA",MagicNumber,0,Green); int ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,0,0,"EMA",MagicNumber,0,Green); if(ticket>=0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { OrderModify(ticket,0,OrderOpenPrice()+StopLoss*Point,OrderOpenPrice()-TakeProfit*Point,0,0); //Print("SELL order opened : ",OrderOpenPrice()); TradeOpenAllowed=false; //Don't allow further trades on this signal } } else { Print("Error opening SELL order : ",GetLastError()); } } else { //Allow new trades when price above MA and last trade has closed if (getOpenOrders()==0) TradeOpenAllowed=true; if (Close[1] > iMA(NULL, NULL,55,0,MODE_EMA,PRICE_CLOSE,1)) CloseAll(3, 12345); } } } int getOpenOrders() { int myOrders = 0; for (int i = OrdersTotal()-1; i >=0 ; i--) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) myOrders++; } return(myOrders); } void CloseAll(int Slippage, int MagicNumber) { bool closed; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); while(IsTradeContextBusy()) Sleep(100); RefreshRates(); if (OrderType() == OP_BUY && MagicNumber == OrderMagicNumber()) { closed = OrderClose(OrderTicket(),OrderLots(), NormalizeDouble(MarketInfo(OrderSymbol(), MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS)),Slippage,White); } if (OrderType() == OP_SELL && MagicNumber == OrderMagicNumber()) { closed = OrderClose(OrderTicket(),OrderLots(), NormalizeDouble(MarketInfo(OrderSymbol(), MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),Slippage,White); } } }
Blindly following others will make you blind!