Variable MA Format, Watchlist, Label, Scan For ThinkOrSwim

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:

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;
Alert(UpAlert VMA > VMA(1), "VMA Uptrend", Alert.BAR, Sound.RING);
Alert(UpAlert VMA < VMA(1), "VMA Downtrend", Alert.BAR, Sound.RING);
 

mc01439

Well-known member
2019 Donor
VIP
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);
 

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.
Top