NexusFi: Find Your Edge


Home Menu

 





MID price indicator for TOS


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one smegey with 5 posts (0 thanks)
    2. looks_two devildriver6 with 3 posts (10 thanks)
    3. looks_3 Shortline with 2 posts (0 thanks)
    4. looks_4 Semifaded with 2 posts (0 thanks)
    1. trending_up 10,885 views
    2. thumb_up 12 thanks given
    3. group 12 followers
    1. forum 18 posts
    2. attach_file 0 attachments




 
Search this Thread

MID price indicator for TOS

  #11 (permalink)
devildriver6
Dallas, Texas
 
Posts: 43 since Jun 2015
Thanks Given: 2
Thanks Received: 32


Shortline View Post
The logic of the script combined with ToS methodology is causing the recursive function to start one bar later than intended.

If you set the following two inputs to 1 bar prior to what you actually want the script will work accurately:

CapturePeriodStart
StartPlotTime

For example, if you are using a 5 minute intraday chart, if you set the above tow parameters to 0925 the values will be correct.

Unfortunately, if you change timeframes without adjusting these parameters it the midline will be inaccurate again.

I'm sure there is some logic that could be built into the script but I did not take the time to investigate that, sorry.

Additional Note: I just realized that if the chart is not showing the extended trading hours session the above hack does not work. Back to the drawing board.




For everyone following this thread, I figured out a more "elegant" way to do this, which is now correct.
This will reset daily, regardless of timeframe (as long as the timeframe is lower than the midpoint you're tracking), as well as provides Daily, Weekly, and Monthly midpoints, as desired.

Lastly, this gives you the option to see the High and Low it's using or hide it, as needed, and rounds the Mid Point to the nearest tick value.

Here's what it looks like (showing the high and low, which you can hide):



Here's the code:
## Provided by @The_Dude_Trader on Stocktwits / Twitter##
## For personal use only##
## Come see more at @DTWCoachandDude on Stocktwits / Twitter / Facebook ##
## https://www.secretsociety7.com ##


input timeFrame = {default DAY, WEEK, MONTH} ;
input ShowHiLo = no ;


def cap = GetAggregationPeriod() ;
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH ;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period") ;

def yyyyMmDd = GetYYYYMMDD() ;
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd ;
case WEEK:
periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7) ;
case MONTH:
periodIndx = RoundDown(yyyyMmDd / 100, 0) ;
}
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes) ;

def HI ;
def LO ;

if (isPeriodRolled) {
HI = high ;
LO = low ;
} else {
HI = if high > HI[1] then high else HI[1] ;
LO = if low < LO[1] then low else LO[1] ;
}

def NA = double.NaN ;

plot TheHI = if ShowHiLo then HI else NA ;
plot TheLO = if ShowHiLo then LO else NA ;
plot TheMid = round(((HI + LO) / 2) / ticksize(), 0) * ticksize();

TheHI.setdefaultColor(color.green) ;
TheLO.setdefaultColor(color.red) ;
TheMid.setdefaultColor(color.yellow) ;
TheMid.setlineweight(2) ;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Futures True Range Report
The Elite Circle
Deepmoney LLM
Elite Quantitative GenAI/LLM
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #12 (permalink)
 
Shortline's Avatar
 Shortline 
Lake Stevens, WA
 
Experience: Intermediate
Platform: NinjaTrader, TOS, IB exec
Broker: Interactive Brokers
Trading: ES CL
Posts: 46 since Aug 2016
Thanks Given: 38
Thanks Received: 43


devildriver6 View Post
For everyone following this thread, I figured out a more "elegant" way to do this, which is now correct.

Nice update! It is very elegant.

I like it. Thanks for sharing.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #13 (permalink)
 BlueSky929 
New Orleans, Louisiana
 
Experience: Beginner
Platform: ThinkOrSwim
Trading: Emini
Posts: 1 since Apr 2017
Thanks Given: 1
Thanks Received: 1



devildriver6 View Post
For everyone following this thread, I figured out a more "elegant" way to do this, which is now correct.
;

The devil's in the details, as you already know, devildriver6. This indicator is quite elegant, and I love it, man. I have been looking for this for quite a while. You are da' man! Thank you very much!


Reply With Quote
Thanked by:
  #14 (permalink)
