Winter Haven, FL
Posts: 2 since Apr 2019
Thanks Given: 3
Thanks Received: 1
|
Hey Everyone!
Forgive me if this has been answered somewhere, but I haven't found any posts/threads that might answer my question and I am a newbie to this forum and not adept at searching it yet. I am working on some code in thinkscript, where I am trying to mark the high and low of the first 3 minutes on a 144 tick chart (I use it to gauge risk and entries for a market open strategy). To troubleshoot the variables, I displayed the values using labels, and noticed that it marked the high correctly (for example, 2900.00), but not the low (it equals 0). It baffles me that I am getting one value correct and the other incorrect.
Here is the code:
#9:30am is 34200 seconds from midnight and 9:33 is 34380 seconds from midnight.
def RangeWindow = if secondsfromtime(0) >= 34200 and secondsfromtime(0) <= 34380 then 1 else 0;
rec periodHigh = if RangeWindow == 1 and high > periodHigh[1] then high else periodHigh[1];
rec periodLow = if RangeWindow == 1 and low < periodLow[1] then low else periodLow[1];
def periodRange = PeriodHigh - PeriodLow;
def risk = (periodRange / ticksize()) * tickvalue();
#Draw the horizontal lines
plot ph = if RangeWindow == 1 then double.nan else periodhigh;
plot pl = if RangeWindow == 1 then double.nan else periodlow;
I thought using secondsfromtime would be the best approach to capture the desired time window since the bars aren't time based, but getting 0 for the low tells me either I did something wrong, I missed something in the code, or time and ticks don't play nice.
I appreciate any insights or help.
Thanks,
Drift
|