The profit target is a function of what my average entry price is. The problem I am having is Ninja is not reading my average entry price correctly on the first trade, and then it messes up the trades thereafter
I get a log error that states "Calculated target order price was smaller/equal 0. No target order placed",
It seems to me, if there is only 1 entry made, ninjatrader's average price is not working correctly.
Below is the code, and a picture of the chart. You can clear see in the chart the entry price and target don't print until the second trade, when they should start printing on the first. And you will see that the issue causes a problem on the second trade.
Thanks.
if (Close[6]<Close[7]
&& Close[5]<Close[6]
&& Close[4]<Close[5]
&& Close[3]<Close[4]
&& Close[2]<Close[3]
&& Close[1]>Close[2]
&& Close[0]>Close[1]
&& (BarsSinceExitExecution() >= 1 || BarsSinceExitExecution() == -1))
{
EnterLong(0,DefaultQuantity, "Long");
longOrderBar = CurrentBars[0];
pftpcnt = 25/100;
averagePrice = Position.AveragePrice;
takeProfit = (Position.AveragePrice+Position.AveragePrice/100*pftpcnt);
SetProfitTarget("Long", CalculationMode.Price,takeProfit,true);
Draw.Line(this,"averagePrice"+ CurrentBars[0].ToString(),false,0,averagePrice,-15,averagePrice,Brushes.Green,DashStyleHelper.Dash ,1);
Draw.Line(this,"takeProfit"+ CurrentBars[0].ToString(),false,0,takeProfit,-15,takeProfit,Brushes.Red,DashStyleHelper.Dash,1);
}
Comment