private int entrytime=0; private int currenttime=0; private int diff=0;
currenttime=ToDay(Time[0]); //reset times if (Position.MarketPosition == MarketPosition.Flat) { entrytime=0; currenttime=0; } //store entrytime if (Position.MarketPosition == MarketPosition.Flat && CurrentBars[0] > BarsRequiredToTrade &&CrossAbove(SMA1, SMA2, 1)) { EnterLong(Convert.ToInt32(DefaultQuantity), ""); entrytime=ToDay(Time[0]); } //calculate difference between entry time and current time in a position if (Position.MarketPosition == MarketPosition.Long); { diff=currenttime-entrytime; Print(diff); } //exit after 5 days and reset entrytime and currenttime if(diff>5) { ExitLong(); entrytime=0; currenttime=0; }
Thoughts on this code? Looks like it works fine. Is this an efficient way to keep track of time? I could use barssinceexecution but I can't for my purposes. Asking b/c my strategy has thousands of lines of codes and trades up to 5 instruments at the same time so trying to reduce the code as much as possible.
Comment