Iceman1205us
New member
I follow Nextsignals blog - a couple of his studies are posted on this site. He recently released a trend following study:
https://nextsignals.com/2022/08/15/modified-thinkscript-for-adaptive-moving-average/
His theory is chart forecasting is dead due to the auction market and that one has probably better success with the trend. I compared his study with a 4x EMA average study using Fib values 1, 5, 13, 21 and the lines look very similar. I don't know the math make up is but I thought I'd give his study a shot and put it my chart. First thing I wanted to do besides change colors is to display reversal arrows. I've added this code in and it works well enough, but I'm wondering why on different time frames the arrow is lagging and paints on the following candle? Is it because this is a single plot vs different plots that cross, like a 8 and 21 EMA or is it something ese?
Secondly, I made a scan and watchlist from it. Scan works fine due to the addition of the arrows, but for the worklist columns, instead of displaying the default label "Long" or "Short" I'd like copy the Keltner Momentum Channels column that Pensar created. I'm not a coder, more a dabbler and I have no idea what his count code is doing:
https://usethinkscript.com/threads/momentum-keltner-channels-for-thinkorswim.2855/
I thought maybe I all needed to do was just have copy the two codes together, rewrite "plot MAA" to def MAA and redirect "def avg = MAA" but, alas, the numbers values are off. Obviously there's some black counting magic going on.
Any help would be appreciated. Thanks
https://nextsignals.com/2022/08/15/modified-thinkscript-for-adaptive-moving-average/
His theory is chart forecasting is dead due to the auction market and that one has probably better success with the trend. I compared his study with a 4x EMA average study using Fib values 1, 5, 13, 21 and the lines look very similar. I don't know the math make up is but I thought I'd give his study a shot and put it my chart. First thing I wanted to do besides change colors is to display reversal arrows. I've added this code in and it works well enough, but I'm wondering why on different time frames the arrow is lagging and paints on the following candle? Is it because this is a single plot vs different plots that cross, like a 8 and 21 EMA or is it something ese?
Code:
# Arrows
plot Buy = MAA crosses above MAA[1];
Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy.SetDefaultColor(createColor(0,255,0));
Buy.SetLineWeight(4);
plot Sell = MAA crosses below MAA[1];
Sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Sell.SetDefaultColor(createColor(255,0,0));
Sell.SetLineWeight(4);
Secondly, I made a scan and watchlist from it. Scan works fine due to the addition of the arrows, but for the worklist columns, instead of displaying the default label "Long" or "Short" I'd like copy the Keltner Momentum Channels column that Pensar created. I'm not a coder, more a dabbler and I have no idea what his count code is doing:
https://usethinkscript.com/threads/momentum-keltner-channels-for-thinkorswim.2855/
I thought maybe I all needed to do was just have copy the two codes together, rewrite "plot MAA" to def MAA and redirect "def avg = MAA" but, alas, the numbers values are off. Obviously there's some black counting magic going on.
Code:
# Worklist column combining Nextsignal and Keltner Momentum Channel, trying to duplicate Keltner Column count for NextSignal
# NextSignal Adaptive Moving Average
# https://nextsignals.com/2022/08/15/modified-thinkscript-for-adaptive-moving-average/
def lastBar = BarNumber();
def current = HighestAll(If(IsNaN(close), 0, lastBar));
## Chop Thinkorswim’s MovAvgAdaptive
input mode = {default KAMA, AMA};
def direction;
def volatility;
def ER;
switch (mode) {
case KAMA:
direction = AbsValue(close – close[10]);
volatility = Sum(AbsValue(close – close[1]), 10);
ER = if volatility != 0 then direction / volatility else 0;
case AMA:
direction = Double.NaN;
volatility = Double.NaN;
ER = AbsValue((close – Lowest(low, 10)) –
(Highest(high, 10) – close)) / (Highest(high,
10) – Lowest(low, 10));}
def SlowSF = 0.2222;
def ScaledSF = ER * (0.4 – SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (close – AMA[1]),
close);
def MAA = AMA;
# Keltner Momentum Channel Worklist code
# https://usethinkscript.com/threads/momentum-keltner-channels-for-thinkorswim.2855/
# Momentum Keltner Channels Watchlist Column
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)
# The count displayed in the watchlist shows the number of bars since a break up or break down
input length = 34;
input factor = 0.5;
input displace = 0;
input price = close;
input type = AverageType.Simple;
def nan = double.nan;
def shift = factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg = MAA;
def line1 = avg[-displace] - shift[-displace];
def line2 = avg[-displace] + shift[-displace];
def Chg = if(close > line2, 1, if(close < line1, -1, 0));
def Hold = CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);
def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def count1 = if n1 and !n1[1] then 1 else count1[1]+1;
def count2 = if n2 and !n2[1] then 1 else count2[1]+1;
plot n = if n1 then count1 else if n2 then count2 else double.nan;
n.setdefaultcolor(color.black);
assignbackgroundcolor(if n1 and count1 then color.green else color.red);
#End of code
Any help would be appreciated. Thanks
Last edited by a moderator: