so i am trying to set up a additional condition that will execute a exit if the trade has been going for more than 10 days, but its not working, could i get some assistance on the correct way to make this happen? any assistance would be wonderful
this is the on bar update section :
protected override void OnBarUpdate()
{
// Ensure the code is executed only for the primary data series
if (BarsInProgress != 0)
return;
if (CurrentBar < 10)
return;
ManageEntry();
ManageExit();
CheckTradeDuration(); // Call the new method to check the trade duration
}
below is the entrance conditions , i have a separate section that deals with the main exit and that is working properly
}
// enter short position based on the trend confirmation
else if (isPivotConfirmTrend2)
{
EnterShort(Contracts,@"myEntryshort");
Print("Entered Short position"); // Added debug message
OkToTrade = true;
entryDate = Time[0]; // Store the entry date
}
this is the section for the trade duration exit
private void CheckTradeDuration()
{
if (Position.MarketPosition != MarketPosition.Flat)
{
if (Time[0].Date.Subtract(entryDate.Date).TotalDays >= 10)
{
if (Position.MarketPosition == MarketPosition.Long)
{
ExitLong("Exited after 10 days");
}
else if (Position.MarketPosition == MarketPosition.Short)
{
ExitShort("Exited after 10 days");
}
}
}
}
Comment