In the code below, I tried hard to isolate the close for the bar during which the price first crossed below the SMA. With every attempt to write this, the answer I get seems to be pulled from a hat. In some tests, I have to go back several days just to determine where the return falls within the stock's daily price range.
This code is in a watchlist column with a five-minute aggregation.
This code is in a watchlist column with a five-minute aggregation.
Code:
def FloorIsOpen = SecondsFromTime(930) >= 0 and SecondsTillTime(1600) >= 0;
def SMA10 = SimpleMovingAvg(Close,10);
def Top = Max(Open,Close);
def SMACross = if !FloorIsOpen[1] and FloorIsOpen then 0 else if FloorIsOpen and SMACross[1] == 0 and crosses(Top,SMA10,CrossingDirection.BELOW) then Close else SMACross[1];
Plot X = SMACross;
Last edited by a moderator: