Identifying Higher Lows/Lower Highs
Posted: Wed Jan 12, 2022 9:12 am
Hey Pine Scripters,
I'm really excited with this journey so far!
I appreciate your consideration in reading this.
What I'm Trying To Accomplish:
I have a partially back-tested strategy (250+ trades the old fashioned way lol) that I eventually want to code for ease of testing and use, but for now I'm just wondering how I would go about identifying/targeting certain conditions in price and on this indicator!
*Full code for indicator below
*Pic of valid setups for clarity on what I'm describing:
My Entry Conditions
1. Only LONG entries above 200EMA. Only SHORTS below 200EMA. (No help needed with this)
*For simplicity's sake, let's define the last two conditions in context of a LONG.
2. My Long entry is defined as a Green Triangle of a 'Momentum Wave" (faster blue/pink oscillator - called "WTO ONE/wt_1" in the script) that is SMALLER than the previous, larger "Momentum Wave". That is to say the oscillator did not go as low into negative integers as it did the time before - AND the oscillator has to cross the "0 line" to the opposite side between the two waves occurring. A Smaller Wave with a Buy Triangle after having NOT crossed the 0 line between it's accompanied Larger Wave does not constitute a valid set-up.
*Green Triangles are triggered by the (invisible) "cross" or change of direction in WTO ONE, in case it's helpful.
3. While the Momentum Wave is making that "Higher-Low" (Smaller after Larger), price-action ALSO has to make a higher low - or simply be higher than it was at the time of the Large Wave. If price is lower at the time of the Small-Wave "Buy" triangle than it was at the Large-Wave "Buy" triangle, the setup is invalid.
In summary, "Higher Lows" on both price-action and momentum waves (with retracement across 0 line between momentum waves) with "Buy" on small momentum wave, + above 200EMA = LONG. Inverse for a short.
I need guidance with:
How do you go about identifying price being higher on what could be a varying period? It's clearly not as cut and dry as a look-back period, so I'm somewhat at a loss.
How do you go about identifying the fact that the current oscillator wave is higher at the time of posting a triangle than the last one was, and that it crossed into positive territory at some point since the last one?
My fear is that this is outside of the limitations of Pine Script - that said - I know like 5% of Pine, and certainly less about what's achievable with it. So I humbly ask you internet friends for guidance.
I sincerely thank you!
Code: "WTO ONE" is the oscillator in question. WT2 can be ignored entirely.
I'm really excited with this journey so far!
I appreciate your consideration in reading this.
What I'm Trying To Accomplish:
I have a partially back-tested strategy (250+ trades the old fashioned way lol) that I eventually want to code for ease of testing and use, but for now I'm just wondering how I would go about identifying/targeting certain conditions in price and on this indicator!
*Full code for indicator below
*Pic of valid setups for clarity on what I'm describing:
My Entry Conditions
1. Only LONG entries above 200EMA. Only SHORTS below 200EMA. (No help needed with this)
*For simplicity's sake, let's define the last two conditions in context of a LONG.
2. My Long entry is defined as a Green Triangle of a 'Momentum Wave" (faster blue/pink oscillator - called "WTO ONE/wt_1" in the script) that is SMALLER than the previous, larger "Momentum Wave". That is to say the oscillator did not go as low into negative integers as it did the time before - AND the oscillator has to cross the "0 line" to the opposite side between the two waves occurring. A Smaller Wave with a Buy Triangle after having NOT crossed the 0 line between it's accompanied Larger Wave does not constitute a valid set-up.
*Green Triangles are triggered by the (invisible) "cross" or change of direction in WTO ONE, in case it's helpful.
3. While the Momentum Wave is making that "Higher-Low" (Smaller after Larger), price-action ALSO has to make a higher low - or simply be higher than it was at the time of the Large Wave. If price is lower at the time of the Small-Wave "Buy" triangle than it was at the Large-Wave "Buy" triangle, the setup is invalid.
In summary, "Higher Lows" on both price-action and momentum waves (with retracement across 0 line between momentum waves) with "Buy" on small momentum wave, + above 200EMA = LONG. Inverse for a short.
I need guidance with:
How do you go about identifying price being higher on what could be a varying period? It's clearly not as cut and dry as a look-back period, so I'm somewhat at a loss.
How do you go about identifying the fact that the current oscillator wave is higher at the time of posting a triangle than the last one was, and that it crossed into positive territory at some point since the last one?
My fear is that this is outside of the limitations of Pine Script - that said - I know like 5% of Pine, and certainly less about what's achievable with it. So I humbly ask you internet friends for guidance.
I sincerely thank you!
Code: "WTO ONE" is the oscillator in question. WT2 can be ignored entirely.
Code: Select all
//@version=5
indicator(title="+ WAVE", timeframe="")
src = input(defval=hlc3, title="Source")
//WTO PLOT ONE
channel_len = input(defval=10, title="Channel Length", group="Primary Wavetrend Inputs")
average_len = input(defval=12, title="Average Length", group="Primary Wavetrend Inputs")
wt_1_ma_len = input(defval=3, title="Moving Average Length", group="Primary Wavetrend Inputs")
esa = ta.ema(src, channel_len)
d = ta.ema(math.abs(src - esa), channel_len)
ci = (src - esa) / (0.015 * d)
tci = ta.ema(ci, average_len)
wt_1 = tci
wt_1_ma = ta.sma(wt_1, wt_1_ma_len)
//COLOR INPUTS
wt_1_up = input(color.new(#00e1ff, 0), title="High", inline="wt 1 color", group="Primary Wavetrend Inputs")
wt_1_down = input(color.new(#ff00ff, 0), title="Low", inline="wt 1 color", group="Primary Wavetrend Inputs")
wt_1_color = color.from_gradient(wt_1, -80, 80, wt_1_down, wt_1_up)
plot(wt_1, color=wt_1_color, title="Primary Wavetrend", linewidth=2)
//WTO PLOT TWO
channel_len_2 = input(defval=32, title="Channel Length", group="Secondary Wavetrend Inputs")
average_len_2 = input(defval=50, title="Average Length", group="Secondary Wavetrend Inputs")
esa2 = ta.ema(src, channel_len_2)
d2 = ta.ema(math.abs(src - esa2), channel_len_2)
ci2 = (src - esa2) / (0.015 * d2)
tci2 = ta.ema(ci2, average_len_2)
wt_2 = tci2
//COLOR INPUTS
wt_2_up = input(color.new(#09ff00, 40), title="High", inline="wt 2 color", group="Secondary Wavetrend Inputs")
wt_2_down = input(color.new(#ff1919, 40), title="Low", inline="wt 2 color", group="Secondary Wavetrend Inputs")
wt_2_color = color.from_gradient(wt_2, -60, 60, wt_2_down, wt_2_up)
plot(wt_2, color=wt_2_color, title="Secondary Wavetrend")
//MOVING AVERAGE CROSS SIGNALS ON PRIMARY WAVETREND
plotshape(ta.crossover(wt_1, wt_1_ma), title="Maybe Buy", style=shape.triangleup, color=color.green, size=size.tiny, location=location.bottom)
plotshape(ta.crossunder(wt_1, wt_1_ma), title="Maybe Sell", style=shape.triangledown, color=color.red, size=size.tiny, location=location.top)
////HORIZONTAL LINES & OB/OS REGIONS
wto_2_overbought = hline(80, color=#ff1919, linestyle=hline.style_dotted, title="80")
wto_1_overbought = hline(60, color=#ff1919, linestyle=hline.style_dotted, title="60")
uline40 = hline(25, color=#787b86, linestyle=hline.style_dotted, title="25")
uline20 = hline(15, color=#787b86, linestyle=hline.style_dotted, title="15")
median = hline(0, color=color.fuchsia, linestyle=hline.style_solid, title="Median", linewidth=3)
dline20 = hline(-15, color=#787b86, linestyle=hline.style_dotted, title="-15")
dline40 = hline(-25, color=#787b86, linestyle=hline.style_dotted, title="-25")
wto_1_oversold = hline(-60, color=#56ff38, linestyle=hline.style_dotted, title="-60")
wto_2_oversold = hline(-80, color=#4bff2b, linestyle=hline.style_dotted, title="-80")
fill_col_upper = input(color.new(#ff5252, 85), title="Overbought Fill Color", group="Oscillator Extremes")
fill_col_lower = input(color.new(#47a637, 85), title="Oversold Fill Color", group="Oscillator Extremes")
fill(wto_2_overbought, wto_1_overbought, color=fill_col_upper, title="Overbought Region")
fill(wto_2_oversold, wto_1_oversold, color=fill_col_lower, title="Oversold Region")