NexusFi: Find Your Edge


Home Menu

 





Price Levels With Start And End Times


Discussion in ThinkOrSwim

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




 
Search this Thread

Price Levels With Start And End Times

  #1 (permalink)
 Joseph H 
Wilmington Delaware
 
Experience: Intermediate
Platform: NinjaTrader, TOS
Trading: Futures
Posts: 21 since May 2019
Thanks Given: 3
Thanks Received: 16

Hi,

I am trying to build an indicator that will plot a price line from a defined start time through a defined end time on a certain date. User input would be Date, Start Time, End Time, and Price. Any ideas on how to set this up would be great.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Exit Strategy
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #2 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43

Hi Joseph,

Not sure if you still need this. The general idea is to set the plot variable to a valid value only when you want the line to draw and to NaN any time you don't want it to draw. So in this example there's a window defined by the date and times provided. Using that you can control when the line starts and ends.

Hope this helps,
Jeremy

 
Code
input userDate = 20200515;
input priceLevel = 2860;
input startTime = 930;
input endTime = 1130;

def isDateActive = if getYyyyMmDd() == userDate then 1 else 0;

def windowActive = isDateActive && SecondsFromTime(startTime) >= 0 && SecondsFromTime(endTime) < 0;

plot plotLevel = if windowActive then priceLevel else Double.NaN;
PriceLevelStartEnd

Reply With Quote
  #3 (permalink)
 Joseph H 
Wilmington Delaware
 
Experience: Intermediate
Platform: NinjaTrader, TOS
Trading: Futures
Posts: 21 since May 2019
Thanks Given: 3
Thanks Received: 16


Thank you so much for your reply. I can't get it to work, because my start time is on Globex start time 1800, but the end time is the next day at 1700 (23 hours). If the start time and end time are on the same date, then the script you supplied works great. Would you be able to help with the script for accomplishing that? I still want the start and end time to be input (user) values, because the start time isn't always at exactly 1800.

Thanks,
Joseph H.

Started this thread Reply With Quote
  #4 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43

Yea, combining date and time range is tricky. I'll work on it and let you know how it goes.

JayC

Reply With Quote
  #5 (permalink)
 Joseph H 
Wilmington Delaware
 
Experience: Intermediate
Platform: NinjaTrader, TOS
Trading: Futures
Posts: 21 since May 2019
Thanks Given: 3
Thanks Received: 16

Thanks so much, greatly appreciated!!

Started this thread Reply With Quote
  #6 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43

Hi Joseph,

I've created different plots that show or hide depending on how many days are included in the range. This was to manage the different conditions when crossing date boundaries. This seems to work for the cases I've tried, but give it a shot and let me know how it works for you.

JayC

 
Code
input startDate = 20200512;
input endDate = 20200513;
input startTime = 1800;
input endTime = 1700;
input priceLevel = 2850;

def dayCount = endDate - startDate;

def isInBetween = If endDate - startDate <= 0 then No else DaysFromDate(startDate+1) >= 0 && DaysFromDate(endDate) < 0;
def isStart = DaysFromDate(startDate) == 0 && SecondsFromTime(startTime) >= 0;
def isEnd = DaysFromDate(endDate) == 0 && SecondsFromTime(endTime) <= 0;
def isSingleDayWindow = DaysFromDate(startDate) == 0 and SecondsFromTime(startTime) >= 0 and SecondsFromTime(endTime) <= 0;

plot plotLevelSingleDay = if isSingleDayWindow then priceLevel else Double.NaN;
plotLevelSingleDay.setDefaultColor(Color.CYAN);
plotLevelSingleDay.setHiding(dayCount > 0);

plot plotLevelTwoDay = if isStart or isEnd then priceLevel else Double.NaN;
plotLevelTwoDay.setDefaultColor(Color.DARK_ORANGE);
plotLevelTwoDay.setHiding(dayCount != 1);

plot plotLevelMultiDay = if isStart or isEnd or isInBetween then priceLevel else Double.NaN;
plotLevelMultiDay.setDefaultColor(Color.DARK_GREEN);
plotLevelMultiDay.setHiding(dayCount < 2);

Reply With Quote
  #7 (permalink)
 Joseph H 
Wilmington Delaware
 
Experience: Intermediate
Platform: NinjaTrader, TOS
Trading: Futures
Posts: 21 since May 2019
Thanks Given: 3
Thanks Received: 16

JayC,

Thank you so much for that code. It works great and does what I needed. Sorry it took so long to get back, I am back to work after having Covid-19 so these 12 hr work days are long. I really appreciated the time you spent getting that together for me.

Started this thread Reply With Quote
  #8 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43

No problem, glad its working for you. Hope you're feeling better.

Take care,
JayC

Reply With Quote




Last Updated on May 28, 2020


© 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