How can I store the 2nd pivot high or low to allow for comparison?

R

RConner7

Member
I'm using the below code to create previous high and low levels. seems to work well.

How can i get this to allow me to store the 2nd previous swing high or 2nd previous swing low?

My goal is to compare the the 2nd previous high to the current previous high to determine up or down trend.

I have tried using the simple Support[1] > Support[2] but it doesn't seem to work. When i add these to a label, it only gives me to current high or low no matter what value i put into the [ ].

Please help.

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 by a moderator:
inthefutures

inthefutures

Active member
not sure this works, but what about repeating the calculations but have them set back the lookback period eg.
def _highInPeriod1 = Highest(high[lookback], LookbackPeriod);
 
R

RConner7

Member
@inthefutures thanks for the response. I'm not sure if that will work for this. I'll give it a try though.
 
inthefutures

inthefutures

Active member
then try a bigger lookback for that line. I have no idea if this works just thinking out loud
 
R

RConner7

Member
good thought. I gave it a shot by duplicating the code and using 2 separate lookback periods but it didn't play nice. still going to keep hunting for something.
 
R

RConner7

Member
I'm struggling with this. I feel like this should be something relatively easy to figure out but i can't seem to crack the logic on this. Simply doubling the lookback period doesn't help.

For example - I just want to record the previous 2 highs of 82.94 and 82.90 as well as the 2 previous lows of 82.25 and 82.33. Once i can do that, i can use them for comparison.
 
R

RConner7

Member
@RobertPayne - hi Robert. I found some scripts you’ve written that are similar to what I’m trying to do. Any chance you could assist me with this?
 

Similar threads

Top