Vertical Bar on EMA crossover

Hello,

In Ninjatrader, there is an indicator that paints a vertical bar when two lines cross. In this case, I have configured it to paint a pink bar when my 9 EMA crosses below the 21 EMA, and a green bar when 9 crosses over 21. It gives me a good visual of the cross over. Does something similar exist in TOS? Can someone write a script for me if it does not?

Thanks,

AJ
 

Attachments

  • Screenshot 2023-06-23 095651.png
    Screenshot 2023-06-23 095651.png
    7.8 KB · Views: 99
Solution
Hello,

In Ninjatrader, there is an indicator that paints a vertical bar when two lines cross. In this case, I have configured it to paint a pink bar when my 9 EMA crosses below the 21 EMA, and a green bar when 9 crosses over 21. It gives me a good visual of the cross over. Does something similar exist in TOS? Can someone write a script for me if it does not?

Thanks,

AJ

I modified a previous code that had various options for crossovers to add your request for a cloud.

Screenshot 2023-07-07 160544.png
Code:
# Example_Addchartbubble_Addchart_Clouds_movavgcrosser
#
#

input show_arrows  = yes;
input show_cross_clouds  = yes;
input show_bubbles_up_dn = yes;
input show_bubbles_time  = yes;
input price = close;
input length1 = 15;
input length2 = 30...
Hello,

In Ninjatrader, there is an indicator that paints a vertical bar when two lines cross. In this case, I have configured it to paint a pink bar when my 9 EMA crosses below the 21 EMA, and a green bar when 9 crosses over 21. It gives me a good visual of the cross over. Does something similar exist in TOS? Can someone write a script for me if it does not?

Thanks,

AJ


this will use cloud() to draw a rectangle, between the 2 bars, on each side of 2 averages crossing.

can change this,
input cloud_factor = 0.1;
, to change the rectangle height.


Code:
#avg_cross_cloud

#https://usethinkscript.com/threads/vertical-bar-on-ema-crossover.15889/
#Vertical Bar on EMA crossover

def na = double.nan;
def bn = barnumber();

def price = close;

input ma1_len = 9;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 21;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

input show_lines = yes;
plot z1 = if show_lines then ma1 else na;
z1.setdefaultcolor(getcolor(1));
#z1.setlineweight(1);
z1.hidebubble();
plot z2 = if show_lines then ma2 else na;
z2.setdefaultcolor(getcolor(2));
#z2.setlineweight(1);
z2.hidebubble();

def ma1xup = (ma1 crosses above ma2);
def ma1xdwn = (ma1 crosses below ma2);

input cloud_factor = 0.1;
#input show_cross_cloud = yes;

def top1;
def bot1;
if ma1xup[-1] then {
# green , 1st bar
  top1 = max(high[0], high[-1]) * (1 + (cloud_factor/100));
  bot1 = min(low[0], low[-1]) * (1 - (cloud_factor/100)); 
} else if ma1xup[0] then {
# green , 2nd bar
  top1 = max(high[1], high[0]) * (1 + (cloud_factor/100));
  bot1 = min(low[1], low[0]) * (1 - (cloud_factor/100));
} else if ma1xdwn[-1] then {
# red , 1st bar
  bot1 = max(high[0], high[-1]) * (1 + (cloud_factor/100));
  top1 = min(low[0], low[-1]) * (1 - (cloud_factor/100)); 
} else if ma1xdwn[0] then {
# red , 2nd bar
  bot1 = max(high[1], high[0]) * (1 + (cloud_factor/100));
  top1 = min(low[1], low[0]) * (1 - (cloud_factor/100));
} else {
  top1 = na;
  bot1 = na;
}

addcloud(top1, bot1, color.light_green, color.magenta);

#

teP0ODK.jpg
 
Hello,

In Ninjatrader, there is an indicator that paints a vertical bar when two lines cross. In this case, I have configured it to paint a pink bar when my 9 EMA crosses below the 21 EMA, and a green bar when 9 crosses over 21. It gives me a good visual of the cross over. Does something similar exist in TOS? Can someone write a script for me if it does not?

Thanks,

AJ

I modified a previous code that had various options for crossovers to add your request for a cloud.

Screenshot 2023-07-07 160544.png
Code:
# Example_Addchartbubble_Addchart_Clouds_movavgcrosser
#
#

input show_arrows  = yes;
input show_cross_clouds  = yes;
input show_bubbles_up_dn = yes;
input show_bubbles_time  = yes;
input price = close;
input length1 = 15;
input length2 = 30;
input averageType1 = AverageType.EXPONENTIAL;
input averageType2 = AverageType.EXPONENTIAL;


plot avg1 = MovingAverage(averageType1, price, length1);
plot avg2 = MovingAverage(averageType2, price, length2);

plot signalup = if avg1 crosses above avg2 then avg1 else Double.NaN;
plot signaldn = if avg1 crosses below avg2 then avg2 else Double.NaN;

signalup.SetDefaultColor(Color.GREEN);
signaldn.SetDefaultColor(Color.RED);
signalup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
signaldn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
signalup.SetHiding(!show_arrows);
signaldn.SetHiding(!show_arrows);

#Time defined
input timezone = {default "ET", "CT", "MT", "PT"};

def starthour  = (if timezone == timezone."ET"
                        then 9
                        else if timezone == timezone."CT"
                        then 8
                        else if timezone == timezone."MT"
                        then 7
                        else 6) ;
def hour = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60;
#

AddChartBubble(show_bubbles_up_dn and signalup, avg1 - TickSize() * 2, "UP", Color.GREEN, no);
AddChartBubble(show_bubbles_time and signalup, avg1 - TickSize() * 2, hour + ":" + (if minutes < 10
            then "0" else "") + minutes, Color.WHITE, no);

AddChartBubble(show_bubbles_up_dn and signaldn, avg2 + TickSize() * 2, "DN", Color.RED, yes);
AddChartBubble(show_bubbles_time and signaldn, avg2 + TickSize() * 2, hour + ":" + (if minutes < 10
            then "0" else "") + minutes, Color.WHITE, yes);

def up = signalup;
def dn = signaldn;

#Cloud
def uph = if IsNaN(up[-1]) and up
              then Double.POSITIVE_INFINITY else Double.NaN;
def upl = if IsNaN(up[-1]) and up
              then Double.NEGATIVE_INFINITY else Double.NaN;
def dnh = if IsNaN(dn[-1]) and dn
              then Double.POSITIVE_INFINITY else Double.NaN;
def dnl = if IsNaN(dn[-1]) and dn
              then Double.NEGATIVE_INFINITY else Double.NaN;

AddChart(if !show_cross_clouds then Double.NaN else uph, upl, uph, upl, ChartType.CANDLE, growColor = Color.GREEN);
AddChart(if !show_cross_clouds then Double.NaN else dnh, dnl, dnh, dnl, ChartType.CANDLE, growColor = Color.RED);
 
Last edited:
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
479 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