Hi Support
I wrote a strategy with a trailing stop that I coded myself.
The trailing stop is managed by the following lines of code within the "onTick" body:
if (inLong)
{
b = tick.getBid();
if (b<=stoploss)
{
order_long.close();
inLong = false;
}
else if (b-trailpips>stoploss)
{
stoploss = b-trailpips;
}
}
else if (inShort)
{
b = tick.getAsk();
if (b>=stoploss)
{
order_short.close();
inShort = false;
}
else if (b+trailpips<stoploss)
{
stoploss = b+trailstop;
}
}
This works perfectly in the historical tester, but it does not work at all if strategy is running in real time.
Your help will be greatly appreciated.