"the Hidden Trailing Stop i tried to code doesn't work in live, it works well in strategy
tester using "open prices only" but using "every tick" fails.
it just opens one order and close it instantaneously...."
I think it is best you post the entire actual code you are using, because that will help us find the problem. Then again,
that is a personal decision and I really should not demand to see your actual code. Therefore, I can only give my best guess based on whats likely
causing this.
Now, the strategy tester has several settings for spread to use during backtest, which you will find just above the "Optimization"
checkbox. It is likely that you may have intentionally or unintentionally, set this to use a constant spread while backtesting.
This means that if your code has no other errors and the spread setting you have on the strategy tester(e.g. 2,5...) is less than your
maximum
allowed spread in your code, then your code always run. In real life , however, spread is not constant, unless your broker is a Market Maker
or some other special arrangement. So, when you attempt to run your code live the spread at that time might be higher than your maximum.
Based on what I see in your code, the current order will be closed if the current spread is equal to or higher than 20. Which leads me to
another question: Why would you open an order then if the spread is higher than the max spread? I think you should only open an order if
the spread is less than max spread. Your method will almost certainly blow your account.
"It's just about variables in use within these 2 rules:"
Since you are sure where the problem is, you can see and confirm it yourself by looking at the actual values in the variables using the attached tool below.
I suggest you start by placing the below code just above the two OrderClose:
BreakPoint("","","",true,"(OrderOpenPrice()-Ask>=HiddenStop*MyPoint)",DoubleToStr((OrderOpenPrice()-Ask>=HiddenStop*MyPoint)),"(MarketInfo(Symbol(), MODE_SPREAD)",DoubleToStr((MarketInfo(Symbol(), MODE_SPREAD)) );//for OP_BUY section
BreakPoint("","","",true,"(Bid-OrderOpenPrice()>=HiddenStop*MyPoint)",DoubleToStr((Bid-OrderOpenPrice()>=HiddenStop*MyPoint)),"(MarketInfo(Symbol(), MODE_SPREAD)",DoubleToStr((MarketInfo(Symbol(), MODE_SPREAD)) );//for OP_SELL section
This should help you do less guessing as you code. Remember to add
#include <BreakPoint.mqh>//you can comment this out when liveat the top section of your code just below "#property strict".
Files:
BreakPoint.mqh
10 kb
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
it's been a month i'm stuck with this problem.
I found nowhere on Internet how to set up a hidden trailing stop so i tried to code it myself.
there is an error in my "Hidden TrailingStop" code.
here is my bot:
the section making trouble is the exit rules section :
the Hidden Trailing Stop i tried to code doesn't work in live, it works well in strategy tester using "open prices only" but using "every tick" fails.
it just opens one order and close it instantaneously....
I see no reason for this to happen, i am really clueless... I tried to debug it using "Print" and every output look correct to me..
any input welcome.
ps: if i uncomment these lines and use "normal" TrailingStop everything works fine:
I'm pretty sure i did a very stupid mistake... and the error can be very easy to spot for skilled coders...
It's just about variables in use within these 2 rules: