MA Crossover with Signals

woulf1004

Active member
VIP
Hi,

Can someone help with this script and add a couple of functions to it.

1. Add the option to choose either the SMA or EMA for both 50MA and 200MA to crossover.
2. Add arrow plotting when the 50MA crosses above or below the 200MA on a Heikin Ashi tick chart or minute chart as well.
3. Assign price color like green when the candle closes above the 50MA and the 50MA is above the 200MA, change color to red if the the candle closes below the 50MA and the 50MA is below the 200MA, and finally color gray if the the candles are in between the 50MA and 200MA.

input price = close;
input length = 50;
input length2 = 200;
input displace = 0;
input showBreakoutSignals = no;

plot AvgExp = ExpAverage(price[-displace], length);
plot AvgExp2 = ExpAverage(price[-displace], length2);
plot UpSignal = price crosses above AvgExp;
plot DownSignal = price crosses below AvgExp;


UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

AvgExp.SetDefaultColor(GetColor(1));
AvgExp2.SetDefaultColor(GetColor(3));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

input showlabels = yes;

addlabel( 1,(if AvgExp > AvgExp2 then "E50 > E200" else if AvgExp < AvgExp2 then "E50 < E200" else "-"), if AvgExp > AvgExp2 then color.cyan else if AvgExp < AvgExp2 then color.gray else color.Orange);

AddLabel(showlabels, "|", Color.YELLOW);
 
Hi,

Can someone help with this script and add a couple of functions to it.

1. Add the option to choose either the SMA or EMA for both 50MA and 200MA to crossover.
2. Add arrow plotting when the 50MA crosses above or below the 200MA on a Heikin Ashi tick chart or minute chart as well.
3. Assign price color like green when the candle closes above the 50MA and the 50MA is above the 200MA, change color to red if the the candle closes below the 50MA and the 50MA is below the 200MA, and finally color gray if the the candles are in between the 50MA and 200MA.

input price = close;
input length = 50;
input length2 = 200;
input displace = 0;
input showBreakoutSignals = no;

plot AvgExp = ExpAverage(price[-displace], length);
plot AvgExp2 = ExpAverage(price[-displace], length2);
plot UpSignal = price crosses above AvgExp;
plot DownSignal = price crosses below AvgExp;


UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

AvgExp.SetDefaultColor(GetColor(1));
AvgExp2.SetDefaultColor(GetColor(3));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

input showlabels = yes;

addlabel( 1,(if AvgExp > AvgExp2 then "E50 > E200" else if AvgExp < AvgExp2 then "E50 < E200" else "-"), if AvgExp > AvgExp2 then color.cyan else if AvgExp < AvgExp2 then color.gray else color.Orange);

AddLabel(showlabels, "|", Color.YELLOW);

Your requests and corresponding changes made in the code are numbered to match so you can see them.

The image is a Heikin Ashi tick chart with the arrows appearing at the crossover of the averages.

Capture.jpg
Ruby:
#1. Add the option to choose either the SMA or EMA for both 50MA and 200MA to crossover.
#2. Add arrow plotting when the 50MA crosses above or below the 200MA on a Heikin Ashi tick chart or minute chart as well.
#3. Assign price color like green when the candle closes above the 50MA and the 50MA is above the 200MA, change color to red if the the candle closes below the 50MA and the 50MA is below the 200MA, and finally color gray if the the candles are in between the 50MA and 200MA.

input avgtype1 = AverageType.EXPONENTIAL;# request 1
input avgtype2 = AverageType.EXPONENTIAL;# request 1
input price = close;
input length = 50;
input length2 = 200;
input displace = 0;
input showBreakoutSignals = no;

plot Avg1 = MovingAverage(avgtype1, price[-displace], length);# request 1
plot Avg2 = MovingAverage(avgtype2, price[-displace], length2);# request 1
plot UpSignal = price crosses above Avg1;
plot DownSignal = price crosses below Avg1;
plot Up = if Avg1 crosses above Avg2 then Avg1 else 0;# request 2
plot Dn = if Avg1 crosses below Avg2 then Avg1 else 0;# request 2

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Avg1.SetDefaultColor(GetColor(1));
Avg2.SetDefaultColor(GetColor(3));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Up.SetDefaultColor(Color.UPTICK);
Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Up.SetLineWeight(5);
Dn.SetDefaultColor(Color.DOWNTICK);
Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Dn.SetLineWeight(5);

