I am developing a strategy that will open a position. it will wait one year minus one day and verify if the position is winning or losing. If the position is losing, it will close the position. if the position is winning it will wait until one year plus one day to close the position.
Can you please help me with the piece of code that will help me identify that it has been one year since the position was opened? Any suggestion on where to find the information will be greatly appreciated
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Entry Signal
if (ADX1[0] < ADXinput)
{
EnterLongLimit(Convert.ToInt32(DefaultQuantity), ZonasdeOperacionCompra1[0], @"Compra");
}
// Exit signal 1 = if position is losing
if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]) < 0 && days since position open < one year) //piece of code I don't know how to write
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"Exitloss", @"Compra");
}
// Exit signal 2 = if the position is winning
if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]) > 0 && days since position open > one year) //piece of code i dont know how to write
{
ExitLong(Convert.ToInt32(DefaultQuantity), "Exitwinning", @"compra");
}
}

Comment