♥ 0 |
Dear Sir, I have a very quick question regarding my code below. I tried to calculate the first available Open (1 minute) value from 0930. However my code will sometimes generate error (NaN or Infinity) when the Open value is not available at 0930.
Specifically:
It will be really great if can advice me on how can I correct my code. Thank you so much sir!!
# ————————————————- # Define Time System
def isToday = if ( getDay() == getLastDay() ) then 1 else 0;
# ——————————————— # Definition: Candlestick
def C_1m = CLOSE(period = AggregationPeriod.MIN); def O_1m = OPEN(period = AggregationPeriod.MIN); def H_1m = HIGH(period = AggregationPeriod.MIN); def L_1m = LOW(period = AggregationPeriod.MIN); def V_1m = VOLUME(period = AggregationPeriod.MIN);
# ————————————————-
def Time_Start = 0930; def Time___End = 0959;
# ————————————————- # Calculate : RT Open
def RT_Open_Price = # Not yet reaching RT_StartTime (0930), therefore value not available. if ( SecondsFromTime(Time_Start) < 0 and isToday ) then Double.NaN else # Time equals RT_StartTime (0930). Set initial value. if ( SecondsFromTime(Time_Start) == 0 and isToday ) then O_1m else # Time equals RT_StartTime (0930), however no value is available because no trade # happens at RT_StartTime. Go to next time interval and use that value as initial value. if ( SecondsFromTime(Time_Start) >= 0 and SecondsTillTime(Time___End) >= 0 and isToday and isNaN(RT_Open_Price[1]) == 1 and isNaN(O_1m) != 1 ) then O_1m else RT_Open_Price[1];
Marked as spam
|
Please log in to post questions.