Repaints Moxie for ThinkorSwim

Repaints

tradegeek

Active member
2019 Donor
9UXnzEn.png


I don't know if anyone has come across this neat indicator called the "Moxie Indicator". It seems the creator of this indicator has it developed for Ninjatrader and Thinkorswim but he's not releasing the TOS version because he doesn't want the code shared. He has partnered up with John Carter from SimplerTrading to provide alerts based on this indicator.

You can check it out here...

It would be nice if something like this can be replicated. I am not a programmer so I wouldn't know where to start. Can it be reversed engineered from a NinjaTrader script?

Much success to all!

Edit #1: @diazlaz converted a TradingView script that mimicked the Moxie script: https://usethinkscript.com/threads/moxie-indicator-for-thinkorswim.369/post-36862

Edit #2: Check out @Slippage version of the Moxie Indicator here: https://usethinkscript.com/threads/moxie-indicator-for-thinkorswim.369/post-53789

Edit #3: @Slippage reviews of the paid Moxie indicator https://usethinkscript.com/threads/moxie-indicator-for-thinkorswim.369/post-53751
 
Last edited by a moderator:
@tradegeek IMO, I would just move on. Never buy an indicator. Find a system that works for you and keep working it. There are many hundred of them on this website to research. Start in the Tutorials as well as Look at the built in Strategies.

Code:
# Moxie_PriceChannel_Adjustable
# Built on 5/11/20
# For use on a All Time Frames

input channelLength = 34;
input averageType = AverageType.EXPONENTIAL;
input PriceChannel_Aggregation = AggregationPeriod.FIFTEEN_MIN;
input Moxie_highestAggregation = AggregationPeriod.TEN_MIN;
input Moxie_lowestAggregation = AggregationPeriod.FIVE_MIN;

def MovAvg_H = MovingAverage(averageType, high, channelLength);
def MovAvg_C = MovingAverage(averageType, close, channelLength);
def MovAvg_L = MovingAverage(averageType, low, channelLength);

def MovAvg_H1x = (MovAvg_H - MovAvg_L) + MovAvg_H;
def MovAvg_L1x = MovAvg_L - (MovAvg_H - MovAvg_L);

# HTF_Ergodic Momentum ----------------------------------------------
def diff = close(period=PriceChannel_Aggregation) - close(period=PriceChannel_Aggregation)[1];
def TSI  = (ExpAverage(ExpAverage(diff, 32), 5)) / (ExpAverage(ExpAverage(AbsValue(diff), 32), 5)) * 100;
def Signal = ExpAverage(TSI, 5);
def Momentum = TSI - Signal;
def LHMult = If (.01 <> 0, (1 / 0.01), 0);
def TSVBlues = If (Momentum >= 0, Momentum, 0);
def TSVMomentum_Pos = TSVBlues * LHMult;
def TSVReds = If (Momentum < 0, Momentum, 0);
def TSVMomentum_Neg = TSVReds * LHMult;

# HTF ERGODIC Price Channel Momentum Indicator ----------------------------------------
plot PC_H = MovAvg_H;
plot PC_L = MovAvg_L;

PC_H.DefineColor("SlopeUp", CreateColor(0, 153, 0)); #createColor(0,153,0)); GREEN
PC_H.DefineColor("NoSlope", Color.GRAY);
PC_H.DefineColor("SlopeDown", Color.RED);
PC_H.AssignValueColor(if TSVmomentum_Pos then PC_H.Color("SlopeUp") else if TSVmomentum_Neg then PC_L.Color("SlopeDown") else PC_H.Color("NoSlope"));
PC_H.SetLineWeight(2);
PC_H.HideBubble();

PC_L.DefineColor("SlopeUp", CreateColor(0, 153, 0));#createColor(0,153,0)); GREEN
PC_L.DefineColor("NoSlope", Color.GRAY);
PC_L.DefineColor("SlopeDown", Color.RED);
PC_L.AssignValueColor(if TSVmomentum_Pos then PC_L.Color("SlopeUp") else if TSVmomentum_Neg then PC_L.Color("SlopeDown") else PC_L.Color("NoSlope"));
PC_L.SetLineWeight(2);
PC_L.HideBubble();

# MOXIE - This section is for the medium term MACD ---------------------------------------------
def midTermFastAvg = ExpAverage(close(period = Moxie_lowestAggregation), 12);
def midTermSlowAvg = ExpAverage(close(period = Moxie_lowestAggregation), 26);
def midTermValue = midTermFastAvg - midTermSlowAvg;
def midTermAvg = ExpAverage(midTermValue, 9);
def midTermDiff = (midTermValue - midTermAvg)*3;

# MOXIE - This section is for the long term MACD -----------------------------------------------
def longTermFastAvg = ExpAverage(close(period = Moxie_highestAggregation), 12);
def longTermSlowAvg = ExpAverage(close(period = Moxie_highestAggregation) , 26);
def longTermValue = longTermFastAvg - longTermSlowAvg;
def longTermAvg = ExpAverage(longTermValue, 9);
def longTermDiff = (longTermValue - longTermAvg)*3;

# Signal Criteria -----------------------------------------------------------------------
def midTermLower = midTermDiff < 0 and midTermDiff < midTermDiff[1];
def midTermHigher = midTermDiff > 0 and midTermDiff > midTermDiff[1];

def longTermLower = longTermDiff < 0 and longTermDiff < longTermDiff[1];
def longTermHigher = longTermDiff > 0 and longTermDiff > longTermDiff[1];

#########################################################################
plot BuySignal = if midTermHigher and LongTermHigher then MovAvg_L1x else Double.NaN;
BuySignal.SetDefaultColor (Color.White); #(CreateColor(0, 153, 0));
BuySignal.SetPaintingStrategy(PaintingStrategy.POINTS);
BuySignal.SetLineWeight(2);
BuySignal.HideBubble();
BuySignal.HideTitle();

plot SellSignal = if midTermLower and LongTermLower then MovAvg_H1x else Double.NaN;
SellSignal.SetDefaultColor(Color.White);
SellSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
SellSignal.SetLineWeight(2);
SellSignal.HideBubble();
SellSignal.HideTitle();

# Cloud Fill -----------------------------
AddCloud(MovAvg_H, MovAvg_L, Color.LIGHT_GRAY);

alert (close>BuySignal,"ChannelDotup", alert.bar,Sound.ding);
alert (close<SellSignal,"ChannelDotdown", alert.bar,Sound.ding);

#alert (close>BuySignal,"ChannelDotup", alert.once,Sound.ding);
#alert (close<SellSignal,"ChannelDotdown", alert.once,Sound.ding);
 
I liked his explanation. Seems to me its some custom indicator based on RSI like criteria (e.g. momentum based indicator). Very likely he uses multiple timeframe cross to generate signal (e.g. change colors). Its even clear he has multiple timeframe setup (daily/monthly) for it

It is unbounded and not percentage based ( so more like stochastics/macd in this way).
 
guys I was watching several videos on this Moxie indicator itreally works in showing divergence an entry signals on the 60 min if the daily is align in trend if someone can get this script will be great
 
I have watched many of the indicator videos from Simpler Options. Raghee Horner's approach using her 34 EMA waves with prop dots as well as Darvas really resonated with me. Watched her video a while ago. thought it made a lot of sense
 
I have watched many of the indicator videos from Simpler Options. Raghee Horner's approach using her 34 EMA waves with prop dots as well as Darvas really resonated with me. Watched her video a while ago. thought it made a lot of sense
@tomsk can you summarize the approach? Thanks
 
Basically a trend approach. If there is no trend or sideways, no trade is taken. If I recall correctly it comprises 3-4 different indicators. She mentioned she had been using it for 33 years and her account has never blown up, and survived hedge fund blowups, crashes, etc.
 
Trying to extract the high and low price for the 2nd highest volume bar. Finding it for the highest is easy enough. I'm using a fold statement to iterate thought the range comparing the volume bars to each other. If there is a better way I'm all ears. Appreciate the help.

Code:
declare lower;
input length = 100;

# highest volume bar used to help compare for 2nd highest volume bar
def vol = highest(volume, length);

#2nd highest volume bar need to extract the high and low values. 
def vol2 = fold i = 0 to length with v do if volume[ i ] < vol and volume[ i ] > v then volume[ i ]  else v;

# get the high and low values for the highest volume bar. 
def highPriceVolhigh = GetValue(high, GetMaxValueOffset(volume, length), length);
def lowPriceVolhigh = GetValue(low, GetMaxValueOffset(volume, length), length);

Addcloud(highPriceVolhigh,lowPriceVolhigh,color.light_gray,color.light_gray,yes);

I've searched around the forum and found code that leverages highestall and barnumber to get the highest/lowest values. My ask is bit more complex i'm tying to find the 2nd and 3rd highest volume values x bar before and after the swing high of the volume bar.

I leveraged the swing high swing low code to get the bar number and volume of the first highest volume but now I'll looking from that point to look to find the 2nd highest swing high in that same range. I'm assuming the using the barNumber of the highest volume is the key but i'm not sure how you pass that to HighestAll but not sure how you make a range of it. Any help would be appreciated. Link to image below showing the highest and second highest volume with the price highs and lows for a 5 period lookback and lookforward swing high.

BA.png


Code:
### taken for Robert Paynes swing high low code.
input length = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);

# i get this defines the swing high looking back 10 and foward  10 periods  changed it for volume
def swingHigh = volume > Highest(volume[1], length - 1) and high == GetValue(Highest(volume, length), -offset);
# identify the very last swing high point
#
def highPointOneBarNumber = HighestAll(if swingHigh then bn else 0);

So i gave it a shot and was able to get the next highest value prior to the swing high but not the highest value after the swing high. Instead I get some weird number I think it has to do with the -offset calculation but can't seem to figure why it give a weird number for vol2 plot. Any help would be greatly appreciated.

Code:
input length = 10;

def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingHigh = volume > Highest(volume[1], length - 1) and volume == GetValue(Highest(volume, length), -offset);
def volHighBefore = volume > Highest(volume[1], length - 1);
def volHighAfter = volume == GetValue(Highest(volume, length), -offset);

# identify the very last swing high point
def volHighBarNum = HighestAll(if swingHigh then bn else 0);
def volHighValue = if bn == volHighBarNum then high else volHighValue[1];
plot volHighPrior = if bn < volHighBarNum then Double.NaN else volHighValue;
volHigh.SetDefaultColor(Color.Yellow);

# identify the  highest volume for the last X periods before the last swing high point
def volHighBeforeBarNum = HighestAll(if volHighBefore and bn < volHighBarNum then bn else 0);
def volHighBeforeValue = if bn ==  volHighBeforeBarNum then high else volHighBeforeValue[1];
plot vol1 = if bn < volHighBeforeBarNum then Double.NaN else volHighBeforeValue;
vol1.SetDefaultColor(Color.CYAN);

# identify the  highest volume for the last X periods after the last swing high point
def volHighAfterBarNum = HighestAll(if volHighAfter and bn > volHighBarNum then bn else 0);
def volHighAfterValue = if bn ==  volHighAfterBarNum then high else volHighAfterValue[1];
plot vol2 = if bn < volHighAfterBarNum then Double.NaN else volHighAfterValue;
volHigh.SetDefaultColor(Color.RED);
 
Last edited by a moderator:
This is fairly new to me, so I might not know the appropriate terminology, please bear with me. I am not sure even if I picked the proper category, thank you.

Everyone needs to start somewhere, I might not know what I am doing now, but when I am accomplished, I will surely pass it along. I am requesting help for code that will provide the 3 desired results that could possibly help me.
  • First, Code that will define 5 (swings or waves).
  • Second, code to identify that the 5th (swing or wave) is complete.
  • Third, code that will authenticate that the 5th (swing or wave) is longer than the 3rd swing.
Is this complicated? Whatever you can do for me will be deeply appreciated.

What I was trying to do was. I wanted the highest SWING at the top of the screen. Next have the 2 black candles right after the swing HIGH. And lastly I wanted the 2 black candles to be as close as possible to be Last 2 candles on this chart

Code:
def peak =  ( close < close[1] and close[1] < close[2] and close[2] > close[3] and close[3] > close[4]) ;
plot scan = peak;
plot scan highestall (high);
input length = 20;
def = islongblack = islongblack(length);
plot twolongblack = islongblack[1] and islongblack;

My objective is to place a down arrow over close[4] the highest point in the pivot

Code:
def peak = ( close < close[1] and close[1] < close[2] and close[2] < close[3] and close[3] < close[4]) and close[4] > close[5] and close [5] > close[6];
plot arrowdown = close[4];
arrowdown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
Arrowdown.SetDefaultColor(Color.WHITE);
Arrowdown.SetLineWeight(4);

Would like to utilize this script I retrieved from funwiththinkscript but I don't know what is missing to plot this to the chart. I was hoping that Robert or someone was available to help me make this happen. I am new and do not understand the switch concept.

Code:
input xyz = {"major", default "minor"};

def R3;
def R2;
def R1;
def PP;
def S1;
def S2;
def S3;
switch (xyz) {
case "major":
PP = MajorCalculation;
R1 = MajorCalculation;
R2 = MajorCalculation;
R3 = MajorCalculation;
S1 = MajorCalculation;
S2 = MajorCalculation;
S3 = MajorCalculation;
case "minor":
PP = MinorCalculation;
R1 = MinorCalculation;
R2 = MinorCalculation;
R3 = MinorCalculation;
S1 = MinorCalculation;
S2 = MinorCalculation;
S3 = MinorCalculation;
}

plot PP = if Switch == 1 then MinorCalculation else MajorCalculation;
 
@lee-I-O=coke-A Hi Bernie, and welcome to useThinkScript.com. I am a senior citizen living with brain injury as well.
I do not mean this to be short or snippy:

Please migrate to the tutorial section and look at the Universe of ThinkScript. If one has been created, you'll find it in there.

There is also this post https://usethinkscript.com/threads/wolf-waves-trendline-breakouts-indicator-for-thinkorswim.66/

Google "SyracusePro Thinkscript". I believe that Victor has worked with Elliot, Kondriedtiff and Wolf Waves among others.

Questions: Have you scheduled a platform tour? You are entitled to one. Please contact ThinkorSwim support and ask for one to be scheduled.
Be sure to write down 10 questions to ask that are of interest to you so that your time is well spent.

Why are you starting with such an extremely difficult study to start with? I'd suggest starting smaller.

As far as your last line above, VIP status can be searched for in the Box above.
 
Is this related to Elliott wave by any chance? See if this can be any help to ya (but I doubt it)

Code:
## Mobius' swing high/low script.
## Added Fib retracements and extensions

# The number of bars to look back.
input n = 20;

# Set minDollarRange > 0 to turn off 0.382 and 0.618 Fibs,
# when dollar value of HighLine - LowLine range is less than
# chosen minDollarRange. Set to zero to ignore setting.
input minDollarRange = 200.0;

# Allow lines to be drawn in expansion area (Yes).
input rightExt = Yes;

def H = high;
def L = low;
def cBar = barNumber();
def PH;
def PL;

def isH = fold i = 1 to n + 1 with p = 1
while p do H > getValue(H, -i);

PH = if (cBar > n and H == Highest(H, n) and isH) then H
else double.NaN;

def isL = fold j = 1 to n + 1 with q = 1
while q do L < getValue(L, -j);

PL = if (cBar > n and L == Lowest(L, n) and isL) then l
else double.NaN;

rec PHL = if !IsNaN(PH) then PH else PHL[1];
rec PLL = if !IsNaN(PL) then PL else PLL[1];

def bOk = !IsNaN(h) or rightExt;

plot HighLine = if bOk and PHL > 0 then PHL else double.NaN;
HighLine.SetDefaultColor(Color.Light_Red);
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.SetLineWeight(1);

plot LowLine = if bOk and PLL > 0 then PLL else double.NaN;
LowLine.SetDefaultColor(Color.Light_Green);
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.SetLineWeight(1);

########################################
## Fib Retracements

def Ext0_382 = 0.382;
def Ext0_618 = 0.618;
def Ext0_2 = 0.2;
def Ext0_8 = 0.8;

def rHi = HighLine;
def rLo = LowLine;

def tmidP = (rHi + rLo) / 2;
def range = rHi - rLo;
def F0_382 = rHi - (range * Ext0_382);
def F0_618 = rHi - (range * Ext0_618);
def F0_2 = rHi - (range * Ext0_2);
def F0_8 = rHi - (range * Ext0_8);

def rangeValue = (AbsValue(range) / tickSize()) * tickValue();

def rangeValueOK = minDollarRange <= rangeValue;

plot FibMid = tmidP;
plot Fib0_382 = if !rangeValueOK then Double.NaN else F0_382;
plot Fib0_618 = if !rangeValueOK then Double.NaN else F0_618;
plot Fib0_2 = F0_2;
plot Fib0_8 = F0_8;

FibMid.HideTitle();
FibMid.SetDefaultColor(Color.White);
FibMid.SetPaintingStrategy(PaintingStrategy.DASHES);
FibMid.SetLineWeight(1);

Fib0_382.HideTitle();
Fib0_382.SetDefaultColor(Color.Gray);
Fib0_382.SetPaintingStrategy(PaintingStrategy.DASHES);

Fib0_618.HideTitle();
Fib0_618.SetDefaultColor(Color.Gray);
Fib0_618.SetPaintingStrategy(PaintingStrategy.DASHES);

Fib0_2.HideTitle();
Fib0_2.SetDefaultColor(Color.Gray);
Fib0_2.SetPaintingStrategy(PaintingStrategy.DASHES);

Fib0_8.HideTitle();
Fib0_8.SetDefaultColor(Color.Gray);
Fib0_8.SetPaintingStrategy(PaintingStrategy.DASHES);

########################################
## Fib Extensions

def FH_382 = range + if !IsNaN(h) then F0_382 else F0_382[1];
;

plot FibH_382 = FH_382;

FibH_382.HideTitle();
FibH_382.SetDefaultColor(Color.Cyan);
FibH_382.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibH_382.SetLineWeight(1);

def FL_618 = (if !IsNaN(h) then F0_618 else F0_618[1]) - range;

plot FibL_618 = FL_618;

FibL_618.HideTitle();
FibL_618.SetDefaultColor(Color.Magenta);
FibL_618.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibL_618.SetLineWeight(1);
 
Is there an Indicator somewhere that draws a dot on the swing highs and lows ? I did some searching in here and havent found anything . Thanks

kyXnuu9.png
 
I have this indicator which was provided as part of a training course I took , long time back. I cant find the documentation for it and haven't received response from its authors. Any chance someone can help summarize what it might be doing? It plots some good resistance/support lines, but don't understand how its being calculated.

Code:
# Trading Analysis Swing Waves - Trader
# Version 1.0
# 6/13/2016
#
# Authors: Brian Strong - Micro Quant ([email protected]) SwingWave detection
#          Daniel Sinnig - Biiuse Trading ([email protected]) Ideal entry detection
#

