NexusFi: Find Your Edge


Home Menu

 





auto draw horizontal lines in thinkscript on tick chart over a specified time frame


Discussion in ThinkOrSwim

Updated
    1. trending_up 1,620 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 0 attachments




 
Search this Thread

auto draw horizontal lines in thinkscript on tick chart over a specified time frame

  #1 (permalink)
drift
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

Reply With Quote




Last Updated on April 16, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts