NexusFi: Find Your Edge


Home Menu

 





Identify big Average true range


Discussion in ThinkOrSwim

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




 
Search this Thread

Identify big Average true range

  #1 (permalink)
 russ12345 
brooklyn new york/usa
 
Experience: Beginner
Platform: tos
Trading: futures
Posts: 9 since Jan 2013
Thanks Given: 0
Thanks Received: 0

Hello,

I am new to think or swim programming and am trying to create an indicator that colors the average true range bar (with a 1 bar period) red if it is a down bar that is 20% greater than the 14 period atr. Same thing for an Up bar - color it green if it is a 20% greater than the 14 period atr. Basically i am just trying to identify big range bars.

Thank you and I appreciate any help with this.

peace

russ123

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Request for MACD with option to use different MAs for fa …
NinjaTrader
ZombieSqueeze
Platforms and Indicators
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
55 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
What percentage per day is possible? [Poll]
31 thanks
GFIs1 1 DAX trade per day journal
29 thanks

  #2 (permalink)
tangerine
albuquerque nm/usa
 
Posts: 29 since Aug 2015
Thanks Given: 3
Thanks Received: 9


russ12345 View Post
Hello,
I am new to think or swim programming and am trying to create an indicator that colors the average true range bar (with a 1 bar period) red if it is a down bar that is 20% greater than the 14 period atr. Same thing for an Up bar - color it green if it is a 20% greater than the 14 period atr. Basically i am just trying to identify big range bars.
Thank you and I appreciate any help with this.
peace
russ123

russ123 , does this meet your needs? My experience is that TOS won't display more than one "color bar" at a time. So I think you have to run two separate studies at the same time, unless somebody knows a workaround to run both in one study. So in the below code, run one as-is and run a copy of it but remove the # from the AssignPriceColor for downbar and move it to the AssignPriceColor for upbar. Interesting, I just finished writing a TS tutorial and covered this or I wouldn't have known about only one colorbar being displayable. Hope this helps.
P.S.- I used "magenta" not red so I could see it on my charts. Just change magenta to red.
 
Code
def myATR = reference ATR;
def downbar = close<open;
def upbar = close>open;
def downbar20 = close>=myATR*1.20;
def upbar20 = close>=myATR*1.20;
AssignPriceColor(if downbar AND downbar20 then color.magenta else Color.CURRENT);
#AssignPriceColor(if upbar AND upbar20 then color.green else Color.CURRENT);

Reply With Quote
The following user says Thank You to tangerine for this post:
  #3 (permalink)
spywon
cologne / nrw
 
Posts: 2 since Jul 2013
Thanks Given: 2
Thanks Received: 0


Hi
i'm also new to tos script-writing and i want to create a similar script like russ:
i want the background color of the main chart to become (e.g.) green when the macd line is above zero and above the signal line, and red if it goes vice versa. in all other cases the color of the background should stay as default (neutral).
this would be an enormous step up to my strategy.
does someone know how to...?

upfront thanks

Ross

Reply With Quote
  #4 (permalink)
tangerine
albuquerque nm/usa
 
Posts: 29 since Aug 2015
Thanks Given: 3
Thanks Received: 9

spywon and Russ12345:

spywon View Post
Hi
i'm also new to tos script-writing and i want to create a similar script like russ:
i want the background color of the main chart to become (e.g.) green when the macd line is above zero and above the signal line, and red if it goes vice versa. in all other cases the color of the background should stay as default (neutral).
this would be an enormous step up to my strategy.
does someone know how to...?
upfront thanks
Ross

spywon, this works (I put the code I added to MACD at the end in bold blue, so you understand how to do this with any other indicator):
 
Code
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close,
slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up")
else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down")
else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
def mycolor1 = VALUE>ZEROLINE AND VALUE>AVG;
def mycolor2 = VALUE<ZEROLINE AND VALUE<AVG;
AssignBackgroundColor(if mycolor1 then color.green else if mycolor2 then color.red
else Color.CURRENT);
And Russ12345, I learn something every day. Turns out you CAN put more than one colorbar in the study, like this:
 
Code
def myATR = reference ATR;
def downbar = close<open;
def upbar = close>open;
def downbar20 = close>=myATR*1.20;
def upbar20 = close>=myATR*1.20;
AssignPriceColor(if downbar AND downbar20 then color.magenta else if upbar AND upbar20
then color.green else Color.CURRENT);

Reply With Quote
The following user says Thank You to tangerine for this post:
  #5 (permalink)
spywon
cologne / nrw
 
Posts: 2 since Jul 2013
Thanks Given: 2
Thanks Received: 0

thx for the quick response, i'll definitley checkt that out

Reply With Quote





Last Updated on February 1, 2016


© 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