input MajorSwingPeriod = 13;
input MinorSwingPeriod = 5;
input AlertsOn = yes;
input ExpansionFactor = 1.0;
input LookBackPeriod = 200;
input ADXPeriod = 21;
input ShowCounterTrendEntries = no;

def powerStopsOff = no;

def signalOffsetFactor = 0.20;
def offset = Average(TrueRange(high, close, low), 9) * signalOffsetFactor;

#Calculate Major Swings
def majorPivotH = if high > Highest(high[1], MajorSwingPeriod) and high >
Highest(high[-MajorSwingPeriod], MajorSwingPeriod) then 1 else 0;
def majorH = if majorPivotH then high+offset else Double.NaN;
def majorPivotL = if low < Lowest(low[1], MajorSwingPeriod) and low <
Lowest(low[-MajorSwingPeriod], MajorSwingPeriod) then 1 else 0;
def majorL = if majorPivotL then low-offset else Double.NaN;

#Calculate Minor Swings
def minorPivotH = if high > Highest(high[1], MinorSwingPeriod) and high >
Highest(high[-MinorSwingPeriod], MinorSwingPeriod) then 1 else 0;
def minorH = if minorPivotH then high+offset else Double.NaN;
def minorPivotL = if low < Lowest(low[1], MinorSwingPeriod) and low <
Lowest(low[-MinorSwingPeriod], MinorSwingPeriod) then 1 else 0;
def minorL = if minorPivotL then low-offset else Double.NaN;

#Ideal entry detection
#Find last minor and major High and Lows
def indexOfLastMinorHigh = fold minorHighIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod  while IsNaN(GetValue(minorH, minorHighIndex)) do minorHighIndex + 1;
def indexOfLastMinorLow = fold minorLowIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod while IsNaN(GetValue(minorL, minorLowIndex)) do minorLowIndex + 1;
def indexOfLastMajorHigh = fold majorHighIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod while IsNaN(GetValue(majorH, majorHighIndex)) do majorHighIndex + 1;
def indexOfLastMajorLow = fold majorLowIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod while IsNaN(GetValue(majorL, majorLowIndex)) do majorLowIndex + 1;

#Find High / Low between current bar and last minor low / high (check that it should only minor for major stops as well)/
def indexOfLastHigh_sinceMinorHigh = fold i20 = -MajorSwingPeriod to indexOfLastMinorHigh + 1 with _tempHigh = Double.NEGATIVE_INFINITY do if GetValue(high, i20) > _tempHigh then GetValue(high, i20) else _tempHigh;
def indexOfLastLow_sinceMinorLow = fold i21 = -MajorSwingPeriod to indexOfLastMinorLow + 1 with _tempLow = Double.POSITIVE_INFINITY do if GetValue(low, i21) < _tempLow then GetValue(low, i21) else _tempLow;

def DiPlusDiMinusDiff = DIPlus(ADXPeriod) - DIMinus(ADXPeriod);

#Calculate and set individual differences

#---------------------------------------------
# (1) Major High to major Low
def differenceMajorH_to_MajorL = if IsNaN(majorL)
                                    then 0 #if we are not at a major low then it's 0
                                    else #otherwise find the corresponding major High and calculate the difference
                                        fold i1 = 1 to lookBackPeriod
                                             with diffMajorHighToMajorLow = 0
                                             while (diffMajorHighToMajorLow == 0) do
                                               if (!IsNaN(GetValue(majorL, i1))) then Double.NaN else #if another major low is found then cancel
                                                if (!IsNaN(GetValue(majorH, i1)) and (GetValue(DiPlusDiMinusDiff, i1) < 0)) then Double.NaN #if DI+ is less than DI- then flag as NaN so that loop will stop and it'll be ignored later on
                                                else if (!IsNaN(GetValue(majorH, i1))) then high[i1] - low
                                                                                                  else 0;
def sum_AllDifferences_MajorH_to_MajorL = fold i5 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
                                            with _tempSum_MajorH_to_MajorL = 0 do
                                            if !IsNaN(differenceMajorH_to_MajorL[i5]) then _tempSum_MajorH_to_MajorL + differenceMajorH_to_MajorL[i5] else _tempSum_MajorH_to_MajorL;
                                          
def count_AllDifferences_MajorH_to_MajorL = fold i9 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MajorH_to_MajorL = 0 do if
!IsNaN(differenceMajorH_to_MajorL[i9]) then
    if (differenceMajorH_to_MajorL[i9] <> 0) then _tempCount_MajorH_to_MajorL + 1 else _tempCount_MajorH_to_MajorL
else _tempCount_MajorH_to_MajorL;                                                                                               

def average_MajorH_to_MajorL = if (count_AllDifferences_MajorH_to_MajorL <> 0) then sum_AllDifferences_MajorH_to_MajorL / count_AllDifferences_MajorH_to_MajorL else 0;

