NexusFi: Find Your Edge


Home Menu

 





Conditional GetSymbol() Help


Discussion in ThinkOrSwim

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




 
Search this Thread

Conditional GetSymbol() Help

  #1 (permalink)
airgeadllc
Fayetteville, AR
 
Posts: 19 since Apr 2021
Thanks Given: 8
Thanks Received: 15

Hi,

I was hoping one of the members with thinkScript skills may be able to help me out. I want to put a label on a chart that displays the current session range for treasuries. I want it to display the range in the minimum movement in fractions.

So, if my label is on the 30yr then it will display the label "Session Range: 24" meaning a 24/32 tick range. I have included my script attempt below. I want to create a dashboard that will display the correct range for each contract type. So I need to divide the equivalent fraction decimal into the range.

I hope this is not confusing. So on my dashboard I would see something like:

Contract Range
/UB 31
/ZB 23
/ZN 1 05

I don't understand how to code the conditions, if getsymbol() = /ZB then contractTick = contractTick30yrBond

Then the range will be divided by the correct decimal to produce the tick count.

 
Code
declare upper;

input BasePeriod = AggregationPeriod.DAY;
input showlabel = yes;

def contractTick = integer;
def contractTickUltraBond = 0.03125;
def contractTick30yrBond = 0.03125;
def contractTickUltra10Note = 0.015625;
def contractTick10yrNote = 0.015625;
def contractTick5yrBill = 0.0078125;
def contractTick2yrBill = 0.0078125;

#if getSymbol() = “/ZB” then contractTick = contractTick30yrBond else if getSymbol() = “/UB” then #contractTick = contractTickUltraBond;

def Session_High = Highest(high(period = baseperiod)[0], 1);
def Session_Low = Lowest(low(period =baseperiod)[0], 1);

def SessionRange = (Session_High - Session_Low)/contractTick;

AddLabel(showlabel, GetSymbol() + "Day Range: " + SessionRange);
Your help would be greatly appreciated.
Ken

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Deepmoney LLM
Elite Quantitative GenAI/LLM
Futures True Range Report
The Elite Circle
 
  #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

try this...

 
Code
declare upper;

input BasePeriod = AggregationPeriod.DAY;
input showlabel = yes;

#def contractTick = integer;
def contractTickUltraBond = 0.03125;
def contractTick30yrBond = 0.03125;
def contractTickUltra10Note = 0.015625;
def contractTick10yrNote = 0.015625;
def contractTick5yrBill = 0.0078125;
def contractTick2yrBill = 0.0078125;

def contractTick = 
if getSymbol() == "/ZB:XCBT" then 
contractTick30yrBond 
else if getSymbol() == "/UB:XCBT" then 
contractTickUltraBond 
else if getSymbol() == "/TN:XCBT" then 
contractTickUltra10Note
else if getSymbol() == "/ZN:XCBT" then 
contractTick10yrNote
else if getSymbol() == "/ZF:XCBT" then 
contractTick5yrBill
else 
contractTick2yrBill;

def Session_High = Highest(high(period = baseperiod)[0], 1);
def Session_Low = Lowest(low(period =baseperiod)[0], 1);

def SessionRange = (Session_High - Session_Low)/contractTick;

AddLabel(showlabel, GetSymbol() + " Day Range: " + SessionRange);

Reply With Quote
Thanked by:
  #3 (permalink)
airgeadllc
Fayetteville, AR
 
Posts: 19 since Apr 2021
Thanks Given: 8
Thanks Received: 15


Thank you for the suggestion. I had kept digging and I eventually found a method of doing what I wanted using the "switch" command. I am putting the code here that I used for others who may want to do something similar. I won't lie, I do not fully understand how to use this command. I just looked at the example code and made it work for me.

HTML Code:
declare upper;

input BasePeriod = AggregationPeriod.DAY;
input showlabel = yes;
input symbol = {default "ZB", "UB", "ZN", "TN", "ZF", "ZT", "Current"};

def contractTickUltraBond = 0.03125;
def contractTick30yrBond = 0.03125;
def contractTickUltra10Note = 0.03125;
def contractTick10yrNote = 0.03125;
def contractTick5yrBill = 0.03125;
def contractTick2yrBill = 0.03125;

switch (symbol)
{
case ZB:
     contractTick = contractTick30yrBond;
case UB:
     contractTick = contractTickUltraBond;
case ZN:
     contractTick = contractTick10yrNote;
case TN:
     contractTick = contractTickUltra10Note;
case ZF:
     contractTick = contractTick5yrBill;
case ZB:
     contractTick = contractTick2yrBill;
default:
     contractTick = contractTick30yrBond;
}

def Session_High = Highest(high(period = baseperiod)[0], 1);
def Session_Low = Lowest(low(period =baseperiod)[0], 1);

def SessionRange = (Session_High - Session_Low)/contractTick;

AddLabel(showlabel, symbol + "Day Range: " + SessionRange);

Reply With Quote
  #4 (permalink)
chtulhu
Nashville+Tennessee
 
Posts: 8 since Feb 2020
Thanks Given: 1
Thanks Received: 3

won't work.
1st get the names right. To get the names,
click in the symbol entry box on the left
on the little window that opens, click on hen select more
then right click on any of the rows,
select more info
select fundamentals
then DETACH the window, so you don't have to reopen it.
In the window you can select any symbol, the symbol() name is next to the product

eg: for /YM, the name is /YM:XCBT.

Reply With Quote
Thanked by:
  #5 (permalink)
airgeadllc
Fayetteville, AR
 
Posts: 19 since Apr 2021
Thanks Given: 8
Thanks Received: 15

Works fine for me

Reply With Quote




Last Updated on June 27, 2021


© 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