Why MathAbs() in the buy but not in the sell?
Also with your use of the explicit ">" and "<" you are not allowing for the conditions where the values are equal "=". I recommend you use ">=" and "<=" where appropriate unless you really intend for your EA to take no action when value are "==" (and then be aware that the EA truly won't take action at those times when the values are equal).
extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; bool buycond=true; bool sellcond=true; extern double takeprofit = 150; extern double MACDOpenLevel=20; extern double MACDCloseLevel=5; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- condition(); close(); //---- return(0); } //+------------------------------------------------------------------+ //| function for analysing conditions and opening order!!!! | //+------------------------------------------------------------------+ void condition() { double MacdCurrent, MacdPrevious, SignalCurrent; double SignalPrevious, MaCurrent, MaPrevious, TPB,TPS; int cnt, ticket, total; TPB=NormalizeDouble(Ask+takeprofit*(Point*10),5); TPS=NormalizeDouble(Bid-takeprofit*(Point*10),5); MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1); SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0); SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); MaCurrent=iMA(NULL,0,9,0,MODE_EMA,PRICE_CLOSE,0); MaPrevious=iMA(NULL,0,9,0,MODE_EMA,PRICE_CLOSE,1); if(MacdCurrent>=SignalCurrent && MacdPrevious<=SignalPrevious && buycond==true && MathAbs(MacdCurrent)>(MACDOpenLevel*Point)){ OrderClose(OrderTicket(),OrderLots(),Ask,3,White); ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,TPB,"macd sample",19861227,0,Red); buycond=false; sellcond=true; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); Alert("BUY"); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(MacdCurrent<=SignalCurrent && MacdPrevious>=SignalPrevious && sellcond==true && MacdCurrent>(MACDOpenLevel*Point)) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Gold); ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,TPS,"macd sample",19861227,0,Blue); sellcond=false; buycond=true; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); Alert("SELL"); } else Print("Error opening SELL order : ",GetLastError()); return(0); } } void close() { double MacdCurrent, MacdPrevious, SignalCurrent; double SignalPrevious, MaCurrent, MaPrevious; /* double ma; //---- get Moving Average ma=iMA(NULL,0,9,0,MODE_EMA,PRICE_CLOSE,0); */ for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=19861227 || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { if(MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious){// && MacdCurrent>(MACDCloseLevel*Point)) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);} Comment("closing buy"); break; } if(OrderType()==OP_SELL) { if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious){// && MathAbs(MacdCurrent)>(MACDCloseLevel*Point)) OrderClose(OrderTicket(),OrderLots(),Ask,3,Gold);} Comment("closing sell"); break; } } }
May I know which currency we see at the attached picture & what TF
May I know which currency we see at the attached picture & what TF
Eur/Usd, M30.
Sir can you tell why these problems are coming???
Why doesn't EA place an order when it is supposed to ?
I'm sorry, I've been awake over 24 hours and I can't concentrate on your calculation, if you want to explain the calculation when to buy and when to sell I will try to go over on this again
The calculations are simple.
if( current macd line goes above current signal line && currentmacd is greater than macd open level){BUY}
if(current macd line is below current signal line && currentmacd is greater than macd open level){SELL}
But it misses crucial positions!!!
Can anyone please tell me why it does not consider the crossovers?
the test is for Eur/Usd M30.
Thanks

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm writing an EA based on MACD. Though it is based on MA, MACD is quite different, as you people.
I've put following conditions...
The problem I'm facing is, even though it opens and closes order, it misses some. Like in these cases....
Can someone please explain me why??? I tried reading MACD documentation but couldn't get it....
Thank you in advance.
Rohit.