#FINAL
plot majorLongEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
    if (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) >= 0)) then indexOfLastHigh_sinceMinorHigh - average_MajorH_to_MajorL * ExpansionFactor else Double.NaN
else Double.NaN);

majorLongEntryLine.SetLineWeight(2);
majorLongEntryLine.SetDefaultColor(Color.GREEN);



#------------------------------------------------
# (2) Major Low to major High

def differenceMajorL_to_MajorH = if IsNaN(majorH)
                                    then 0 #if we are not at a minor high then it's 0
                                    else #otherwise find the corresponding major Low and calculate the difference
                                        fold i2 = 1 to lookBackPeriod
                                             with diffMajorLowToMajorHigh = 0
                                             while (diffMajorLowToMajorHigh == 0) do
                                                if (!IsNaN(GetValue(majorH, i2))) then Double.NaN else #if another major high is found then cancel
                                                if (!IsNaN(GetValue(majorL, i2)) and (GetValue(DiPlusDiMinusDiff, i2) > 0)) then Double.NaN #if DI+ is greater than DI- then flag as NaN so that loop will stop and it'll be ignored later on
                                                else if (!IsNaN(GetValue(majorL, i2))) then high - low[i2]
                                                                                                  else 0;
def sum_AllDifferences_MajorL_to_MajorH = fold i6 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
                                            with _tempSum_MajorL_to_MajorH = 0 do
                                            if !IsNaN(differenceMajorL_to_MajorH[i6]) then _tempSum_MajorL_to_MajorH + differenceMajorL_to_MajorH[i6] else _tempSum_MajorL_to_MajorH;
                                          
def count_AllDifferences_MajorL_to_Major_H = fold i10 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MajorL_to_MajorH = 0 do if
!IsNaN(differenceMajorL_to_MajorH[i10]) then
    if (differenceMajorL_to_MajorH[i10] <> 0) then _tempCount_MajorL_to_MajorH + 1 else _tempCount_MajorL_to_MajorH
else _tempCount_MajorL_to_MajorH;                                                                                           

def average_MajorL_to_MajorH = if (count_AllDifferences_MajorL_to_Major_H <> 0) then sum_AllDifferences_MajorL_to_MajorH / count_AllDifferences_MajorL_to_Major_H else 0;

#FINAL
plot majorShortEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
     if (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) <= 0)) then indexOfLastLow_sinceMinorLow + average_MajorL_to_MajorH * ExpansionFactor else Double.NaN
else Double.NaN);

majorShortEntryLine.SetLineWeight(2);
majorShortEntryLine.SetDefaultColor(Color.RED);

#------------------------------------------------
# (3) Any high to any low (except major to major)

def differenceMinorH_to_MinorL = if IsNaN(minorL)
                                    then 0 #if we are not at a minor low (that is not also a major low)  then it's 0
                                    else #otherwise find the corresponding major High and calculate the difference
                                        fold i3 = 1 to lookBackPeriod
                                             with diffMinorHighToMinorLow = 0
                                             while (diffMinorHighToMinorLow == 0) do
                                               if (!IsNaN(GetValue(minorL, i3))) then Double.NaN else #if another low is found then cancel
                                               if !IsNaN(majorL) and !IsNaN(GetValue(majorH, i3)) then Double.NaN else #exclude major to major
                                               if (!IsNaN(GetValue(minorH, i3)) and (GetValue(DiPlusDiMinusDiff, i3) < 0)) then Double.NaN #if DI+ is less than DI- then flag as NaN so that loop will stop and it'll be ignored later on
                                                else if (!IsNaN(GetValue(minorH, i3))) then high[i3] - low
                                                else 0;

def sum_AllDifferences_MinorH_to_Minor_L = fold i7 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
                                            with _tempSum_MinorH_to_MinorL = 0 do
                                            if !IsNaN(differenceMinorH_to_MinorL[i7]) then _tempSum_MinorH_to_MinorL + differenceMinorH_to_MinorL[i7] else _tempSum_MinorH_to_MinorL;
                                          
def count_AllDifferences_MinorH_to_MinorL = fold i11 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MinorH_to_MinorL = 0 do if
!IsNaN(differenceMinorH_to_MinorL[i11]) then
    if (differenceMinorH_to_MinorL[i11] <> 0) then _tempCount_MinorH_to_MinorL + 1 else _tempCount_MinorH_to_MinorL
else _tempCount_MinorH_to_MinorL;                                                                                                

def average_MinorH_to_MinorL = if (count_AllDifferences_MinorH_to_MinorL <> 0) then sum_AllDifferences_MinorH_to_Minor_L / count_AllDifferences_MinorH_to_MinorL else 0;

#FINAL
plot minorLongEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
if (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) >= 0)) then indexOfLastHigh_sinceMinorHigh - average_MinorH_to_MinorL * ExpansionFactor else Double.NaN
else Double.NaN);

