Hi all,
I am VERY new to thinkscript and I am working on how to code an ATR quick calculator but can't seem to figure it out. I've created it in excel but can't figure out how to translate it to a chart bubble in ToS. Essentially, what I am looking for is a way to use a multiple (1.5 for example) of the current ATR to figure out the number of ticks (rounded to the tick size of the security) for stop-loss and take profit with the ATR multiple as an input. I am really only going to be using this for trading futures in S&P, DOW, Russel2k, and the Nasdaq if that's helpful at all. (micros- /MYM /MES /MNQ /M2k and the minis- /ES /YM /NQ /RTY). Again, I'm not sure if this is helpful at all but I would only be really using this during regular trading hours, NOT during extended hours/overnight.
For example, if the current price of the /MYM is trading at 34,400 and the ATR is 9.5, I'd like a chat bubble that shows the following:
[(current ATR multiple), STOP: XXXXX, TICK: XXXXX, Target: XXXXX] or with using that example above [(1.5), STOP: 34414, TICK: 14, TARGET: 34386}
This is what I have coded so far:
#Default values are set to trade /MYM- is it possible to dynamically change the tick size and value based on what symbol is on the chart? Ideally, I'd only like to have to change the ATR Length and the multiple.
input ATRLength = 14;
input ATRmultiple = 1.5;
input TickSize = 1;
input TickValue= .50;
#Calculating ATR value
def ATR = Average(TrueRange(high, close, low), ATRLength);
#Calulating ATR with multiple
def ATRMulti = (ATR * ATRmultiple);
#Define currentprice
def CP = close(pricetype.last);
#Define stop and target
def Stop = absvalue(ATRMulti - CP);
def Target = absvalue(ATRMulti + CP);
#define number of ticks
def TickNum = (CP - Stop);
#ATR Multiple, number of ticks, STOP/TARGET label
addlabel(yes, ( ATRmulti =(ATRMulti), "STOP:" =Stop, "TICK:" =TickNum, "TARGET:" =Target) , color.yellow);
Is what I'm asking about possible in ToS? I think my biggest challenge right now is figuring out how to code the current price and how to format the chart code itself. As of right now, all I'm getting is N/A on the chart bubble. I know there is probably ALOT missing so any help would be greatly appreciated!!
Thanks everyone!
I am VERY new to thinkscript and I am working on how to code an ATR quick calculator but can't seem to figure it out. I've created it in excel but can't figure out how to translate it to a chart bubble in ToS. Essentially, what I am looking for is a way to use a multiple (1.5 for example) of the current ATR to figure out the number of ticks (rounded to the tick size of the security) for stop-loss and take profit with the ATR multiple as an input. I am really only going to be using this for trading futures in S&P, DOW, Russel2k, and the Nasdaq if that's helpful at all. (micros- /MYM /MES /MNQ /M2k and the minis- /ES /YM /NQ /RTY). Again, I'm not sure if this is helpful at all but I would only be really using this during regular trading hours, NOT during extended hours/overnight.
For example, if the current price of the /MYM is trading at 34,400 and the ATR is 9.5, I'd like a chat bubble that shows the following:
[(current ATR multiple), STOP: XXXXX, TICK: XXXXX, Target: XXXXX] or with using that example above [(1.5), STOP: 34414, TICK: 14, TARGET: 34386}
This is what I have coded so far:
#Default values are set to trade /MYM- is it possible to dynamically change the tick size and value based on what symbol is on the chart? Ideally, I'd only like to have to change the ATR Length and the multiple.
input ATRLength = 14;
input ATRmultiple = 1.5;
input TickSize = 1;
input TickValue= .50;
#Calculating ATR value
def ATR = Average(TrueRange(high, close, low), ATRLength);
#Calulating ATR with multiple
def ATRMulti = (ATR * ATRmultiple);
#Define currentprice
def CP = close(pricetype.last);
#Define stop and target
def Stop = absvalue(ATRMulti - CP);
def Target = absvalue(ATRMulti + CP);
#define number of ticks
def TickNum = (CP - Stop);
#ATR Multiple, number of ticks, STOP/TARGET label
addlabel(yes, ( ATRmulti =(ATRMulti), "STOP:" =Stop, "TICK:" =TickNum, "TARGET:" =Target) , color.yellow);
Is what I'm asking about possible in ToS? I think my biggest challenge right now is figuring out how to code the current price and how to format the chart code itself. As of right now, all I'm getting is N/A on the chart bubble. I know there is probably ALOT missing so any help would be greatly appreciated!!
Thanks everyone!