YungTraderFromMontana
Well-known member
I used the swing high low indicator and then added a cross confirmation between multiple lookbacks for a higher accuracy.
There are three inputs that are lookbacks and should be somewhat manually tweaked to fit a certain stock (similar to ATR mult. with supertrend). What usually works best from early testing is choosing the first lookback as a number 8- 15, second 5-8, and third 3-5.
Here's a chart of /gc with 10,5,4 settings. https://tos.mx/AEctufx
It works on anything stocks, forex, futures etc
There are three inputs that are lookbacks and should be somewhat manually tweaked to fit a certain stock (similar to ATR mult. with supertrend). What usually works best from early testing is choosing the first lookback as a number 8- 15, second 5-8, and third 3-5.
Code:
def price = (open + close)/2;
def length = 1;
def displace = 0;
def SMA = Average(price[-displace], length);
#1
input LookbackPeriod1 = 8;
def FirstBar = BarNumber();
def Highest = fold i = 1
to LookbackPeriod1 + 1
with p = 1
while p
do high > GetValue(high, -i);
def A = if (FirstBar > LookbackPeriod1
and high == Highest(high, LookbackPeriod1)
and Highest)
then high
else Double.NaN;
def Lowest = fold j = 1
to LookbackPeriod1 + 1
with q = 1
while q
do low < GetValue(low, -j);
def B = if (FirstBar > LookbackPeriod1
and low == Lowest(low, LookbackPeriod1)
and Lowest)
then low
else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod1);
def _lowInPeriod1 = Lowest(low, LookbackPeriod1);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod1] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod1];
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[-LookbackPeriod1] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod1];
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;
def lower_close1 = (sma crosses below Support1[1]);
def higher_close1 = (sma crosses above Resistance1[1]);
#---------------------------------------
def ph1 = Round(A, 2);
def pl1 = Round(B, 2);
#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance1.SetDefaultColor(Color.GREEN);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.DASHES);
Support1.SetDefaultColor(Color.RED);
def doublebreakup1 = higher_close1;
def doublebreakdown1 = lower_close1;
#2
input LookbackPeriod0 = 4;
def FirstBar0 = BarNumber();
def Highest0 = fold i0 = 1
to LookbackPeriod0 + 1
with p0 = 1
while p0
do high > GetValue(high, -i0);
def A0 = if (FirstBar0 > LookbackPeriod0
and high == Highest(high, LookbackPeriod0)
and Highest0)
then high
else Double.NaN;
def Lowest0 = fold j0 = 1
to LookbackPeriod0 + 1
with q0 = 1
while q0
do low < GetValue(low, -j0);
def B0 = if (FirstBar0 > LookbackPeriod0
and low == Lowest(low, LookbackPeriod0)
and Lowest0)
then low
else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod10 = Highest(high, LookbackPeriod0);
def _lowInPeriod10 = Lowest(low, LookbackPeriod0);
#--------------------------------------------------------------
def marketLow10 = if _lowInPeriod10 < _lowInPeriod10[-LookbackPeriod0] then _lowInPeriod1 else _lowInPeriod10[-LookbackPeriod0];
def _markedLow10 = low == marketLow10;
rec _lastMarkedLow10 = CompoundValue(1, if IsNaN(_markedLow10) then _lastMarkedLow10[1] else if _markedLow10 then low else _lastMarkedLow10[1], low);
#--------------------------------------------------------------
def marketHigh10 = if _highInPeriod10 > _highInPeriod10[-LookbackPeriod0] then _highInPeriod10 else _highInPeriod10[-LookbackPeriod0];
def _markedHigh10 = high == marketHigh10;
rec _lastMarkedHigh10 = CompoundValue(1, if IsNaN(_markedHigh10) then _lastMarkedHigh10[1] else if _markedHigh10 then high else _lastMarkedHigh10[1], high);
#--------------------------------------------------------------
def Resistance10 = _lastMarkedHigh10;
def Support10 = _lastMarkedLow10;
def lower_close0 = (sma crosses below Support10[1]);
def higher_close0 = (sma crosses above Resistance10[1]);
#---------------------------------------
def ph0 = Round(A, 2);
def pl0 = Round(B, 2);
def doublebreakup2 = higher_close0;
def doublebreakdown2 = lower_close0;
#3
input LookbackPeriod00 = 2;
def FirstBar00 = BarNumber();
def Highest00 = fold i00 = 1
to LookbackPeriod00 + 1
with p00 = 1
while p00
do high > GetValue(high, -i00);
def A00 = if (FirstBar00 > LookbackPeriod00
and high == Highest(high, LookbackPeriod00)
and Highest00)
then high
else Double.NaN;
def Lowest00 = fold j00 = 1
to LookbackPeriod00 + 1
with q00 = 1
while q00
do low < GetValue(low, -j00);
def B00 = if (FirstBar00 > LookbackPeriod00
and low == Lowest(low, LookbackPeriod00)
and Lowest00)
then low
else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod100 = Highest(high, LookbackPeriod00);
def _lowInPeriod100 = Lowest(low, LookbackPeriod00);
#--------------------------------------------------------------
def marketLow100 = if _lowInPeriod100 < _lowInPeriod100[-LookbackPeriod00] then _lowInPeriod100 else _lowInPeriod100[-LookbackPeriod00];
def _markedLow100 = low == marketLow100;
rec _lastMarkedLow100 = CompoundValue(1, if IsNaN(_markedLow100) then _lastMarkedLow100[1] else if _markedLow100 then low else _lastMarkedLow100[1], low);
#--------------------------------------------------------------
def marketHigh100 = if _highInPeriod100 > _highInPeriod100[-LookbackPeriod00] then _highInPeriod100 else _highInPeriod1[-LookbackPeriod00];
def _markedHigh100 = high == marketHigh100;
rec _lastMarkedHigh100 = CompoundValue(1, if IsNaN(_markedHigh100) then _lastMarkedHigh100[1] else if _markedHigh100 then high else _lastMarkedHigh100[1], high);
#--------------------------------------------------------------
def Resistance100 = _lastMarkedHigh100;
def Support100 = _lastMarkedLow100;
def lower_close00 = (sma crosses below Support100[1]);
def higher_close00 = (sma crosses above Resistance100[1]);
#---------------------------------------
def ph000 = Round(A, 2);
def pl000 = Round(B, 2);
def doublebreakup3 = higher_close00;
def doublebreakdown3 = lower_close00;
def twoathree = doublebreakup1 or doublebreakup2;
def twoofthree2 = doublebreakup1 or doublebreakup3;
def twoathree3 = doublebreakdown1 or doublebreakdown2;
def twoofthree3 = doublebreakdown1 or doublebreakdown3;
plot allbreakup = doublebreakup1 and doublebreakup2 and doublebreakup3;
plot allbreakdown = doublebreakdown1 and doublebreakdown2 and doublebreakdown3;
plot twoofthreeup = twoofthree2 and twoofthree2;
plot twoofthreedown = twoathree3 and twoofthree3;
plot slippedthroughthecracksup = twoofthreeup and (price[1] < resistance1 and price > resistance1);
plot slippedthroughthecracksdown = twoofthreedown and (price[1] > support1) and (price < support1);
input BuyEntry = 3;
input SellEntry = 3;
def QB = Highest(high, BuyEntry);
def QS = Lowest(low, SellEntry);
plot trueqb = qb[1];
plot trueqs = qs[1];
Here's a chart of /gc with 10,5,4 settings. https://tos.mx/AEctufx
It works on anything stocks, forex, futures etc
Last edited by a moderator: