[F]or sell order, the Ask price shoud be equal or higher the stop loss to trigger it?
Yes. A stop order converts to a market order when triggered. Remember, the idea of a stop is to get out urgently. Slippage and delay can be manipulated in the Tester, of course.
In contrast, a limit order does exactly that--limit execution to at or better than... assuming that your limit order can get filled.
As Every tick based on real ticks and Every tick [generated] can't be exactly the same all of the time, I would be interested to see what happens when you demo test your code.I found an Article dedicated to accurate backtesting:
"The pursuit of reliable back-test results in algorithmic trading hinges not only on robust strategy logic but also on the efficiency and precision of the underlying code. Raw code optimization and tweaking are critical to ensuring that Expert Advisors (EAs) perform as intended, minimizing computational overhead while maximizing execution accuracy. Poorly optimized code can distort back-test outcomes through delayed order execution, incorrect signal detection, or resource exhaustion—issues that mask a strategy’s true potential."
"Two MqlTick structures—`CTick` and `PTick`—are employed to track real-time price data, ensuring precision in execution timing and market condition analysis."
Raw Code Optimization and Tweaking for Improving Back-Test Results
Hlomohang John Borotho, 2025.05.09 11:55
Enhance your MQL5 code by optimizing logic, refining calculations, and reducing execution time to improve back-test accuracy. Fine-tune parameters, optimize loops, and eliminate inefficiencies for better performance.int copiedTicks=CopyTicksRange(GetSymb(),mqlTick,COPY_TICKS_INFO,(ulong) start * 1000);
Did you check that you got the correct ticks for the considered bar ?
Are you this log you posted is using Every ticks (real or generated) ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Testing an EA that has the following function called in OnTrade() event. The goal of the function is to find the highest Ask price for the current bar. Later I want to extend the function so I could get the Ask Price for any bar back in history and use it in an indicator
Having a Sell order for which stop loss is triggered. Here are the logs:
Question: Why is the stoploss triggered at price 1.17406, yet the maxAsks for the current bar is still 1.17398? AFAIK, for sell order, the Ask price shoud be equal or higher the stop loss to trigger it?
Tested both with Modelling : Every tick based on real ticks and Every tick, same results