For better accuracy on the strategy tester it is best to just use:
Close[0]
- www.mql5.com
I am going to assume the spread is 0 in this instance, for better accuracy on the strategy tester it is best to just use:
The trade isn't executing because as far as I am aware this is the only indicator you have provided:
You need an extra set of indicators under iBands:
If you understand how Bollinger bands work, you would know that 2 standard deviations above or below current price is closer to price than 3 standard deviations.
I use the strategy tester for this, and set the spread to current for the trading pair.
This was an example of 3SD which does not open trades. When I use 2SD (like in the code posted in this post), the trade execution is hit or miss (mostly miss).
Also, isnt using Close[0] the close of that bar? This is not what I want. I want to execute the trade based on the live price of the bid.
Nonetheless, I have used Close[0], issue still persists.
- You have slippage set to zero. Hit or miss whether it will open any orders.
- Without checking whether orders are already open or a new bar, your code should open one order per tick once the condition has been met.
1. I have just added slippage of 20, and the issue still persists.
2. This is an excerpt of the code. I have included whether trades are open using the magic number in the full code, ensuring only 1 trade opens. I have also done it by checking if a order of the same symbol is open. Still the issue persists.
I use the strategy tester for this, and set the spread to current for the trading pair
This was an example. When I use 3 SD, this is when my problem occurs
So as of this moment you do know that the bid and ask prices on your broker are very wide and start to narrow after 23:00 UTC ? Meaning if you run the strategy tester using your brokers current spread between 22:00 & 23:00 UTC, if you see that price is above the upper bound and it is not executing, the bid price depending on the spread may be below the upper bound ?
So as of this moment you do know that the bid and ask prices on your broker are very wide and start to narrow after 23:00 UTC ? Meaning if you run the strategy tester using your brokers current spread, if you see that price is above the upper bound and it is not executing, the bid price depending on the spread may be below the upper bound ?
Yes, I understand this. I either use the current spread, or I set it using the predefined numbers in the ST that is close to the usual floating spread given.
"if you see that price is above the upper bound and it is not executing, the bid price depending on the spread may be below the upper bound ?" please elaborate on this, because I have used Close[0], and the issue still persists.
For example if the bid and ask is 1.01/1.10. Your current upper bound is 1.12. If the current price is above 1.12, the bid would be 1.03, the current spread of the Bid & Ask between the timings 22:00- 23:00 UTC is so wide that the Bid price is lower than the upper bound when in fact you visually see the price above the upperbound.
You can try this code.
if ((Hour() >= 4) && (Hour() < 21)) if ( Close[0] > upband ) { { int sellOrder = OrderSend(Symbol(), OP_SELL, 0.01,Bid,0,0,Ask-(n),"sell order baby",MAGICSELL,0,0); } } if((Hour() >= 4) && ( Hour() < 21)) if (Close[0] < lowerband){ { int buyOrder = OrderSend(Symbol(), OP_BUY, 0.01,Ask,0,0,Bid+(n),"buy order baby",MAGICBUY,0,0); //--n being the pip amount --// } }
I use the strategy tester for this, and set the spread to current for the trading pair.
This was an example of 3SD which does not open trades. When I use 2SD (like in the code posted in this post), the trade execution is hit or miss (mostly miss).
Also, isnt using Close[0] the close of that bar? This is not what I want. I want to execute the trade based on the live price of the bid.
Nonetheless, I have used Close[0], issue still persists.
Close[0] is current Bid Price, OR the bid price of the current candle if it were to close on current tick.
Close[1] is the final bid price of the first closed candle.
Any moderators care to correct me?For example if the bid and ask is 1.01/1.10. Your current upper bound is 1.12. If the current price is above 1.12, the bid would be 1.03, the current spread of the Bid & Ask between the timings 22:00- 23:00 UTC is so wide that the Bid price is lower than the upper bound when in fact you visually see the price above the upperbound.
You can try this code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
However, the larger the deviation (above 2, going to 3), the longer the delay in execution. Sometimes the trade executes 5, 10 minutes later.
Sometimes, when the Bid price is above/below the deviation level, the trade doesn't even execute (I have attached an image showign this).
Sample code is below. Please note this issu is occuring whether I am using OnTick(), or OnTimer().
Thank you in advance.