Thinkscript to show label & arrow for largest gain/range since uptrend

beh0211

New member
Hey guys,

I am working on a new indicator to display lable & arrow for largest gain and largest range candle since 50MA crosses 150MA.

I manage to display the label correctly but somehow my painting strategy ain't showing. Appreciate if anyone can give some advise.

Code:
def downtrend = SimpleMovingAvg(length = 50) < SimpleMovingAvg(length = 150);

def countuptrend = if downtrend[1] then 1 else countuptrend[1] + 1;

#AddLabel(1, "Bar since 50x150: "+ countuptrend, (if countuptrend >50 then color.DARK_GREEN else color.red));

plot largestgainD = fold i = 0 to countuptrend with p1 do if GetValue(close - close[1],i) > p1 then GetValue(close - close[1],i) else p1;

plot largestrangeD = fold j = 0 to countuptrend  with p2 do if GetValue(high-low,j) > p2 then GetValue(high-low,j) else p2;

#not working here
largestgainD.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

def isLargestgainD = close-close[1] >= largestgainD;
def isLargestrangeD = high-low >= largestrangeD;

AddLabel(1, "Largest Daily Gain: $ "+ largestgainD, (if isLargestgainD and countuptrend > 1 then color.red else color.GRAY));

AddLabel(1, "Largest Daily Range: $ "+ largestrangeD, (if isLargestrangeD and countuptrend > 1 then color.red else color.GRAY));
 

beh0211

New member
I changed to boolean arrow but still nothing come up. Is it due to the fold function ?

00M1Ec5.png
 

SleepyZ

Well-known member
VIP
Lifetime
Hey guys,

I am working on a new indicator to display lable & arrow for largest gain and largest range candle since 50MA crosses 150MA.

I manage to display the label correctly but somehow my painting strategy ain't showing. Appreciate if anyone can give some advise.

Code:
def downtrend = SimpleMovingAvg(length = 50) < SimpleMovingAvg(length = 150);

def countuptrend = if downtrend[1] then 1 else countuptrend[1] + 1;

#AddLabel(1, "Bar since 50x150: "+ countuptrend, (if countuptrend >50 then color.DARK_GREEN else color.red));

plot largestgainD = fold i = 0 to countuptrend with p1 do if GetValue(close - close[1],i) > p1 then GetValue(close - close[1],i) else p1;

plot largestrangeD = fold j = 0 to countuptrend  with p2 do if GetValue(high-low,j) > p2 then GetValue(high-low,j) else p2;

#not working here
largestgainD.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

def isLargestgainD = close-close[1] >= largestgainD;
def isLargestrangeD = high-low >= largestrangeD;

AddLabel(1, "Largest Daily Gain: $ "+ largestgainD, (if isLargestgainD and countuptrend > 1 then color.red else color.GRAY));

AddLabel(1, "Largest Daily Range: $ "+ largestrangeD, (if isLargestrangeD and countuptrend > 1 then color.red else color.GRAY));

To get the arrow to plot, the plot lg = the point when close-close[1] equals largestgainD result.

Capture.jpg
Ruby:
def downtrend = SimpleMovingAvg(length = 50) < SimpleMovingAvg(length = 150);

def countuptrend = if downtrend[1] then 1 else countuptrend[1] + 1;

#AddLabel(1, "Bar since 50x150: "+ countuptrend, (if countuptrend >50 then color.DARK_GREEN else color.red));

def largestgainD = fold i = 0 to HighestAll(countuptrend) with p1 do if GetValue(close - close[1], i) > p1 then GetValue(close - close[1], i) else p1;

def largestrangeD = fold j = 0 to HighestAll(countuptrend)  with p2 do if GetValue(high - low, j) > p2 then GetValue(high - low, j) else p2;

##############
plot lg = (close - close[1]) == largestgainD;
lg.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
lg.setlineWeight(5);
##############

def isLargestgainD = close - close[1] >= largestgainD;
def isLargestrangeD = high - low >= largestrangeD;

AddLabel(1, "Largest Daily Gain: $ " + largestgainD, (if isLargestgainD and countuptrend > 1 then Color.RED else Color.GRAY));

AddLabel(1, "Largest Daily Range: $ " + largestrangeD, (if isLargestrangeD and countuptrend > 1 then Color.RED else Color.GRAY));
 

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