Really ? Nobody for such a simple problem ?
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:
|| ((PeriodHighest-OrderOpenPrice()>Trailing_trigger_move*MyPoint) && (Ask<PeriodHighest-TrailingStop*MyPoint)) || ((OrderOpenPrice()-PeriodLowest>Trailing_trigger_move*MyPoint) && (Bid>PeriodLowest+TrailingStop*MyPoint))
ok i did, if moderators come around, you can delete this thread thanx.
Instead of
for(int cnt=0;cnt<OrdersTotal();cnt++)code
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
Maybe there still is a problem, but surely that is a step forward.
From looking at the close condition, EXIT RULE is part of several OR conditions and not of AND conditions,
It is part of the spread (when spread is less then MaxSpread and digits >=4)
if ((MarketInfo(Symbol(), MODE_SPREAD)<=MaxSpread && (Digits == 5 || Digits == 4) && ((EXIT RULE HERE) |
And one of those parts is true
(DayOfWeek()==5 && Hour()>=21) || (Bid-OrderOpenPrice()>=HiddenStop*MyPoint) || ((OrderOpenPrice()-PeriodLowest>Trailing_trigger_move*MyPoint) && (Bid>PeriodLowest+TrailingStop*MyPoint)) ))) // close sell rule || Bid>=TrStop) { OrderClose(OrderTi cket(),OrderLots(),OrderClosePrice(),Slippage,Red)
So just put the EXIT RULE as a single AND component with all the other rules, meaning it will exit only when EXIT RULE is true.
From looking at the close condition, EXIT RULE is part of several OR conditions and not of AND conditions,
It is part of the spread (when spread is less then MaxSpread and digits >=4)
And one of those parts is true
So just put the EXIT RULE as a single AND component with all the other rules, meaning it will exit only when EXIT RULE is true.
same result, in fact i did try already :| but i'm not sure to understand what you mean by "And one of those parts is true "
of course if one of those parts is true
(DayOfWeek()==5 && Hour()>=21) || (Bid-OrderOpenPrice()>=HiddenStop*MyPoint) || ((OrderOpenPrice()-PeriodLowest>Trailing_trigger_move*MyPoint) && (Bid>PeriodLowest+TrailingStop*MyPoint))
then i want the order to close, and remember if i keep only :
(DayOfWeek()==5 && Hour()>=21) || (Bid-OrderOpenPrice()>=HiddenStop*MyPoint)
it works well on "every tick".
I'm really stuck. the weirdest part is that backtesting it using "open prices only" works well...
same result, in fact i did try already :| but i'm not sure to understand what you mean by "And one of those parts is true "
of course if one of those parts is true
then i want the order to close, and remember if i keep only :
it works well on "every tick".
I'm really stuck. the weirdest part is that backtesting it using "open prices only" works well...
|| ((OrderOpenPrice()-PeriodLowest>Trailing_trigger_move*MyPoint) && (Bid>PeriodLowest+TrailingStop*MyPoint))OrderOpenPrice() is a fixed price. Trailing_trigger_move*MyPoint is fixed as well. So, what you achieve here is when the price first moves more the Trailing_trigger_move from the open price - you close it. This is not trailing of the price, but is a take profit of Trailing_trigger_move points.
Obviously the problem is in the first part ofOrderOpenPrice() is a fixed price. Trailing_trigger_move*MyPoint is fixed as well. So, what you achieve here is when the price first moves more the Trailing_trigger_move from the open price - you close it. This is not trailing of the price, but is a take profit of Trailing_trigger_move points.
thanx for your help, but you are wrong on this point. if that was the case the problem should manifest using "open price only" in the strategy tester.
and even if the logic was wrong then at least it would wait for the price to move the amount of pips according to "Trailing_trigger_move" variable.
What it does here is that it closes the order INSTANTANEOUSLY.
"open prices only" backtest, you can see the trailing stop is triggered on the last 2 trades (forget about the others) :
this is normal behavior of my bot.
Now have a look running "every tick" backtest with exactly the same settings:
when backtesting using "every tick" the values in the variables are messed up :/
i now think the problem reside in the iBarShift() function, probably something i misunderstood about it.

- 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,
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 code.
here is my bot:
the section making trouble is the exit rules section :
the Hidden Trailing Stop i tried t 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 looks correct to me..
any input welcome.
ps: if i uncomment these TrailingStop sections everything works fine:
ps2: if i remove these lines everything works well too:
ps3: for those who think it's useless to include a hidden TrailingStop in a bot please just don't post in this thread.