True Momentum Oscillator for ThinkorSwim

T

tomsk

Well-known member
VIP
@switchfire I did some work with the TMO Scan a while ago - Have a read through post #93 and #96 It might get you closer to what you seek. If not adjustments can be made
 
switchfire

switchfire

Member
VIP
@switchfire I did some work with the TMO Scan a while ago - Have a read through post #93 and #96 It might get you closer to what you seek. If not adjustments can be made
Yes, i did see your post and have actually been using it :) My problem is that it's specific to the level being set (-10 in this instance) I'm trying to figure out how i can set the scan to not require a specific level.

Thanks for your contributions!!
 
T

tomsk

Well-known member
VIP
Try something like the following. All it does is to make sure that both the main and signal plots have indeed pulled back from the previous bar. However do test it thoroughly and see if this is something you really desire. Note that this does not have the requirement for any specific level

Code:
plot scan = main < main[1] and signal < signal[1];

I just ran that scan on the S&P 500 (Daily aggregation) and obtained 310 results, so looks like the tide has changed
 
Last edited:
H

HighBredCloud

Active member
VIP
@tomsk The scan that you mentioned in post #93 and #96 with the -10 instance...does that indicate the polarity change or simply crossing from oversold? Also if you change the instance to 10 from -10 will that scan for a bearish instance from over bought? Where exactly would you put the code from post #123? at the top or bottom of the code? Thanks...
 
switchfire

switchfire

Member
VIP
Try something like the following. All it does is to make sure that both the main and signal plots have indeed pulled back from the previous bar. However do test it thoroughly and see if this is something you really desire. Note that this does not have the requirement for any specific level

Code:
plot scan = main < main[1] and signal < signal[1];

I just ran that scan on the S&P 500 (Daily aggregation) and obtained 310 results, so looks like the tide has changed
Thanks man! I'll try it out
 
T

tomsk

Well-known member
VIP
@tomsk The scan that you mentioned in post #93 and #96 with the -10 instance...does that indicate the polarity change or simply crossing from oversold? Also if you change the instance to 10 from -10 will that scan for a bearish instance from over bought? Where exactly would you put the code from post #123? at the top or bottom of the code? Thanks...

Note that posts #93 and #96 were custom scan code for @tenacity11 and @markos For more details read the context/requests just prior to those posts

# For #123, note that this was a specific type of scan for @switchfire. If you like to implement this, just use the scan code I posted in #93 as a base. Then replace the plot scan statement at the end of the file

Code:
plot scan = main < level and signal < level and main > signal;
with the following statement. Just remember that the scan engine only accepts a single plot statement. Anything more than that, the scan editor will flag as an error. Simple as that

Code:
plot scan = main < main[1] and signal < signal[1];

Thanks man! I'll try it out
Have a blast with that @switchfire Once you get the hang of it, you'll be confident of writing your own scan queries, have fun!
 
Last edited:
H

HighBredCloud

Active member
VIP
@tomsk Thank You! So just in case anyone else is looking for a TMO scan can you please confirm below bullish and bearish scans if I got that right? I kept your initial Bullish Scan from post #93 and I added a Bearish Scan as well...then I also implemented what you suggested in post #126 for regular TMO Bullish and Bearish Scans...

Bullish/Bearish TMO Scan: Default is set to Bullish Scan

Code:
# TMO ((T)rue (M)omentum (O)scilator) Scan
# Mobius, with modifications by tomsk, 1.1.2020
# V01.05.2018
#hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum

oscillators using price.

input length = 14;
input calcLength = 5;
input smoothLength = 3;
#input level = -10;   ##Bullish Scan
#input level = 10;   ##Bearish Scan

