How can I add MTF to my VPN cloud?

Guille

New member
Code:
declare lower;

input length = 30;
input emaLength = 3;
input averageLength = 30;
input factor = 0.1;
input criticalValue = 10;
input averageType = AverageType.SIMPLE;

def atr = WildersAverage(TrueRange(high, close, low), length);
def diff = hlc3 - hlc3[1];
def vp = Sum(if diff > factor * atr then volume else 0, length);
def vn = Sum(if diff < -factor * atr then volume else 0, length);

plot VPN = ExpAverage(100 * (vp - vn) / Sum(volume, length), emaLength);
plot VPNAvg = MovingAverage(averageType, VPN, averageLength);
plot CriticalLevel = criticalValue;

#VPN.DefineColor("Above", Color.UPTICK);
#VPN.DefineColor("Below", Color.DOWNTICK);
#VPN.AssignValueColor(if VPN > CriticalLevel then VPN.Color("Above") else VPN.Color("Below"));
#VPNAvg.SetDefaultColor(GetColor(7));
CriticalLevel.SetDefaultColor(GetColor(1));
AddCloud(VPN, VPNAvg, Color.GREEN, Color.RED);



VPN.DefineColor("Up", GetColor(1));
VPN.DefineColor("Down", GetColor(0));
VPN.AssignValueColor( if VPN > VPN[1] and VPN > criticallevel then Color.GREEN else if VPN < VPN[1] and VPN > criticallevel then Color.downtick else if VPN > VPN[1] and VPN < criticallevel then Color.YELLOW else if VPN < VPN[1] and VPN < criticallevel then Color.RED else Color.GRAY);

VPNAvg.AssignValueColor(if VPNAvg > CriticalLevel and VPNAvg>VPNAvg[1] then Color.green else if VPNAvg > CriticalLevel and VPNAvg<VPNAvg[1] then Color.red else if VPNAvg < CriticalLevel and VPNAvg>VPNAvg[1] then color.yellow else if VPNAvg < CriticalLevel and VPNAvg<VPNAvg[1] then color.red else color.gray);
 
Last edited by a moderator:
Solution
5 Min chart with Hourly selected as Agg:
wd2lX35.png

Here is the complete code for MTF VPN Clouds:

Ruby:
declare lower;

input useHigherTimeframe = yes;                       # Set to yes to use the higher timeframe input below
input higherTF = AggregationPeriod.HOUR;             # Choose higher timeframe (e.g. MIN, FIFTEEN_MIN, HOUR, DAY, etc.)

input length = 30;
input emaLength = 3;
input averageLength = 30;
input factor = 0.1;
input criticalValue = 10;
input averageType = AverageType.SIMPLE;

def srcHigh = if useHigherTimeframe then high(period = higherTF) else high;
def srcLow  = if useHigherTimeframe then low(period = higherTF) else low;
def srcClose = if useHigherTimeframe then close(period = higherTF)...
Add this to the top of your code (use what ever agg you want):
Code:
input Agg = AggregationPeriod.DAY;

Then for all green syntax highlighting in the editor (Close, etc.), change them all to:
Code:
Close(period = agg)

5 Min chart with Hourly selected as Agg:
 

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

5 Min chart with Hourly selected as Agg:
wd2lX35.png

Here is the complete code for MTF VPN Clouds:

Ruby:
declare lower;

input useHigherTimeframe = yes;                       # Set to yes to use the higher timeframe input below
input higherTF = AggregationPeriod.HOUR;             # Choose higher timeframe (e.g. MIN, FIFTEEN_MIN, HOUR, DAY, etc.)

input length = 30;
input emaLength = 3;
input averageLength = 30;
input factor = 0.1;
input criticalValue = 10;
input averageType = AverageType.SIMPLE;

def srcHigh = if useHigherTimeframe then high(period = higherTF) else high;
def srcLow  = if useHigherTimeframe then low(period = higherTF) else low;
def srcClose = if useHigherTimeframe then close(period = higherTF) else close;
def srcHLC3 = if useHigherTimeframe then hlc3(period = higherTF) else hlc3;
def srcVolume = if useHigherTimeframe then volume(period = higherTF) else volume;

def tr_tf = TrueRange(srcHigh, srcClose, srcLow);
def atr = WildersAverage(tr_tf, length);
def diff = srcHLC3 - srcHLC3[1];

def vp = Sum(if diff > factor * atr then srcVolume else 0, length);
def vn = Sum(if diff < -factor * atr then srcVolume else 0, length);

plot VPN = ExpAverage(100 * (vp - vn) / Max(1, Sum(srcVolume, length)), emaLength);
plot VPNAvg = MovingAverage(averageType, VPN, averageLength);
plot CriticalLevel = criticalValue;

VPNAvg.SetDefaultColor(GetColor(7));

AddCloud(VPN, VPNAvg, Color.GREEN, Color.RED);

VPN.DefineColor("Up", GetColor(1));
VPN.DefineColor("Down", GetColor(0));
VPN.AssignValueColor(
    if VPN > VPN[1] and VPN > CriticalLevel then Color.GREEN
    else if VPN < VPN[1] and VPN > CriticalLevel then Color.DOWNTICK
    else if VPN > VPN[1] and VPN < CriticalLevel then Color.YELLOW
    else if VPN < VPN[1] and VPN < CriticalLevel then Color.RED
    else Color.GRAY
);

VPNAvg.AssignValueColor(
    if VPNAvg > CriticalLevel and VPNAvg > VPNAvg[1] then Color.GREEN
    else if VPNAvg > CriticalLevel and VPNAvg < VPNAvg[1] then Color.RED
    else if VPNAvg < CriticalLevel and VPNAvg > VPNAvg[1] then Color.YELLOW
    else if VPNAvg < CriticalLevel and VPNAvg < VPNAvg[1] then Color.RED
    else Color.GRAY
);
 
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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