Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Hello everybody! I’m very new to trading and TOS, and this is my first post here!
I have a very basic question about strategies.
In this strategy and others Buy/sell signals are calculated on the last known period, and the scripts also fills orders on that same period (buy to open/sell to close).
I’m unsure if this reflect real trading conditions. So to reflect better trading conditions, I was wondering if it was possible to change the way orders are filled. Orders should be filled at open and close prices on the next period (next period relative to the last know period exhibiting the buy/sell signal).
Is there something fundamental I don’t understand?
No, sorry I don't have. I'm just in ToS.@mashume hi Mashume, do you have this version in Ninja? Thx
#
# Hull Moving Average Concavity Divergence
# or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-23 V3
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------
declare lower;
input price = CLOSE;
input HMA_length = 200;
input lookback = 50;
input length = 100;
input displace = 0;
def HMA = HullMovingAvg(length = HMA_length, price = price);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
plot zero = 0;
zero.setdefaultcolor(color.gray);
zero.setpaintingstrategy(PaintingStrategy.DASHES);
plot divergence = HMA - next_bar;
def HMA2 = MovingAverage(AverageType.HULL, divergence, length)[-displace];
divergence.setDefaultColor(Color.LIME);
divergence.SetLineweight(2);
assert(length > 0, "'length' must be positive: " + length);
def EMA = compoundValue(1, EMA[1] + 2 / (length + 1) * (divergence[-displace] - EMA[1]), divergence[-displace]);
plot LegacyEMA = EMA;
LegacyEMA.SetDefaultColor(GetColor(1));
plot cx_up = if divergence crosses above zero then 0 else double.nan;
cx_up.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_up.SetDefaultColor(Color.LIGHT_GREEN);
cx_up.SetLineWeight(4);
plot cx_down = if divergence crosses below zero then 0 else double.nan;
cx_down.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_down.SetDefaultColor(Color.RED);
cx_down.SetLineWeight(4);
Is this what you want -I love this setup. Can you share this screenshot please
That's the MA_MIN plot. You can un-check it in the indicator settings. No need to edit the code. You can, of course take the tinker-kit out and mod the source code if you really want.@mashume
Hey again!
I noticed that sometimes the indicator (after popping up with the white triangle that initiates a light-green trend line) will delete the triangle or move it on to the next candlestick after roughly 30sec-1min of showing up initially.
Is there any way to turn this off or delete any line of code in the settings? I'm still running the initial release version because I've found it to be the most consistent with my strategy.
Thanks again for your persistent hard work!
Well I actually love that part of the indicator, as it's what I use as an entry. My true question is is there a way to make it stick and not move mid candlestick?That's the MA_MIN plot. You can un-check it in the indicator settings. No need to edit the code. You can, of course take the tinker-kit out and mod the source code if you really want.
-mashume
Oh I see. Repainting is, unfortunately, a part of this indicator occasionally. Less so if you use CLOSE prices, but then it's not as reactive or timely necessarily.Well I actually love that part of the indicator, as it's what I use as an entry. My true question is is there a way to make it stick and not move mid candlestick?
For example, I used it on the 3m chart for SPY today and it popped at 10:21EST so I entered. About 35seconds later I look back and I do not see the "white triangle" I spoke of earlier. That's where I was a bit confused. If there is no way to keep it once it's been placed regardless, I just thought I'd ask.
Thanks again
#
# Hull Moving Average Concavity Divergence
# or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-23 V3
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------
declare lower;
input price = CLOSE;
input HMA_length = 200;
input lookback = 50;
input length = 100;
input displace = 0;
def HMA = HullMovingAvg(length = HMA_length, price = price);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
plot zero = 0;
zero.setdefaultcolor(color.gray);
zero.setpaintingstrategy(PaintingStrategy.DASHES);
plot divergence = HMA - next_bar;
plot HMA2 = MovingAverage(AverageType.HULL, divergence, length)[-displace];
assert(length > 0, "'length' must be positive: " + length);
input highLowLength = 10;
def multiplier1 = 2 / (length + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (divergence - ma[1]), Average(divergence, length));
plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));
plot cx_up = if divergence crosses above zero then 0 else double.nan;
cx_up.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_up.SetDefaultColor(Color.LIGHT_GREEN);
cx_up.SetLineWeight(4);
plot cx_down = if divergence crosses below zero then 0 else double.nan;
cx_down.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_down.SetDefaultColor(Color.RED);
cx_down.SetLineWeight(4);
divergence.DefineColor("Up", GetColor(1));
divergence.DefineColor("Down", GetColor(0));
divergence.AssignValueColor(if divergence > AEMA then divergence.color("Up") else divergence.color("Down"));
# END
#
# Hull Moving Average Concavity Divergence
# or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-23 V3
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------
declare lower;
input price = CLOSE;
input Divergencelength = 200;
input lookback = 50;
input HMAlength = 200;
input displace = 0;
input EMAlength = 100;
input AEMAlength = 100;
def HMA = HullMovingAvg(length = Divergencelength, price = price);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
plot zero = 0;
zero.setdefaultcolor(color.gray);
zero.setpaintingstrategy(PaintingStrategy.DASHES);
plot divergence = HMA - next_bar;
plot HMA2 = MovingAverage(AverageType.HULL, divergence, HMAlength)[-displace];
assert(HMAlength > 0, "'length' must be positive: " + HMAlength);
def EMA = compoundValue(1, EMA[1] + 2 / (EMAlength + 1) * (divergence[-displace] - EMA[1]), divergence[-displace]);
plot LegacyEMA = EMA;
LegacyEMA.SetDefaultColor(GetColor(1));
input highLowLength = 10;
def multiplier1 = 2 / (AEMAlength + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (divergence - ma[1]), Average(divergence, AEMAlength));
plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));
plot cx_up = if divergence crosses above zero then 0 else double.nan;
cx_up.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_up.SetDefaultColor(Color.LIGHT_GREEN);
cx_up.SetLineWeight(4);
plot cx_down = if divergence crosses below zero then 0 else double.nan;
cx_down.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_down.SetDefaultColor(Color.RED);
cx_down.SetLineWeight(4);
divergence.DefineColor("Up", GetColor(1));
divergence.DefineColor("Down", GetColor(0));
divergence.AssignValueColor(if divergence > LegacyEMA then divergence.color("Up") else divergence.color("Down"));
# END
declare lower;
input price = CLOSE;
input HMA_length = 34;
input lookback = 2;
input length = 100;
input displace = 0;
input EMAlength = 100;
input AEMAlength = 20;
def HMA = HullMovingAvg(length = HMA_length, price = price);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
plot zero = 0;
zero.setdefaultcolor(color.gray);
zero.setpaintingstrategy(PaintingStrategy.DASHES);
plot divergence = HMA - next_bar;
def HMA2 = MovingAverage(AverageType.HULL, divergence, HMA_length)[-displace];
divergence.setDefaultColor(Color.LIME);
divergence.SetLineweight(2);
assert(HMA_length > 0, "'length' must be positive: " + HMA_length);
def EMA = compoundValue(1, EMA[1] + 2 / (EMAlength + 1) * (divergence[-displace] - EMA[1]), divergence[-displace]);
plot LegacyEMA = EMA;
LegacyEMA.SetDefaultColor(GetColor(1));
input highLowLength = 10;
def multiplier1 = 2 / (AEMAlength + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (divergence - ma[1]), Average(divergence, AEMAlength));
plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));
plot cx_up = if divergence crosses above zero then 0 else double.nan;
cx_up.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_up.SetDefaultColor(Color.LIGHT_GREEN);
cx_up.SetLineWeight(4);
plot cx_down = if divergence crosses below zero then 0 else double.nan;
cx_down.SetPaintingStrategy(PaintingStrategy.POINTS);
cx_down.SetDefaultColor(Color.RED);
cx_down.SetLineWeight(4);
# END
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
S | Exponential Hull Moving Average (EHMA) for ThinkorSwim | Indicators | 8 | |
Safe Hull Moving Average Indicator for ThinkorSwim | Indicators | 3 | ||
Hull Format, Label, Watchlist, Scan for ThinkorSwim | Indicators | 115 | ||
L | A Volume Pressure Moving Average For ThinkOrSwim | Indicators | 15 | |
T | Mega Moving Average For ThinkOrSwim | Indicators | 26 |
Start a new thread and receive assistance from our community.
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.
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.