I have a little problem when I try to close a position partially. In my program below, I enter a long position with position size= entryPosSize*maxLot, and I try to exit the position partially with position size= entryPosSize.
The first time, the partial exit works good, but after, the line ExitLong(entryPosSize) is executed because I see the message "FirstStrategyLong Exit long Resistance” but I don't see any order generated by NinjaTrader, neither any exception or confirmation on Log Tab.
Could you advise please, what should I do let NinjaTrader execute the partial exit for the second, third time etc.?
Best regards
try{
//Enter Long Cond
if ((isEnterLongCondTouchSupport() || isEnterLongCondBreakOut())
&& Position.MarketPosition==MarketPosition.Flat)
{
entryPosSize=(int)getEntryPosSize(Close[1],MIN(Low,perFlorCap)[0]);
EnterLong(entryPosSize*maxLot);
double stop=MIN(Low,3)[0];
SetStopLoss(CalculationMode.Price,stop);
String msg="FirstStrategyLong Entry long: Instrument="+Instrument
+" Price="+Open[0]
+"EntrySize="+entryPosSize*maxLot+" Stop="+stop;
Print(msg);
SendMail(mail_from,mail_to,"FirstStrategyLong Entry long"+Instrument,msg);
}
//Exit Long Cond
if(isExitLongCondResistance() && Position.MarketPosition==MarketPosition.Long)
{
ExitLong(entryPosSize);
String msg="FirstStrategyLong Exit long Resistance: Instrument="+Instrument +" Price="+Open[0]+" Size="+entryPosSize;
Print(msg);
SendMail(mail_from,mail_to,"FirstStrategyLong Exit long"+Instrument,msg);
}
}catch (Exception e){
Print(Time[0] + " " + e.ToString());
Log("General Strategy Error: Please check your strategy for errors.", LogLevel.Error);
}
Comment