input showlabels = yes;

AddLabel( 1, (if Avg1 > Avg2 then "50 > 200" else if Avg1 < Avg2 then "50 < 200" else "-"), if Avg1 > Avg2 then Color.CYAN else if Avg1 < Avg2 then Color.GRAY else Color.ORANGE);

AddLabel(showlabels, "|", Color.YELLOW);

input pricecolor = yes;# request 3
AssignPriceColor(if !pricecolor then Color.CURRENT
                 else if close > Avg1 and Avg1 > Avg2
                 then Color.GREEN
                 else if close < Avg1 and Avg1 < Avg2
                 then Color.RED
                 else Color.GRAY);
 

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

Thanks for being awesome! There are a couple of things I would like to fix.

1. Replace and apply the MA script that changes colors based on the Tenkan and Kijun crossover.

input price = close;
input avgtype = AverageType.EXPONENTIAL;
input avglength = 200;
input tenkan_period = 9;
input kijun_period = 26;

plot MA = MovingAverage(avgtype, price, avglength);
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;

Tenkan.SetDefaultColor(GetColor(1));
Kijun.SetDefaultColor(GetColor(2));
MA.AssignValueColor(if MA < Tenkan
then GlobalColor("IchiHigh")
else if MA > Tenkan
then GlobalColor("IchiLow") else GlobalColor("IchiMid"));
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

DefineGlobalColor("IchiHigh", Color.GREEN);
DefineGlobalColor("IchiMid", Color.GRAY);
DefineGlobalColor("IchiLow", Color.RED);

2. Remove the unknown arrows plotted at the bottom of the chart. Please see the attached for your reference.


3. Remove the UpSignal and DownSignals since they are not necessary. Please see the attached for your reference.

 
Thanks for being awesome! There are a couple of things I would like to fix.

1. Replace and apply the MA script that changes colors based on the Tenkan and Kijun crossover.

input price = close;
input avgtype = AverageType.EXPONENTIAL;
input avglength = 200;
input tenkan_period = 9;
input kijun_period = 26;

plot MA = MovingAverage(avgtype, price, avglength);
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;

Tenkan.SetDefaultColor(GetColor(1));
Kijun.SetDefaultColor(GetColor(2));
MA.AssignValueColor(if MA < Tenkan
then GlobalColor("IchiHigh")
else if MA > Tenkan
then GlobalColor("IchiLow") else GlobalColor("IchiMid"));
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

DefineGlobalColor("IchiHigh", Color.GREEN);
DefineGlobalColor("IchiMid", Color.GRAY);
DefineGlobalColor("IchiLow", Color.RED);

2. Remove the unknown arrows plotted at the bottom of the chart. Please see the attached for your reference.


3. Remove the UpSignal and DownSignals since they are not necessary. Please see the attached for your reference.


1. Here is what I think you wanted for #1 which is you want the crossover that was done for the 2 movingaverages above, to be used for the Ichimoku crossover of Tenkan and Kijun instead. #2. I assume those arrows could be from the upsignal/downsignal that #3 that has been removed in this version.

Ruby:
input price = close;
input avgtype = AverageType.EXPONENTIAL;
input avglength = 200;
input tenkan_period = 9;
input kijun_period = 26;

plot MA = MovingAverage(avgtype, price, avglength);
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;

Tenkan.SetDefaultColor(GetColor(1));
Kijun.SetDefaultColor(GetColor(2));
MA.AssignValueColor(if MA < Tenkan
then GlobalColor("IchiHigh")
else if MA > Tenkan
then GlobalColor("IchiLow") else GlobalColor("IchiMid"));
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

