Archives: RSM Indicator for ThinkorSwim

Status
Not open for further replies.
@tron That is really cool you had a chance to chat with Markus. I like his locked in Stop and I use it but I feel better also having a trailing stop for when the market gets news it does not like and decides to swing against me. If the market trends nicely in my direction I am less concerned on the stops. When the market behaves like it has an upset stomach then I start to think about trailing stops more. Good example being today's 400 point dip in the NASDAQ. Much rather get trailing stopped out early while in a profit then have it drop through the entry point and on down to the stop for a loss.

I took the ATR TRailing Stop of thinkorswim and modifed it to mimic Markus' Stop while adjusting to a new days gains. Wanted something quick and easy to test my idea, only been using this a few weeks. Also, I find this useful if I decide that the stock will continue running up beyond Markus' Profit Target and let a partial position ride to make futher gains. Easier for me to see when it has finished it's run and to step out. Instead of getting out completely as Markus suggests and moving on to another stock.

Basically, I changed the ATRperiod to 7, ATRfactor to 1.5, changed Aggregation to day, commented out their plot signals, added my own plots, label and an alert. Used the unmodified version since the modified smooths the signal. Not sure if averagetype should be Wilders but since this is not meant to be exact I left it. This is Long side only, not made the leap to Shorting side yet so did not code for it. Can add another instance of this and set to 4Hour, hour, thirty min, etc. if wanting an earlier warning.

It can also be set for the bar's low or it's close to fall below the trailing stop to trigger alert. I run this on my intra-day 15 min chart. I may re-write this to be less sloppy later on when I have decided what direction to take it.

Hope this explains things.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2021
#

##  Unmodified = calculations use the ATR on defined period multiplied by the specified factor.
##  Modified = calculations uses long period MA, minimizing gaps between adjacent bars, smoothing out sharp surges in price.

input trailType = {default unmodified, modified};
input ATRPeriod = 7;   # default 5, changed to make more like PowerX
input ATRFactor = 1.5;  #default 3.5, changed to make more like PowerX
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

  ##  *modified formula*
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
  ##  *end of modified formula*


  # my add for 1 Day  trailing stop
def highHr = high(Period = AggregationPeriod.Day);
def closeHr = close(Period = AggregationPeriod.Day);
def lowHr = low(Period = AggregationPeriod.Day);


def trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(highHr, closeHr, lowHr);
}

def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail =  close - loss;
        case short:
            state = state.short;
            trail = close + loss;
        }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (closeHr > trail[1]) {
        state = state.long;
        trail = Max(trail[1], closeHr - loss);
    } else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    } else {
        state = state.long;
        trail =  close - loss;
    }
}

#def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
#def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);
#plot TrailingStop = trail;
#TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
#TrailingStop.DefineColor("Buy", GetColor(0));
#TrailingStop.DefineColor("Sell", GetColor(1));
#TrailingStop.AssignValueColor(if state == state.long
#    then TrailingStop.Color("Sell")
#    else TrailingStop.Color("Buy"));


## my add
plot TrailStop = if state == state.long then Trail else Double.NaN;
TrailStop.SetDefaultColor(Color.dark_orange);
TrailStop.SetPaintingStrategy(PaintingStrategy.squares);

AddLabel(yes and state == state.long, "TrailStop-Day: " +round(Trail, 2)+ "", color.dark_orange);
AddLabel(yes and state == state.long and low crosses below Trail, "!!! ALERT : 1Day Trail Stop Hit !!!", color.plum);
alert(state == state.long and low crosses below Trail,"!!! ALERT : 1Day Trail Stop Hit !!!",alert.BAR,sound.RING);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@tron That is really cool you had a chance to chat with Markus. I like his locked in Stop and I use it but I feel better also having a trailing stop for when the market gets news it does not like and decides to swing against me. If the market trends nicely in my direction I am less concerned on the stops. When the market behaves like it has an upset stomach then I start to think about trailing stops more. Good example being today's 400 point dip in the NASDAQ. Much rather get trailing stopped out early while in a profit then have it drop through the entry point and on down to the stop for a loss.

I took the ATR TRailing Stop of thinkorswim and modifed it to mimic Markus' Stop while adjusting to a new days gains. Wanted something quick and easy to test my idea, only been using this a few weeks. Also, I find this useful if I decide that the stock will continue running up beyond Markus' Profit Target and let a partial position ride to make futher gains. Easier for me to see when it has finished it's run and to step out. Instead of getting out completely as Markus suggests and moving on to another stock.

