Hope this helps
1. try restarting your the mtq4 editor and meta trader, probably a wifi or a network issue on your part or the broker.
2. just use a fixed stop loss so you dont have to worry of updating it. also I saw that you put " ; " on the end of the if statement, try removing that one out might solve the errors your getting, this also apply to issue number 3 on your errors. Also since it say the error on line (154,79), try moving the lines on (154,79) on a different line of the code.
if(Ask > MA_1 > MA_2 && PDL < 0.0004) //long
This doesn't do what you think it does.
True = non-zero and false = zero so you get:
if( 3 < 2 < 1 ) if( false < 1 ) if( 0 < 1 ) if( true ) | if( 3 > 2 > 1 ) if( true > 1 ) if( 1 > 1 ) if( false ) |
Hi thank you for your reply, I'm still a bit new to this programming thing, would you mind explaining further?
You can usually test by speaking your boolean test out loud and if it sounds strange it is probably wrong.
if(Bid < MA_1 < MA_2 && PDS < 0.0004)
"If bid is smaller than MA_1 is smaller than MA_2 and PDS is smaller than 0.0004" sounds odd, does it not?
So what does it mean?
Is it
"If bid is smaller than MA_1 and MA_1 is smaller than MA_2 and PDS is smaller than 0.0004"
or is it
"If bid is smaller than MA_1 and bid is smaller than MA_2 and PDS is smaller than 0.0004"
?
These 2 you can read out loud and they don't sound odd.
if(Bid < MA_1 && MA_1 < MA_2 && PDS < 0.0004)
if(Bid < MA_1 && Bid < MA_2 && PDS < 0.0004)
You can usually test by speaking your boolean test out loud and if it sounds strange it is probably wrong.
"If bid is smaller than MA_1 is smaller than MA_2 and PDS is smaller than 0.0004" sounds odd, does it not?
So what does it mean?
Is it
"If bid is smaller than MA_1 and MA_1 is smaller than MA_2 and PDS is smaller than 0.0004"
or is it
"If bid is smaller than MA_1 and bid is smaller than MA_2 and PDS is smaller than 0.0004"
?
These 2 you can read out loud and they don't sound odd.
Hi Keith, thanks, it all makes sense now. The EA now takes orders automatically, but issue 1 and 3 still persist. Once the trade had been closed automatically, and another trade parameter has been met, my EA won't take the trade for some unknown reason. Basically my EA acts more like a script that an EA, working only once then that's it. Any advice would be much appreciated
if(!CheckIfOpenOrdersByMagicNB(magicNB))//if no open orders try to enter new position { if(Open[1] > MA_1 && Close[1] > MA_1 && MA_1 > MA_2) //long { Print("Price is above the two MA's, Sending buy order"); double stopLossPrice = NormalizeDouble(MA_1,Digits); double takeProfitPrice = NormalizeDouble(bbUpperProfitExit,Digits); Print("Entry Price = " + Ask); Print("Stop Loss Price = " + stopLossPrice); Print("Take Profit Price = " + takeProfitPrice); double lotSize = OptimalLotSize(riskPerTrade,Ask,stopLossPrice); openOrderID = OrderSend(NULL,OP_BUY,lotSize,Ask,10,stopLossPrice,takeProfitPrice,NULL,magicNB); if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError()); } else if(Open[1] < MA_1 && Close[1] < MA_1 && MA_1 < MA_2) //shorting { Print("Price is below the two MA's, Sending short order"); double stopLossPrice = NormalizeDouble(MA_1,Digits); double takeProfitPrice = NormalizeDouble(bbLowerProfitExit,Digits); Print("Entry Price = " + Bid); Print("Stop Loss Price = " + stopLossPrice); Print("Take Profit Price = " + takeProfitPrice); double lotSize = OptimalLotSize(riskPerTrade,Bid,stopLossPrice); openOrderID = OrderSend(NULL,OP_SELL,lotSize,Bid,10,stopLossPrice,takeProfitPrice,NULL,magicNB); if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError()); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm a beginner in mql4 and currently practicing in creating a forex bot. I created this simple bot with the strategy of convergence of the 10/20 day EMA, I have no problem in compiling it but when it comes to using it on a demo account, I had the ff issues:
1. sometimes my EA takes a trade, and sometimes it doesn't, even though requirements to take a trade were met.
Scenario A. EA doesn't take the trade even though the requirements in the chart were met
Scenario B. if the EA does take the trade, and got stopped out, once another trade requirement was met, it does not take it.
2. stop loss and TP sometimes won't update.
Same scenario occurs with my first issue, sometimes it updates the SL and sometimes it don't.
3. During back testing, I immediately got an error " zero divide in 'FUNCTIONS COMPILATION 10_19_22.mqh' (154,79)". I don't understand this error, because I was using the same exact include file on a different strategy, and it works just fine, but in this strategy that I created gives out the said error.
Please see EA code below and include file attached.