GJN Woodstock
Kingston, New York USA
 
Posts: 1 since Jun 2019
Thanks Given: 0
Thanks Received: 0

You have made my dream come true ... I'd been searching for a means of creating a mid-point indicator for my TOS intraday futures charts and some midnight cyber-surfing landed me here at Futures IO and your kind contribution to traders unable to craft Think Script ... Kind folks like you make the internet a wonder-filled playground ... Thanks again, George J Nicholson

Reply With Quote
  #15 (permalink)
nick0102
los angeles + ca/usa
 
Posts: 1 since May 2017
Thanks Given: 0
Thanks Received: 0

I had a simple version and this one really fits the bill. I struggled creating it on my own til I finally found my senses and found this one. Thanks devil

Reply With Quote
  #16 (permalink)
Phil in Texas
Dallas, TX USA
 
Posts: 9 since Aug 2012
Thanks Given: 59
Thanks Received: 6


nick0102 View Post
I had a simple version and this one really fits the bill. I struggled creating it on my own til I finally found my senses and found this one. Thanks devil

Ditto this ^^^^^^ from fellow Texan!

Reply With Quote
  #17 (permalink)
 John Michigan 
Grand Rapids MI
 
Experience: Intermediate
Platform: TOS, Ninja, Tradovate
Trading: ES
Posts: 2 since Sep 2019
Thanks Given: 1
Thanks Received: 1

Thanks for sharing your expertise with the mid-point indicator!

Reply With Quote
  #18 (permalink)
 keifer 
San Francisco California USA
 
Experience: Beginner
Platform: ThinkorSwim
Broker: ThinkorSwim
Trading: RTY
Posts: 4 since May 2013
Thanks Given: 7
Thanks Received: 1

Thank you so much for your skill in coding.

I've been looking high and low for this High, Low, Mid code.
I was plotting it manually, this will be such a time saver.

-Keifer

Reply With Quote
  #19 (permalink)
bmont9
austin texas
 
Posts: 1 since Sep 2022
Thanks Given: 0
Thanks Received: 1

Hey everyone, here is a code for theMid that plots the overnight mid then switches during regular trading hours




 
Code
#coded by bmont

declare once_per_bar;

def na = double.NaN ;

def yyyyMmDd = GetYYYYMMDD() ;
def periodIndx = yyyyMmDd;
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes) ;

def HI ;
def LO ;

if (isPeriodRolled) {
HI = high ;
LO = low ;
} else {
HI = if high > HI[1] then high else HI[1] ;
LO = if low < LO[1] then low else LO[1] ;
}

def openingTime = 0400;
def closingTime = 0930;
def isOpen = SecondsFromTime(openingTime) >= 0 and SecondsTillTime(closingTime) > 0;
def isClose = SecondsFromTime(closingTime) >= 27000 or SecondsTillTime(openingTime) > 0;
def isRegHours = isOpen and !isClose;
plot ETHmid = if !isclose and !isopen then na else round(((HI + LO) / 2) / ticksize(), 0) * ticksize();
ETHmid.setdefaultColor(createcolor(169,140,8));

def Begin = 0930;
def End = 1800;
def active = if SecondsTillTime(End) > 0 and SecondsFromTime(Begin) >= 0 then yes else no;
def highest= if highest[1] == 0 or active[1] == 0 and active == 1 then high else if active and high > highest[1] then high else highest[1];
def lowest= if lowest[1] == 0 or active[1] == 0 and active == 1 then low else if active and low < lowest[1] then low else lowest[1];
def midline =  ((highest - lowest) / 2) + lowest;

def openingTimeRTH = 0930;
def closingTimeRTH = 1800;
def isOpenRTH = SecondsFromTime(openingTimeRTH) >= 0 and SecondsTillTime(closingTimeRTH) > 0;
def isCloseRTH = SecondsFromTime(closingTimeRTH) >= 0 or SecondsTillTime(openingTimeRTH) > 0;
def isRegHoursRTH = isOpenRTH and !isCloseRTH;

plot RTHmid = if !isRegHoursRTH then na else if SecondsTillTime(Begin) > 0 then Double.NaN else midline;
RTHmid.setdefaultColor(createcolor(169,140,8));

Reply With Quote
Thanked by:




Last Updated on September 29, 2022


© 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