Dear Mohammad ...
It could be the lack of considering the condition when distances for sl and tp are too tight !.
You have to include a condition of minimum distance for sl and tp ...
This way, it may be work or at least it solves the condition when the price ranges are too tight.
Dear Mohammad ...
It could be the lack of considering the condition when distances for sl and tp are too tight !.
You have to include a condition of minimum distance for sl and tp ...
This way, it may be work or at least it solves the condition when the price ranges are too tight.
I test the EA on Daily time frame so I think it is very hard to have such a case where the difference between the upper and lower bands is too tight.
I think the problem is in the TP and SP or in the logic of the EA.
Something interesting happened while I try to solve the problem. When I set Stop Loss for long and short OrderSend function to Zero the EA freeze in the test at the same point, but when I set the Take Profit for long and short to Zero the EA completed the test without freezing.
Your problem is definitely going to be in your while loops and I'd suggest it would be an order send error related to your SL and/or TP. What errors are reported in your log?
The first thing I would try would be to Normalize all of the doubles in the order send function to the correct decimal places (lots, sl, tp etc)
iBands(....
Returns:
Numerical value of the Bollinger Bands® indicator.
//---Open BUY Orders for 1st time if(Time[0]!=cur_open) if(Close[1] < UpperBBand(1) && Close[1] > CenterBBand(1)) { ticket=-1; while(ticket<0) { Print("spl: ",spl," tpl: ",tpl); ticket = OrderSend(Symbol(),OP_BUY , lots, enl, UserSlippage,spl,tpl, UserComment, MagicNumber, 0, clrGreen); if(ticket<0) Sleep(500); else cur_open=Time[0]; } } //---Open SELL Orders for 1st time if(Time[0]!=cur_open) if(Close[1] > LowerBBand(1) && Close[1] < CenterBBand(1)) { ticket=-1; while(ticket<0) { Print("spl: ",spl," tpl: ",tpl); ticket = OrderSend(Symbol(),OP_SELL , lots, ens, UserSlippage,sps,tps, UserComment, MagicNumber, 0, clrRed); if(ticket<0) Sleep(500); else cur_open=Time[0]; } }
I test the EA on Daily time frame so I think it is very hard to have such a case where the difference between the upper and lower bands is too tight.
I think the problem is in the TP and SP or in the logic of the EA.
One price gap is enough to freeze your EA.
Start the tester in visual mode, it will stop at the wrong entry. So, you will be able to figure out the problem.
Also it would be better to break the while loop after "x" attempts and Print out the error if the Ordersend fails.
One price gap is enough to freeze your EA.
Start the tester in visual mode, it will stop at the wrong entry. So, you will be able to figure out the problem.
Also it would be better to break the while loop after "x" attempts and Print out the error if the Ordersend fails.
Is right it is a very forceful way to open an order.
The output of the iBands indicator does not change that fast.
//---Open BUY Orders for 1st time if(Time[0]!=cur_open) { if(Close[1]<UpperBBand(1) && Close[1]>CenterBBand(1)) { //Print("spl: ",spl," tpl: ",tpl); { ticket=OrderSend(Symbol(),OP_BUY,lots,enl,UserSlippage,spl,tpl,UserComment,MagicNumber,0,clrGreen); { if(ticket>0) { cur_open=Time[0]; } } } } } //---Open SELL Orders for 1st time if(Time[0]!=cur_open) { if(Close[1]>LowerBBand(1) && Close[1]<CenterBBand(1)) { //Print("spl: ",spl," tpl: ",tpl); { ticket=OrderSend(Symbol(),OP_SELL,lots,ens,UserSlippage,sps,tps,UserComment,MagicNumber,0,clrRed); { if(ticket>0) { cur_open=Time[0]; } } } } } //+------------------------------------------------------------------+
It will try to place an order at every new tick for as long as the conditions are met.
And it has been said look at the output journal to see the error code it should be there telling you what went wrong.
Thanks a lot for your help.I have learned something new about MQL4 programing from you.

- 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 am new to MQL4 programing. I build an EA that trade a simple Bollinger Band System but when I test the EA with MT4 System tester it freeze. I tried to find the problem and I think that it is in the way I use Bollinger Bands as Stop-Loss & Take Profit.
I appreciate if any friend can solve this problem.
---------------------------------------------------------------
The system is like this:
1- If close is between upper & center Bollinger Bands (BB) then buy long on the open of the next candle.
2- If close is in between the center & the lower BB then sell short at the open of the next candle.
3- For long positions use upper BB of the previous candle as target & for short positions use lower BB.
4- For long positions use lower BB of previous candle as stop loss & for short positions use upper BB.
---------------------------------------------------------------
Here is the EA code where I think the problem is from take profit & stop loss coding which I want somebody to help me to fix it.
I attach it here too.