Help me add up and down arrows to VMA indicator

C

coolice521

New member
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
 
mc01439

mc01439

Active member
VIP
Warehouse
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:
H

horserider

Well-known member
VIP
Warehouse
@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:
C

coolice521

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

thank you
 
H

horserider

Well-known member
VIP
Warehouse
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;
Alert(UpAlert VMA > VMA(1), "VMA Uptrend", Alert.BAR, Sound.RING);
Alert(UpAlert VMA < VMA(1), "VMA Downtrend", Alert.BAR, Sound.RING);
 
mc01439

mc01439

Active member
VIP
Warehouse
Can you set a alert for me? Red is for sale, green is for buying

thank you

#Alert
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"};

def at = AlertType;

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

Alert (alerttrigger1 and UseAlerts, alerttext1, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);

Alert (alerttrigger2 and UseAlerts, alerttext2, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);
 

Top