DefineGlobalColor("IchiHigh", Color.GREEN);
DefineGlobalColor("IchiMid", Color.GRAY);
DefineGlobalColor("IchiLow", Color.RED);
plot Up = if Tenkan crosses above Kijun then Kijun else 0;
plot Dn = if Tenkan crosses below Kijun then Kijun else 0;

Up.SetDefaultColor(Color.UPTICK);
Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Up.SetLineWeight(5);
Dn.SetDefaultColor(Color.DOWNTICK);
Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Dn.SetLineWeight(5);

input pricecolor = yes;# request 3
AssignPriceColor(if !pricecolor then Color.CURRENT
                 else if close > Tenkan and Tenkan > Kijun
                 then Color.GREEN
                 else if close < Tenkan and Tenkan < Kijun
                 then Color.RED
                 else Color.GRAY);
 
I apologize for the confusion. Let me re organize what I needed for this indicator in the below.

Lets go back to the original script and change only two things.

1. Replace and combine using the script in the below only for the 200MA if possible but if not I don't mind if this is applied to both MA's. Please see the attached for your reference.

input price = close;
input avgtype = AverageType.EXPONENTIAL;
input avglength = 200;
input tenkan_period = 9;
input kijun_period = 26;

plot MA = MovingAverage(avgtype, price, avglength);
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;

Tenkan.SetDefaultColor(GetColor(1));
Kijun.SetDefaultColor(GetColor(2));
MA.AssignValueColor(if MA < Tenkan
then GlobalColor("IchiHigh")
else if MA > Tenkan
then GlobalColor("IchiLow") else GlobalColor("IchiMid"));
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

DefineGlobalColor("IchiHigh", Color.GREEN);
DefineGlobalColor("IchiMid", Color.GRAY);
DefineGlobalColor("IchiLow", Color.RED);

2. Not sure if its a glitch but there are multiple arrows plotted at the bottom of the chart and would like this to be removed. Please refer to the attached for your reference as well.

 
I apologize for the confusion. Let me re organize what I needed for this indicator in the below.

Lets go back to the original script and change only two things.

1. Replace and combine using the script in the below only for the 200MA if possible but if not I don't mind if this is applied to both MA's. Please see the attached for your reference.

input price = close;
input avgtype = AverageType.EXPONENTIAL;
input avglength = 200;
input tenkan_period = 9;
input kijun_period = 26;

plot MA = MovingAverage(avgtype, price, avglength);
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;

Tenkan.SetDefaultColor(GetColor(1));
Kijun.SetDefaultColor(GetColor(2));
MA.AssignValueColor(if MA < Tenkan
then GlobalColor("IchiHigh")
else if MA > Tenkan
then GlobalColor("IchiLow") else GlobalColor("IchiMid"));
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

DefineGlobalColor("IchiHigh", Color.GREEN);
DefineGlobalColor("IchiMid", Color.GRAY);
DefineGlobalColor("IchiLow", Color.RED);

2. Not sure if its a glitch but there are multiple arrows plotted at the bottom of the chart and would like this to be removed. Please refer to the attached for your reference as well.

Isn't that what I provided in post #5. If not, then provide the script that produces the multiple arrows.
 
The indicator in post 5 is a completely different indicator since I still need both the 50 and 200MAs crossover function, arrows that indicates these crossovers and the price assigned colors must be based on the MA crossovers.. not based on the Tenkan and Kijun condition. This Tenkan crossover color change condition must apply only on the 200MA line and nothing else.
In other words. What I need is the upgraded version of script# one that has the MA version that changes colors based on the Tenkan crossover, remove unnecessary arrows at the bottom of the chart but keep everything else.
Not sure if you were able the image provided but if you look at the bottom of the chart there are repeated arrows and would like to remove them. Can this issue be fixed?
 