minorLongEntryLine.SetDefaultColor(Color.GREEN);

#------------------------------------------------
# (4) Minor Low (not major) to Minor High (not major)

def differenceMinorL_to_MinorH = if IsNaN(minorH)
                                    then 0 #if we are not at a minor low (that is not also a major low)  then it's 0
                                    else #otherwise find the corresponding major High and calculate the difference
                                        fold i4 = 1 to lookBackPeriod
                                             with diffMinorLowToMinorHigh = 0
                                             while (diffMinorLowToMinorHigh == 0) do
                                                if (!IsNaN(GetValue(minorH, i4))) then Double.NaN else #if another high is found then cancel
                                                if !IsNaN(majorH) and !IsNaN(GetValue(majorL, i4)) then Double.NaN else #exclude major to major
                                                if (!IsNaN(GetValue(minorL, i4)) and (GetValue(DiPlusDiMinusDiff, i4) > 0)) then Double.NaN #if DI+ is greater than DI- then flag as NaN so that loop will stop and it'll be ignored later on
                                                    else if (!IsNaN(GetValue(minorL, i4))) then high - low [i4]
                                                    else 0;

def sum_AllDifferences_MinorL_to_MinorH = fold i8 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
                                            with _tempSum_MinorL_to_MinorH = 0 do
                                            if !IsNaN(differenceMinorL_to_MinorH[i8]) then _tempSum_MinorL_to_MinorH + differenceMinorL_to_MinorH[i8] else _tempSum_MinorL_to_MinorH;
                                          
def count_AllDifferences_MinorL_to_MinorH = fold i12 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MinorL_to_MinorH = 0 do if
!IsNaN(differenceMinorL_to_MinorH[i12]) then
    if (differenceMinorL_to_MinorH[i12] <> 0) then _tempCount_MinorL_to_MinorH + 1 else _tempCount_MinorL_to_MinorH
else _tempCount_MinorL_to_MinorH;                                                                                             

def average_MinorL_to_MinorH = if (count_AllDifferences_MinorL_to_MinorH <> 0) then sum_AllDifferences_MinorL_to_MinorH / count_AllDifferences_MinorL_to_MinorH else 0;

#FINAL
plot minorShortEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
if  (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) <= 0)) then indexOfLastLow_sinceMinorLow + average_MinorL_to_MinorH * ExpansionFactor else Double.NaN
else Double.NaN);

minorShortEntryLine.SetDefaultColor(Color.RED);

Here is another indicator that plots the swing highs and swing lows in ThinkorSwim. You set the length period to identify the highest price point and lowest price point within the lookback period.

Code:
# HINT: this code is a TOS  Mr Scripts Chart study
# that plots an Exponential moving average line
# and also finds and counts swing high/swing low points

input length = 50;
input price = close;
input averageType = AverageType.EXPONENTIAL;


plot avg = MovingAverage(averageType, price, length);
def height = avg - avg[length];
def AngleDeg = ATan(height / length) * 180 / Double.Pi;
def up = AngleDeg >= 0.0;
avg.AssignValueColor(if up then Color.RED else Color.BLUE);


input swing_back = 8;
input swing_forward = 2;
input maxbars = 30;
input showlevels = Yes;
def na = Double.NaN;
def lfor = Lowest(low, swing_forward)[-swing_forward];
def lback = Lowest(low, swing_back)[1];
def swinglow = if low < lfor and low <= lback then 1 else 0;
plot sl = if swinglow then low else na;
def hfor = Highest(high, swing_forward)[-swing_forward];
def hback = Highest(high, swing_back)[1];
def swinghigh = if high > hfor and high >= hback then 1 else 0;
plot sh = if swinghigh then high else na;
sh.SetStyle(Curve.POINTS);
sh.SetLineWeight(5);
sh.SetDefaultColor(Color.BLUE);
sl.SetStyle(Curve.POINTS);
sl.SetLineWeight(5);
sl.SetDefaultColor(Color.BLUE);

rec countd = CompoundValue(2, if !up and (swinglow or swinghigh) then countd[1] + 1 else if up and (swinglow or swinghigh)  then 0 else countd[1], 1);

rec count = CompoundValue(2, if up and (swinglow or swinghigh) then count[1] + 1 else if !up and (swinglow or swinghigh)  then 0 else count[1], 1);

plot x = if (swinglow or swinghigh) and count != 0 then count else Double.NaN;
x.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot y = if (swinglow or swinghigh) and countd != 0 then countd else Double.NaN;
y.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 
Can we create a script that shows the confluence of the major and minor wave lines at tops and bottoms.... garleys whatever that shows on all time frames with an audible alert when these points converge and preferably an upper indicator.

Example

N9A8ZAy.png
 
Last edited by a moderator:
I'm using the below code to create previous high and low levels. seems to work well.

