i'm Daniel and i'm trying to create my own Ninjascript strategy.
At first, excuse me for my english, it is not my mother tongue, but i hope you will understand me
I traded some months with Ninjatrader and now i want to try it with automated strategies.
I searched in some threads, maybe there is the solution, but it isn't.
I use Ninjatrader 8.
I have two questions or I need help in two situations:
1.
I want to set stoploss on the second last bar close, if i'm in a short position and the last three bars are decreasing. If the following bar is also decreasing, the stoploss should change to the actually second last bar close. Like a trailing stop.
Only if we have three negative bars, stoploss should be changed.
I think about the following solution, but it doesn't really work.
Sometimes it works, but there are some times, if ninjatrader enter a short position and one second later the stoploss is actived and I'm flat again, why?
if ((Position.MarketPosition==MarketPosition.Short)
&& (Close[0]<Close[1])
&& (Close[1]<Close[2])
)
{
SetStopLoss(CalculationMode.Price, Close[2]);
}
I have created an int variable, which is count up one number after a short oder longentry, and then I compare this variable with an other one (my max. trades number) with an if comparison before the short or long order. But it also doesn't work.
Sometimes NT trades more trades, and sometimes NT trades less trades than my "trades number" variable.
What's the reason?
I thank you very very much for your help!
Daniel
Comment