# Help me add up and down arrows to VMA indicator

#### coolice521

##### New member
2019 Donor
Code:
``````#
# TD Ameritrade IP Company, Inc. (c) 2008-2019
#

input price = close;
input length = 10;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price
);
plot VMA = asd;
VMA.setDefaultColor(GetColor(0));``````

Can anyone help me change this script to make it rise trending, showing green down trend showing red thank u

#### mc01439

##### Well-known member
2019 Donor
VIP
Code:
``````#
# TD Ameritrade IP Company, Inc. (c) 2008-2019
#

input price = close;
input length = 10;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price
);
plot VMA = asd;
VMA.setDefaultColor(GetColor(0));``````

Can anyone help me change this script to make it rise trending, showing green down trend showing red thank u

Try this, may work better than arrows? If you still want the arrows let me know.

#######################################################################################
input price = close;
input length = 10;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price
);
plot VMA = asd;
#VMA.setDefaultColor(GetColor(0));

AssignPriceColor(if VMA > VMA[1] then Color.GREEN else if VMA < VMA[1] then Color.RED else Color.YELLOW);

Last edited:

#### horserider

##### Well-known member
VIP
@coolice521 See if this is what you want.

Code:
``````#
# TD Ameritrade IP Company, Inc. (c) 2008-2019
#
#Modified to show green line on uptrend and red line on downtrend
#by Horserider 8/14/2019
#######################################################################################
input price = close;
input length = 10;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price
);
plot VMA = asd;

VMA.DefineColor("Up", Color.GREEN);
VMA.DefineColor("Down", Color.RED);
VMA.DefineColor("Even", Color.WHITE);
VMA.AssignValueColor(if VMA > VMA[1] then VMA.Color("Up") else (if VMA == VMA[1] then VMA.Color("Even") else VMA.Color("Down")));
VMA.SetLineWeight(3);``````

Last edited:

#### coolice521

##### New member
2019 Donor
thank you so much

#### coolice521

##### New member
2019 Donor
Can you set a alert for me? Red is for sale, green is for buying

thank you

#### horserider

##### Well-known member
VIP
Took this off my practice chart so just doing this quickly, no idea if it works. I think you will have difficulties as it may alert each bar that is green or red. But not playing with it anymore . Maybe someone else can join in.

Anyway you can try something like this;

#### mc01439

##### Well-known member
2019 Donor
VIP
Can you set a alert for me? Red is for sale, green is for buying

thank you

def alerttrigger1 = VMA > VMA[1] and VMA[1] <= VMA[2];
def alerttrigger2 = VMA < VMA[1] and VMA[1] >= VMA[2];

input alerttext1 = " ++++++++++ VMA BULLISH +++++++++++ ";
input alerttext2 = " ---------- VMA BEARISH ---------- ";
input UseAlerts = {false, default true};
input AlertType = {default "BAR", "ONCE", "TICK"};

input AlertSound = {"Chimes", "Ring", default "Bell", "NoSound", "Ding"};

#### coolice521

##### New member
2019 Donor
thank you so much

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?