Average Price Move size using highs and lows

imonlysleeping

New member
Hi, i had the idea to create a lower study that shows the average price move between swings over time. My first thought was to use a swing high/low indicator, which I already have, and simply measure and average the price move between each swing high and low.

Being able to average the price moves and plot that as a lower study is beyond my abilities, or perhaps beyond the abilities of thinkscript? I think maybe via the use of CompoundValue and/or fold function, this can be accomplished, I just can't figure it out.

Would be extra cool to have a user input to be able to only extract and average the price moves during a certain time of the day each day. Mainly looking to play with this indicator on a lower timeframe chart.

Would be double extra cool to give two readings - the average size of the moves to the downside and the average size of the moves to the upside.

Can anyone let me know if this is possible to do using thinkscript?

This is the swing high/low indicator i found here in the forums a few months ago, which i have been attempting to alter and use for the creation of the new indicator:

Code:
#SWING HIGH LOW
input LookbackPeriod = 3;
input HideCurrentTF = no;

#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod);
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;

rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod];
def _markedHigh1 = high == marketHigh1;

rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then high else _lastMarkedHigh1[1], high);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Support1 = _lastMarkedLow1 ;

#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance1.SetDefaultColor(Color.GREEN);
Resistance1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.DASHES);
Support1.SetDefaultColor(Color.RED);
Support1.SetHiding(HideCurrentTF);
 
Last edited:
Hi, i had the idea to create a lower study that shows the average price move between swings over time. My first thought was to use a swing high/low indicator, which I already have, and simply measure and average the move size between each swing high and low.

Being able to average the price moves and plot that as a lower study is beyond my abilities, or perhaps beyond the abilities of thinkscript? I think maybe via the use of CompoundValue and/or fold function, this can be accomplished, I just can't figure it out.

Would be extra cool to have a user input to be able to only extract and average the price moves during a certain time of the day each day. Mainly looking to play with this indicator on a lower timeframe chart.

Would be double extra cool to give two readings - the average size of the moves to the downside and the average size of the moves to the upside.

This is the swing high/low indicator i found here in the forums a few months ago, which i have been attempting to alter and use for the directional price moves:

Code:
#SWING HIGH LOW
input LookbackPeriod = 3;
input HideCurrentTF = no;

#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod);
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;

rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod];
def _markedHigh1 = high == marketHigh1;

rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then high else _lastMarkedHigh1[1], high);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Support1 = _lastMarkedLow1 ;

#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance1.SetDefaultColor(Color.GREEN);
Resistance1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.DASHES);
Support1.SetDefaultColor(Color.RED);
Support1.SetHiding(HideCurrentTF);
can you please help to add price chartbubble at resistance1 and support1? Thanks,
 
can you please help to add price chartbubble at resistance1 and support1? Thanks,

Add this to the bottom of the code

Code:
input showbubbles = yes;
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), Support1[b1], "S1");
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), Resistance1[b1], "R1");
 
Add this to the bottom of the code
Thanks SleepyZ, this is not what I wanted. I wanted to have price at every support and resistance lines. I wrote the following codes but it placed price across the resistance and support lines. Can you please correct it?

addchartbubble(yes, resistance1, "$" +round(resistance1,2),color.magenta, yes);
addchartbubble(yes, support1, "$" +round(support1,2),color.cyan, no);
 
Thanks SleepyZ, this is not what I wanted. I wanted to have price at every support and resistance lines. I wrote the following codes but it placed price across the resistance and support lines. Can you please correct it?

addchartbubble(yes, resistance1, "$" +round(resistance1,2),color.magenta, yes);
addchartbubble(yes, support1, "$" +round(support1,2),color.cyan, no);

Try replacing above with:

Code:
addchartBubble(resistance1!=resistance1[1], resistance1,  asdollars(Resistance1), color.magenta);
addchartBubble(support1!=support1[1], support1, asdollars(Support1), color.cyan, no);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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