Arrows Not Showing//EMA-SMA

picasso11205

New member
VIP
Can anyone assist me in getting the arrows to show in the Thinkscript code below? I am not very experienced with Thinkscript coding, watched a bunch of videos but as you can see from my elementary attempt I am pretty much useless. :) Any help you can provide would be greatly appreciated.

declare upper;
input short_average = 8;
input medium_average = 14;
input long_average = 28;
input average_type = {default "SMA", "EMA"};
input showArrows = yes;

def MA1;
def MA2;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
}

# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(color.blue);
ln1.SetStyle(Curve.LONG_DASH);
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(color.yellow);
ln2.SetStyle(Curve.LONG_DASH);

# Calculate Meter Values
def sl1 = ma1 > ma1[1];
def sl2 = ma2 > ma2[1];
def p1 = close > ma1;
def p2 = close > ma2;
def u1 = 2 * (close > open);
def u2 = 2 * (close > high[1]);
def d1 = 2 * (close < open);
def d2 = 2 * (close < low[1]);

def UPstr = sl1 + sl2 + p1 + p2 + u1 + u2;
def DNstr = !sl1 + !sl2 + !p1 +!p2 + d1 + d2;
 
Solution
Can anyone assist me in getting the arrows to show in the Thinkscript code below? I am not very experienced with Thinkscript coding, watched a bunch of videos but as you can see from my elementary attempt I am pretty much useless. :) Any help you can provide would be greatly appreciated.

declare upper;
input short_average = 8;
input medium_average = 14;
input long_average = 28;
input average_type = {default "SMA", "EMA"};
input showArrows = yes;

def MA1;
def MA2;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
}

# Plot the moving average lines
plot ln1 = MA1...
Can anyone assist me in getting the arrows to show in the Thinkscript code below? I am not very experienced with Thinkscript coding, watched a bunch of videos but as you can see from my elementary attempt I am pretty much useless. :) Any help you can provide would be greatly appreciated.

declare upper;
input short_average = 8;
input medium_average = 14;
input long_average = 28;
input average_type = {default "SMA", "EMA"};
input showArrows = yes;

def MA1;
def MA2;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
}

# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(color.blue);
ln1.SetStyle(Curve.LONG_DASH);
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(color.yellow);
ln2.SetStyle(Curve.LONG_DASH);

# Calculate Meter Values
def sl1 = ma1 > ma1[1];
def sl2 = ma2 > ma2[1];
def p1 = close > ma1;
def p2 = close > ma2;
def u1 = 2 * (close > open);
def u2 = 2 * (close > high[1]);
def d1 = 2 * (close < open);
def d2 = 2 * (close < low[1]);

def UPstr = sl1 + sl2 + p1 + p2 + u1 + u2;
def DNstr = !sl1 + !sl2 + !p1 +!p2 + d1 + d2;

the last bit of this code looked kind of interesting, so i loaded it.
first thing i always do is add bubbles to display variables on every bar, so i can see what is going on.
then i changed the bubble color to be green or red, depending on if the upstr count was higher or the dnstr count.
then i could see a pattern.
then i decided to base a direction on if, the up count was higher or the down count
then check when direction changed , and draw an arrow

this looks for 2 ups in a row, then it changes to up, or if 2 dwns in a row, then down
2 labels to show the count on the current bar

Code:
#avg_cnt_cross_arrows

#https://usethinkscript.com/threads/arrows-not-showing-ema-sma.20939/
#Arrows Not Showing//EMA-SMA
#picasso11205  4/22

#Can anyone assist me in getting the arrows to show in the Thinkscript code below? I am not very experienced with Thinkscript coding, watched a bunch of videos but as you can see from my elementary attempt I am pretty much useless. :) Any help you can provide would be greatly appreciated.


declare upper;

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

input short_average = 8;
input medium_average = 14;
input long_average = 28;
input average_type = {default "SMA", "EMA"};
input showArrows = yes;

def MA1;
def MA2;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
}

# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(color.blue);
ln1.SetStyle(Curve.LONG_DASH);
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(color.yellow);
ln2.SetStyle(Curve.LONG_DASH);

# Calculate Meter Values
def sl1 = ma1 > ma1[1];
def sl2 = ma2 > ma2[1];
def p1 = close > ma1;
def p2 = close > ma2;
def u1 = 2 * (close > open);
def u2 = 2 * (close > high[1]);
def d1 = 2 * (close < open);
def d2 = 2 * (close < low[1]);

def UPstr = sl1 + sl2 + p1 + p2 + u1 + u2;
def DNstr = !sl1 + !sl2 + !p1 +!p2 + d1 + d2;

addlabel(1, "UP cnt  " + upstr, color.green);
addlabel(1, "DOWN cnt  " + dnstr, color.red);

input test1_bubbles = no;
addchartbubble(test1_bubbles, low*0.992,
upstr + " up\n" +
dnstr + " dwn"
, (if upstr > dnstr then color.green else if upstr < dnstr then color.red else color.gray), no);

def up = upstr > dnstr;
def dwn = upstr < dnstr;

#create formula for ups and downs, to remove up/dwn jitters
#  is  2 in a row and 3rd back is diff ?
def dir = if up and up[1] and !up[2] then 1
 else if dwn and dwn[1] and !dwn[2] then -1
 else dir[1];

#i dont like arrows touching candles, so i space them away a little bit. easier to see
plot uparrow = if dir>0 and dir[1]<0 then low*0.998 else na;
uparrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
uparrow.SetDefaultColor(Color.green);
uparrow.setlineweight(4);
uparrow.hidebubble();

plot dwnarrow = if dir<0 and dir[1]>0 then high*1.002 else na;
dwnarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
dwnarrow.SetDefaultColor(Color.red);
dwnarrow.setlineweight(4);
dwnarrow.hidebubble();
#
 

Attachments

  • Capture.JPG
    Capture.JPG
    87.3 KB · Views: 81
  • img2.JPG
    img2.JPG
    96.3 KB · Views: 75
Last edited:
Solution

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

Nm, I see that the arrows in JPG1 are appearing without the other indicators in JPG2. Many thanks again for your time and work in responding to my request.
 

Attachments

  • IMG_20250423_123651769.jpg
    IMG_20250423_123651769.jpg
    380.6 KB · Views: 63

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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