I am trying to create a trailing stop logic (I don't want to use the trailstop method as I don't want my trailing stop to be entered when I initially enter the market, I only want it to kick in when a certain condition becomes true).
But I am finding that once I declare a dataseries, Ninjatrader 7 seems to not allow me to redeclare the dataseries value:.
For example, here is the code I'm looking at:
//NB This is within if (BarsInProgress == 0) {
//Stop Calculations
Minmove = TickSize*5;
if (Xtest[0] >= Closes[0][0])
//If xTest (trail stop price) is higher than current price, reset it to current price minus Minmove
{
Xtest.Set(Closes[0][0] -Minmove);
}
//Else if new xTest would be tighter to current price than current xTest, and/or xTest = zero redeclare at tighter value
else if (Closes[0][0] -Minmove] > Xtest[1] || Xtest[0] ==0 )
{
Xtest.Set(Closes[0][0] -Minmove);
}
//Else continue to use same xTest value
else
{
Xtest.Set(Xtest[1]);
}
Print("Xtest " + Xtest[0] + " Price "+ Closes[0][0]);
Xtest 10759 Price 10764
Xtest 10763 Price 10768
Xtest 10765 Price 10770
Xtest 10765 Price 10770
Xtest 10765 Price 10770
Is there a way around this please? The current results above means that my "trailing stop" simply follows the market and doesn't "lock in" the profit.
Many thanks in advance,
David
Comment