Basically, I changed the ATRperiod to 7, ATRfactor to 1.5, changed Aggregation to day, commented out their plot signals, added my own plots, label and an alert. Used the unmodified version since the modified smooths the signal. Not sure if averagetype should be Wilders but since this is not meant to be exact I left it. This is Long side only, not made the leap to Shorting side yet so did not code for it. Can add another instance of this and set to 4Hour, hour, thirty min, etc. if wanting an earlier warning.

It can also be set for the bar's low or it's close to fall below the trailing stop to trigger alert. I run this on my intra-day 15 min chart. I may re-write this to be less sloppy later on when I have decided what direction to take it.

Hope this explains things.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2021
#

##  Unmodified = calculations use the ATR on defined period multiplied by the specified factor.
##  Modified = calculations uses long period MA, minimizing gaps between adjacent bars, smoothing out sharp surges in price.

input trailType = {default unmodified, modified};
input ATRPeriod = 7;   # default 5, changed to make more like PowerX
input ATRFactor = 1.5;  #default 3.5, changed to make more like PowerX
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

  ##  *modified formula*
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
  ##  *end of modified formula*


  # my add for 1 Day  trailing stop
def highHr = high(Period = AggregationPeriod.Day);
def closeHr = close(Period = AggregationPeriod.Day);
def lowHr = low(Period = AggregationPeriod.Day);


def trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(highHr, closeHr, lowHr);
}

def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail =  close - loss;
        case short:
            state = state.short;
            trail = close + loss;
        }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (closeHr > trail[1]) {
        state = state.long;
        trail = Max(trail[1], closeHr - loss);
    } else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    } else {
        state = state.long;
        trail =  close - loss;
    }
}

#def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
#def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);
#plot TrailingStop = trail;
#TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
#TrailingStop.DefineColor("Buy", GetColor(0));
#TrailingStop.DefineColor("Sell", GetColor(1));
#TrailingStop.AssignValueColor(if state == state.long
#    then TrailingStop.Color("Sell")
#    else TrailingStop.Color("Buy"));


## my add
plot TrailStop = if state == state.long then Trail else Double.NaN;
TrailStop.SetDefaultColor(Color.dark_orange);
TrailStop.SetPaintingStrategy(PaintingStrategy.squares);

AddLabel(yes and state == state.long, "TrailStop-Day: " +round(Trail, 2)+ "", color.dark_orange);
AddLabel(yes and state == state.long and low crosses below Trail, "!!! ALERT : 1Day Trail Stop Hit !!!", color.plum);
alert(state == state.long and low crosses below Trail,"!!! ALERT : 1Day Trail Stop Hit !!!",alert.BAR,sound.RING);
I like it! Thanks for the share.
 
@tron That is really cool you had a chance to chat with Markus. I like his locked in Stop and I use it but I feel better also having a trailing stop for when the market gets news it does not like and decides to swing against me. If the market trends nicely in my direction I am less concerned on the stops. When the market behaves like it has an upset stomach then I start to think about trailing stops more. Good example being today's 400 point dip in the NASDAQ. Much rather get trailing stopped out early while in a profit then have it drop through the entry point and on down to the stop for a loss.

I took the ATR TRailing Stop of thinkorswim and modifed it to mimic Markus' Stop while adjusting to a new days gains. Wanted something quick and easy to test my idea, only been using this a few weeks. Also, I find this useful if I decide that the stock will continue running up beyond Markus' Profit Target and let a partial position ride to make futher gains. Easier for me to see when it has finished it's run and to step out. Instead of getting out completely as Markus suggests and moving on to another stock.

Basically, I changed the ATRperiod to 7, ATRfactor to 1.5, changed Aggregation to day, commented out their plot signals, added my own plots, label and an alert. Used the unmodified version since the modified smooths the signal. Not sure if averagetype should be Wilders but since this is not meant to be exact I left it. This is Long side only, not made the leap to Shorting side yet so did not code for it. Can add another instance of this and set to 4Hour, hour, thirty min, etc. if wanting an earlier warning.

It can also be set for the bar's low or it's close to fall below the trailing stop to trigger alert. I run this on my intra-day 15 min chart. I may re-write this to be less sloppy later on when I have decided what direction to take it.

Hope this explains things.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2021
#

##  Unmodified = calculations use the ATR on defined period multiplied by the specified factor.
##  Modified = calculations uses long period MA, minimizing gaps between adjacent bars, smoothing out sharp surges in price.

input trailType = {default unmodified, modified};
input ATRPeriod = 7;   # default 5, changed to make more like PowerX
input ATRFactor = 1.5;  #default 3.5, changed to make more like PowerX
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

  ##  *modified formula*
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
  ##  *end of modified formula*


  # my add for 1 Day  trailing stop
def highHr = high(Period = AggregationPeriod.Day);
def closeHr = close(Period = AggregationPeriod.Day);
def lowHr = low(Period = AggregationPeriod.Day);


def trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(highHr, closeHr, lowHr);
}

def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail =  close - loss;
        case short:
            state = state.short;
            trail = close + loss;
        }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (closeHr > trail[1]) {
        state = state.long;
        trail = Max(trail[1], closeHr - loss);
    } else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    } else {
        state = state.long;
        trail =  close - loss;
    }
}

#def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
#def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);
#plot TrailingStop = trail;
#TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
#TrailingStop.DefineColor("Buy", GetColor(0));
#TrailingStop.DefineColor("Sell", GetColor(1));
#TrailingStop.AssignValueColor(if state == state.long
#    then TrailingStop.Color("Sell")
#    else TrailingStop.Color("Buy"));


## my add
plot TrailStop = if state == state.long then Trail else Double.NaN;
TrailStop.SetDefaultColor(Color.dark_orange);
TrailStop.SetPaintingStrategy(PaintingStrategy.squares);

AddLabel(yes and state == state.long, "TrailStop-Day: " +round(Trail, 2)+ "", color.dark_orange);
AddLabel(yes and state == state.long and low crosses below Trail, "!!! ALERT : 1Day Trail Stop Hit !!!", color.plum);
alert(state == state.long and low crosses below Trail,"!!! ALERT : 1Day Trail Stop Hit !!!",alert.BAR,sound.RING);
@RickAns - Thanks for the logic, I'll definitely give it a shot in my RSM Chart and Profit/Stop Loss Study. I generally try to catch Markus's live youtube stream on M, W, F at 3:30 - 4:15 ET. He usually answers questions after his topic of the day and I have found that if you get your question in early, you have a great chance that he'll answer it.
 
I agree that there are differences that have been discussed between TOS and TV. I've been using the TV official version of the PowerX Strategy Bar Coloring [OFFICIAL VERSION] from Rockwell Trading and I have found that these TOS RSM indicator settings seem to match the TV chart for me:

RSI - Wilders
Stoch - Wilders
MACD - Exponential

Although when I use these settings in the TOS scanner, I still get some UpTrendJustStarted miscompares. That is the scanner will indicate that an UpTrendJust started for a stock and when I look at the stock in my chart on TOS, it doesn't indicate that the UpTrendJustStarted. I have been debugging and hopefully will figure out where my disconnect is.
 
can someone check my code for the ADR for 7 days using the $200 limit in his .pdf something seems off. also this is my first Frankenstein script so please feel free to rip it apart

Code:
#Hint: Average Daily Range

def len = 2;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;


def ADR_high = (dayHigh + dayHigh[1] + dayHigh[2] + dayHigh[3] + dayHigh[4] + dayHigh[5] + dayHigh[6]) / 7;
def ADR_low = (dayLow + dayLow[1] + dayLow[2] + dayLow[3] + dayLow[4] + dayLow[5] + dayLow[6]) / 7;

def hiz = (ADR_high - ADR_low);
def amount = round(hiz * 200);

plot hiiz = hiz;
plot amounts = amount;
addlabel(yes, "account: " + 200 + "  shares: " + amounts,color.yellow);
 
can someone check my code for the ADR for 7 days using the $200 limit in his .pdf something seems off. also this is my first Frankenstein script so please feel free to rip it apart

Code:
#Hint: Average Daily Range

def len = 2;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;


def ADR_high = (dayHigh + dayHigh[1] + dayHigh[2] + dayHigh[3] + dayHigh[4] + dayHigh[5] + dayHigh[6]) / 7;
def ADR_low = (dayLow + dayLow[1] + dayLow[2] + dayLow[3] + dayLow[4] + dayLow[5] + dayLow[6]) / 7;

def hiz = (ADR_high - ADR_low);
def amount = round(hiz * 200);

plot hiiz = hiz;
plot amounts = amount;
addlabel(yes, "account: " + 200 + "  shares: " + amounts,color.yellow);
are you trying to figure out the number of shares?
 
This is what i came up with

Code:
#Hint: Average Daily Range

def len = 1;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;


def ADR_high = (dayHigh + dayHigh[1] + dayHigh[2] + dayHigh[3] + dayHigh[4] + dayHigh[5] + dayHigh[6]) / 7;
def ADR_low = (dayLow + dayLow[1] + dayLow[2] + dayLow[3] + dayLow[4] + dayLow[5] + dayLow[6]) / 7;