How can i get this to allow me to store the 2nd previous swing high or 2nd previous swing low?

My goal is to compare the the 2nd previous high to the current previous high to determine up or down trend.

I have tried using the simple Support[1] > Support[2] but it doesn't seem to work. When i add these to a label, it only gives me to current high or low no matter what value i put into the [ ].

Please help.

Code:
#SWING HIGH LOW
input LookbackPeriod = 3;
input HideCurrentTF = no;

#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod);
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;

rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod];
def _markedHigh1 = high == marketHigh1;

rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then high else _lastMarkedHigh1[1], high);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Support1 = _lastMarkedLow1 ;

#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance1.SetDefaultColor(Color.GREEN);
Resistance1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.DASHES);
Support1.SetDefaultColor(Color.RED);
Support1.SetHiding(HideCurrentTF);

I'm struggling with this. I feel like this should be something relatively easy to figure out but i can't seem to crack the logic on this. Simply doubling the lookback period doesn't help.

For example - I just want to record the previous 2 highs of 82.94 and 82.90 as well as the 2 previous lows of 82.25 and 82.33. Once i can do that, i can use them for comparison.
 
Last edited by a moderator:
@flyingfalcon Moxie indicator is same as MACD but on a higher time frame. For daily, it is MACD on weekly time frame. Hahn-tech as it available here - https://www.hahn-tech.com/thinkorswim-mtf-macd-indicator/

I found this in 2018, but did not think it was very useful. After checking out recent promo videos on Moxie trader, it seems like a useful tool.
the default setting on hahn-tech has current time frame MACD enabled. make sure to disable 'Value', 'Avg' and 'Diff' by unchecking 'Show plot'. And enable 'midTermDiff' plot.

Hope this helps
 
Hi team, I'm looking to code up an indicator that tells me if the current high takes out a previous swing high.

Wo far I've got this with my poor thinkscript skills.

#returns a list of local tops - aka highest pivot high with 10 bars to the left and 10 to the right
def isMinorHigh = fold i = -10 to 10 with isHigh = high do (if GetValue(high, i) > high then 0 else isHigh);

#returns the last value of the high that's not NaN
def getPreviousHigh = fold j = 0 to 99 while GetValue(isMinorHigh, j)<0.1 do GetValue(isMinorHigh, j+1);

#this should return if the current high of the bar is higher than the previous high
plot scan = high > getPreviousHigh[1];

For some reason, this code works as a label on a chart quite well (ex: high>getPreviousHigh[1]) but it doesn't work in the scanner - i think the scan query kinda defaults to 'true' and I am not sure how to debug what causes it and the limitations of the scanner etc.

Anybody got any ideas?

Thanks!
 
I posted an older study using the above techniques so I thought I would throw out an update. I have not used TOS for a while and decided to pick it up again after using trade view... well I'm back toTOS.

Primarily the strategy consists of using a script that will plot market wave highs and lows posting a label at each high and low showing the price change amount this is the core of my strategy.

The lines plotted for major and minor waves continue until the major and minor lines will converge for at some point at a market high/low and when they do these are the best odds for a successful trade, they form triangles at tops and bottoms of price channels.

The indicators I use: market moves 2.0, 8/15 exponential moving averages, Laguerre upper study https://tos.mx/X0hJEUz with a Laguerre MTF lower study https://tos.mx/eTzkKBu, can use harmonic patterns the script https://tos.mx/2LfTtet basically that's it.

JaBjfxY.png


Personally I do not use harmonics but its the closest thing to my script that is not available to share and I trade a 2 min chart I primarily scalp but extend those lines out on higher time frames and follow for gains.

Can also think of using the wave lines as a heads up to change in price direction and probably the best way to confirm buy sell signals is by using the lower RSI in Laguerre Time MTF Option_v3 script and watch for the cross below 8 and above 2 shown on the 1 hr chart. https://tos.mx/DEBxarm

K8740Ge.png


I've combined some studies that help to validate my wave the wave theory I'm using the CCI/ATR, moving average crossover upper, and a harmonics study I came across. I split the charts so the left chart shows the above cross over and the right shows the below crossover with all else being the same indicators just be sure to change that under the crossover script.

5obucqM.png


https://tos.mx/Uk9UCNR

I'm watching AMD running a 4-hour chart and only using minor waves. We finished out a minor yesterday and the price still dropping so I wait for the next minor wave to draw to ending a 4h drawdown before I consider buying back in, always keep an eye on the daily for lines to be drawn.

7JI79L4.png
 
Last edited by a moderator:
Once you install the indicator as explained on the hahn-tech link above, you need to make sure that mid-term > selected timefrade. the label will tell you if the time frame is correct. for example, for current time frame = daily, select mid term = "Weekly"; for hourly period, select mid-term='Daily" and for 15 min, select mid-term="60 min"
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
512 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