Comparison Chart Script problem

Stevep

New member
The source code for the COMPARISON study is not available. I have a chart for stocks that is simply the Haiken Ashi candles with a 7 period moving average that changes colors (green up, red down) I just want to be able to do a comparison with an index or ETF like SPY or QQQ, whereby those look similar to the tickers. I did work on thinkscript for quite a while to figure it out and I am missing something in the code.

This is my code for the color changing M.A. THIS code works fine for the tickers.

input Length = 7;
input AvgType = AverageType.SIMPLE;
input Price = Close;

plot Slope = MovingAverage(AvgType, Price, Length);

Slope.Definecolor("Positive",color.red);
Slope.Definecolor("Negative",color.green);

Slope.AssignValueColor(if Slope > Slope[1] then Slope.Color("Negative") else Slope.Color("Positive"));

Below is the script that I thought would work for the ETF's but not yet:

I need to some how include the Heiken Ashi type of chart.

input comparisonStyle = {"BAR", "LINE", default "CANDLE"};
input secondarySecurity = "";
declare lower;
input length = 7;
plot momentum = close - (length);
momentum.DefineColor("positive", Color.UPTICK);
momentum.DefineColor ("NEGATIVE", Color.DOWNTICK);
momentum.AssignValueColor(if momentum >= 0 then momentum.color.GREEN("POSITIVE") else momentum.Color.RED("NEGATIVE"))

1727209593641.png

I hope someone can come to my rescue and be a hero!! Thank you and I am happy to further discuss.

Thank you,
Stevep
 
Solution
The source code for the COMPARISON study is not available. I have a chart for stocks that is simply the Haiken Ashi candles with a 7 period moving average that changes colors (green up, red down) I just want to be able to do a comparison with an index or ETF like SPY or QQQ, whereby those look similar to the tickers. I did work on thinkscript for quite a while to figure it out and I am missing something in the code.

This is my code for the color changing M.A. THIS code works fine for the tickers.

input Length = 7;
input AvgType = AverageType.SIMPLE;
input Price = Close;

plot Slope = MovingAverage(AvgType, Price, Length);

Slope.Definecolor("Positive",color.red);
Slope.Definecolor("Negative",color.green)...
The source code for the COMPARISON study is not available. I have a chart for stocks that is simply the Haiken Ashi candles with a 7 period moving average that changes colors (green up, red down) I just want to be able to do a comparison with an index or ETF like SPY or QQQ, whereby those look similar to the tickers. I did work on thinkscript for quite a while to figure it out and I am missing something in the code.

This is my code for the color changing M.A. THIS code works fine for the tickers.

input Length = 7;
input AvgType = AverageType.SIMPLE;
input Price = Close;

plot Slope = MovingAverage(AvgType, Price, Length);

Slope.Definecolor("Positive",color.red);
Slope.Definecolor("Negative",color.green);

Slope.AssignValueColor(if Slope > Slope[1] then Slope.Color("Negative") else Slope.Color("Positive"));

Below is the script that I thought would work for the ETF's but not yet:

I need to some how include the Heiken Ashi type of chart.

input comparisonStyle = {"BAR", "LINE", default "CANDLE"};
input secondarySecurity = "";
declare lower;
input length = 7;
plot momentum = close - (length);
momentum.DefineColor("positive", Color.UPTICK);
momentum.DefineColor ("NEGATIVE", Color.DOWNTICK);
momentum.AssignValueColor(if momentum >= 0 then momentum.color.GREEN("POSITIVE") else momentum.Color.RED("NEGATIVE"))

View attachment 22991
I hope someone can come to my rescue and be a hero!! Thank you and I am happy to further discuss.

Thank you,
Stevep

This uses the addchart() unsupported, but usable, function.
Move this lower study to the upper price panel and check 'left axis' at the input screen


Code:
#Addchart_heikinashi_symbol_specific
declare lower;
input sym = "SPY";
input charttype = ChartType.CANDLE;
def h;
def l;
def o;
def c;
h = if IsNaN(close(symbol = sym)) then h[1] else high(symbol  = sym);
l = if IsNaN(close(symbol = sym)) then l[1] else low(symbol   = sym);
o = if IsNaN(close(symbol = sym)) then o[1] else open(symbol  = sym);
c = if IsNaN(close(symbol = sym)) then c[1] else close(symbol = sym);

DefineGlobalColor("Positive", Color.UPTICK);
DefineGlobalColor("Negative", Color.DOWNTICK);

def HAclose = if IsNaN(close) then Double.NaN else (o + h + l + c) / 4;
def HAopen  = if IsNaN(close) then Double.NaN else CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
def haopen_ = if IsNaN(close) then Double.NaN else if HAopen > HAclose
              then HAopen + 0
              else Double.NaN;
def HAhigh  = if IsNaN(close) then Double.NaN else if haopen_ >= HAclose
              then Max(Max(h, haopen_), HAclose)
              else Double.NaN;
def HAlow   = if IsNaN(close) then Double.NaN else if HAopen >= HAclose
              then Min(Min(l, haopen_), HAclose)
              else Double.NaN;

AddChart(growColor = GlobalColor("Negative"), high = HAhigh, low = HAlow, open = haopen_, close = HAclose, type = charttype);

def HAclose1 = if IsNaN(close) then Double.NaN else (o + h + l + c) / 4;
def HAopen1  = if IsNaN(close) then Double.NaN else CompoundValue(1, (HAopen1[1] + HAclose1[1]) / 2, (o[1] + c[1]) / 2);
def haopen_1 = if IsNaN(close) then Double.NaN else if HAopen1 <= HAclose1
               then HAopen1 + 0
               else Double.NaN;
def HAhigh1  = if IsNaN(close) then Double.NaN else Max(Max(h, haopen_1), HAclose1);
def HAlow1   = if IsNaN(close) then Double.NaN else Min(Min(l, haopen_1), HAclose1);

AddChart(growColor = GlobalColor("Positive"), high = HAhigh1, low = HAlow1, open = HAclose1, close = haopen_1, type = charttype);
 
Solution

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
262 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