def hiz = (ADR_high - ADR_low);
def amount = Round(200 / (hiz * 1.5));

plot hiiz = hiz;
plot amounts = amount;
AddLabel(yes, "account: " + 200 + "  shares: " + amounts, Color.BLUE);
 
This is what i came up with

Code:
#Hint: Average Daily Range

def len = 1;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;


def ADR_high = (dayHigh + dayHigh[1] + dayHigh[2] + dayHigh[3] + dayHigh[4] + dayHigh[5] + dayHigh[6]) / 7;
def ADR_low = (dayLow + dayLow[1] + dayLow[2] + dayLow[3] + dayLow[4] + dayLow[5] + dayLow[6]) / 7;

def hiz = (ADR_high - ADR_low);
def amount = Round(200 / (hiz * 1.5));

plot hiiz = hiz;
plot amounts = amount;
AddLabel(yes, "account: " + 200 + "  shares: " + amounts, Color.BLUE);
Thanks I’ll give it a go
 
Thanks. I was wondering if there was a quick way to figure this out without pulling out a calculator
I went with what you started earlier.....Might be something your after


Code:
#Hint: Average Daily Range

input RA = 100;      #Risk Amount
input Entry = high;  #Entry location   (High, Close, etc)
def len = 1;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;


def ADR_high = (dayHigh + dayHigh[1] + dayHigh[2] + dayHigh[3] + dayHigh[4] + dayHigh[5] + dayHigh[6]) / 7;
def ADR_low = (dayLow + dayLow[1] + dayLow[2] + dayLow[3] + dayLow[4] + dayLow[5] + dayLow[6]) / 7;

def hiz = (ADR_high - ADR_low);

def amount = round(RA / (1.5 * hiz));
plot amounts = amount;

def entries = entry + 0.01;

def stop = round(entries - (1.5*hiz));
plot stops = stop;

def t1 = entries + ((1.5*hiz));

def t2 = t1 + ((1.5*hiz));

def t3 = t2 + ((1.5*hiz));

def t4 = t3 + ((1.5*hiz));

AddLabel(yes, "Risk: " + RA, color.Dark_red);

AddLabel(yes, "  Shares: " + amounts, color.blue);

AddLabel(yes, "  Entry: " + entries, color.dark_green);

AddLabel(yes, "  Stop: " + stops, color.red);

AddLabel(yes, "  Target 1: " + t1, color.light_ORANGE);

AddLabel(yes, "  Target 2: " +t2, color.magenta);

AddLabel(yes, "  Target 3: " + t3, color.light_orange);
 
I agree that there are differences that have been discussed between TOS and TV. I've been using the TV official version of the PowerX Strategy Bar Coloring [OFFICIAL VERSION] from Rockwell Trading and I have found that these TOS RSM indicator settings seem to match the TV chart for me:

RSI - Wilders
Stoch - Wilders
MACD - Exponential

Although when I use these settings in the TOS scanner, I still get some UpTrendJustStarted miscompares. That is the scanner will indicate that an UpTrendJust started for a stock and when I look at the stock in my chart on TOS, it doesn't indicate that the UpTrendJustStarted. I have been debugging and hopefully will figure out where my disconnect is.
Are you using scan and chart same settings?
 
Are you using scan and chart same settings?
Yep. I think I figured it out, somehow the scan script RSI type got changed to SIMPLE and I know I checked it multiple times. I have several scans, so I may have been looking at one and changing another. I cleaned up the files to avoid any further confusion.
 
Great work and thank you for your efforts. One question, what is the difference between the solid red or green candles vs the red or green outline candles?
 
User preference mostly, @massfamone. Whatever is easier to see on your monitor and how you have it set up, white versus black background.
 
User preference mostly, @massfamone. Whatever is easier to see on your monitor and how you have it set up, white versus black background.
Hey RickAns, thank you for the reply, but not sure if my question was understood. Some candles are just a green or red outline, where some candles are painted green or red. What is the difference between a outlined red/green vs full red/green candle?
 
Hey RickAns, thank you for the reply, but not sure if my question was understood. Some candles are just a green or red outline, where some candles are painted green or red. What is the difference between a outlined red/green vs full red/green candle?
Those are candle types TOS defaults you are looking for, FullBody's are sell off and Hollow Candles are BuyUP. RSM overrides the color of TOS candles, so Don't Consider the Red and Greens as TOS default Colors, they are respective RSM Trends as defined.

-S
 
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
410 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top