The indicator in post 5 is a completely different indicator since I still need both the 50 and 200MAs crossover function, arrows that indicates these crossovers and the price assigned colors must be based on the MA crossovers.. not based on the Tenkan and Kijun condition. This Tenkan crossover color change condition must apply only on the 200MA line and nothing else.
In other words. What I need is the upgraded version of script# one that has the MA version that changes colors based on the Tenkan crossover, remove unnecessary arrows at the bottom of the chart but keep everything else.
Not sure if you were able the image provided but if you look at the bottom of the chart there are repeated arrows and would like to remove them. Can this issue be fixed?

this is one of the most confusing threads i have read on here. you ask for changes, then ask for more, but it turns out you really want a different study. you want a study modified to remove arrows, but don't provide the study....

please edit your posts in this thread, and add as the first line ,
study 1
or
study 2
or
...

then a brief description of it.
 
I apologize for the confusion once again.
Please use the STUDY# 1 and adjust only two things for me.

1. Please use the Tenkan MA for the 200MA period instead of the current current version created in STUDY# 1

input price = close;
input avgtype = AverageType.EXPONENTIAL;
input avglength = 200;
input tenkan_period = 9;
input kijun_period = 26;

plot MA = MovingAverage(avgtype, price, avglength);
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;

Tenkan.SetDefaultColor(GetColor(1));
Kijun.SetDefaultColor(GetColor(2));
MA.AssignValueColor(if MA < Tenkan
then GlobalColor("IchiHigh")
else if MA > Tenkan
then GlobalColor("IchiLow") else GlobalColor("IchiMid"));
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

DefineGlobalColor("IchiHigh", Color.GREEN);
DefineGlobalColor("IchiMid", Color.GRAY);
DefineGlobalColor("IchiLow", Color.RED);

2. Please remove the arrows plotted at the bottom of the chart. Attaching an image for your reference.


Once again. All it needs to change from STUDY# 1 is the 200MA and remove the unnecessary arrows plotted at the bottom of the chart.
 
If what I'm asking is too complicated. I will really appreciate it if you can at least remove the yellow arrows plotted at the bottom of the chart from study# 1 in the below? Attaching an image for your reference in regards to the arrow issue marked in red for clarification.

#1. Add the option to choose either the SMA or EMA for both 50MA and 200MA to crossover.
#2. Add arrow plotting when the 50MA crosses above or below the 200MA on a Heikin Ashi tick chart or minute chart as well.
#3. Assign price color like green when the candle closes above the 50MA and the 50MA is above the 200MA, change color to red if the the candle closes below the 50MA and the 50MA is below the 200MA, and finally color gray if the the candles are in between the 50MA and 200MA.

input avgtype1 = AverageType.EXPONENTIAL;# request 1
input avgtype2 = AverageType.EXPONENTIAL;# request 1
input price = close;
input length = 50;
input length2 = 200;
input displace = 0;
input showBreakoutSignals = no;

plot Avg1 = MovingAverage(avgtype1, price[-displace], length);# request 1
plot Avg2 = MovingAverage(avgtype2, price[-displace], length2);# request 1
plot UpSignal = price crosses above Avg1;
plot DownSignal = price crosses below Avg1;
plot Up = if Avg1 crosses above Avg2 then Avg1 else 0;# request 2
plot Dn = if Avg1 crosses below Avg2 then Avg1 else 0;# request 2

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Avg1.SetDefaultColor(GetColor(1));
Avg2.SetDefaultColor(GetColor(3));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Up.SetDefaultColor(Color.UPTICK);
Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Up.SetLineWeight(5);
Dn.SetDefaultColor(Color.DOWNTICK);
Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Dn.SetLineWeight(5);

input showlabels = yes;

AddLabel( 1, (if Avg1 > Avg2 then "50 > 200" else if Avg1 < Avg2 then "50 < 200" else "-"), if Avg1 > Avg2 then Color.CYAN else if Avg1 < Avg2 then Color.GRAY else Color.ORANGE);

AddLabel(showlabels, "|", Color.YELLOW);

input pricecolor = yes;# request 3
AssignPriceColor(if !pricecolor then Color.CURRENT
else if close > Avg1 and Avg1 > Avg2
then Color.GREEN
else if close < Avg1 and Avg1 < Avg2
then Color.RED
else Color.GRAY);

 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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