def o = open;
def c = close;
def data = fold i = 0 to length
           with s
           do s + (if c > getValue(o, i)
                   then 1
                   else if c < getValue(o, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);

#hint: Comment out using # below to scan for Bullish or Bearish.  Please note that ## applies to conditional scan with parameters -10 (over sold condition) Bullish Scan) and 10 (over bought condition) Bearish Scan) Default is set to a Bullish TMO Scan without any conditions.

##***Bullish Scan***

##plot scan = main < level and signal < level and main > signal;
plot scan = main < main[1] and signal < signal[1];

##***Bearish Scan***

##plot scan = main > level and signal > level and main < signal;
#plot scan = main > main[1] and signal > signal[1];

# End TMO ((T)rue (M)omentum (O)scilator) Scan
 
YungTraderFromMontana

YungTraderFromMontana

Active member
@markos The higher aggregation causes it to repaint right? Also what is coloring your bars? I couldn't find the study responsible.
 
Last edited:
markos

markos

Well-known member
VIP
@markos The higher aggregation causes it to repaint right? Also what is coloring your bars? I couldn't find the study responsible.
Hi, please read the whole first page. You will see my changes compared to the first post that @BenTen put up. Everything is there in the code.
We must not have the same meaning for repaint,but, what ever the color is, that is what it always will be.
 
YungTraderFromMontana

YungTraderFromMontana

Active member
Hi, please read the whole first page. You will see my changes compared to the first post that @BenTen put up. Everything is there in the code.
We must not have the same meaning for repaint,but, what ever the color is, that is what it always will be.
So if it closes red it stays red? If so this is amazing. Thanks
 
markos

markos

Well-known member
VIP
So if it closes red it stays red? If so this is amazing. Thanks
Your welcome. Just confirm with your eyes that what I say and what you believe are the same thing.
Look at the pictures all the way down page one.
You can go into the editor and change the colors of the weekly to what ever you wish so that they stand out better. ...ok, back to the employees...
 
Last edited:
switchfire

switchfire

Member
VIP
Would there might be a way to backtest a strategy of buying and selling based on momentum changes?
 
H

HighBredCloud

Active member
VIP
So if it closes red it stays red? If so this is amazing. Thanks
@YungTraderFromMontana I use this indicator...IF you are using a higher aggregation for example...You are using a 5 min chart but you have your TMO set to 30 min...Then the MAIN and SIGNAL will repaint on TMO indicator when you're looking on a 5 min chart...the last 6 bars will change color...This makes it hard to check your strategy after the market closes and the charts aren't live because of the repaint on higher aggregation. I hope that helps.
 
BenTen

BenTen

Administrative
Staff
VIP
@switchfire Sure, what would be your condition for buying and selling?
 
switchfire

switchfire

Member
VIP
@switchfire Sure, what would be your condition for buying and selling?
Thanks for the reply Ben,

I'd like to test the crossover on various time frames, and maybe even eventually mix and match, e.g. buy on 30 min green cross and sell on hourly red crossover. For now, just a standard cross for a specific time frame would be a good place to start. What do you think?
 
switchfire

switchfire

Member
VIP
I just thought about it and realized it's probably not possible to back test on diff time frames. What about a simple cross over? Also, could i add another condition, eg rsi crosses a number or similar.
 
BenTen

BenTen

Administrative
Staff
VIP
@switchfire Here is a simple crossover buy/sell strategy for you to backtest. You can also take this same concept and apply it to other indicators.

Code:
# TMO ((T)rue (M)omentum (O)scilator)
# Mobius
# V01.05.2018
# hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.
# 01/27/2020 Backtesting code added by BenTen

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
def data = fold i = 0 to length


           with s
           do s + (if c > getValue(o, i)


                   then 1
                   else if c<getValue(o, i)


                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal
                      then color.green
                           else color.red);
     Signal.AssignValueColor(if Main > Signal
                             then color.green
                             else color.red);
     Signal.HideBubble();
     Signal.HideTitle();
addCloud(Main, Signal, color.green, color.red);
plot zero = if isNaN(c) then double.nan else 0;
     zero.SetDefaultColor(Color.gray);
     zero.hideBubble();
     zero.hideTitle();
plot ob = if isNaN(c) then double.nan else round(length* .7);
ob.SetDefaultColor(Color.gray);
     ob.HideBubble();
     ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(length* .7);
os.SetDefaultColor(Color.gray);
     os.HideBubble();
     os.HideTitle();
addCloud(ob, length, color.light_red, color.light_red, no);
addCloud(-length, os, color.light_green, color.light_green);
# End Code TMO

# Backtesting Code
def buy = Main crosses above Signal;
def sell = Main crosses below Signal;

AddOrder(OrderType.BUY_AUTO, condition = buy, price = close,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BUY");
AddOrder(OrderType.SELL_AUTO, condition = sell, price = close,100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SELL");
 
markos

markos

Well-known member
VIP
@YungTraderFromMontana I use this indicator...IF you are using a higher aggregation for example...You are using a 5 min chart but you have your TMO set to 30 min...Then the MAIN and SIGNAL will repaint on TMO indicator when you're looking on a 5 min chart...the last 6 bars will change color...This makes it hard to check your strategy after the market closes and the charts aren't live because of the repaint on higher aggregation. I hope that helps.
Youse guys are using the wrong definition of repaint. The TMO with even 5 aggs would NOT repaint. It just doesn't. @BenTen time for a board meeting!
 
markos

markos

Well-known member
VIP
Draw a circle around the repaint or get off the subject, please.

 
horserider

horserider

Well-known member
VIP
Markos has it correct. It is not a repaint. A repaint is a drawn plot that then changes in the future. If drawn on the close and a future close causes the plot to change it is a repaint. This is where MTF confuses things. On the five minute chart your 5 min TMO plots on the close so will update with a new bar each 5 min. Meanwhile the 30 min TMO also plots on the close. To see the plot of the 30 min you need to wait for the 30 minutes to pass for the next plot. It is not repainting but simply has not passed the time needed to plot the next point.

Are you saying the 5 min plot is changing when the 30 min plot is printed? Those plots should be independent. If that is occurring possible you have somehow introduced an error into the code you are using.
 

Top