• Get $40 off VIP by signing up for a free account! Sign Up

HighLow Beta Test

mcdon030

Member
I haven't posted here in awhile as threads here sometimes go sideways; however, since the script started here, i'll give it a go. I found this swing script here:https://usethinkscript.com/threads/here-are-some-of-the-indicators-i-use-every-day.4114/post-54871

I don't have alot of time to test so maybe others could and give feedback. I have added inputs to each swing, such as RSI, Volume SPikes, Fisher, etc and a simple backtest, and the individual who posted it wanted the other direction so it's been added. Basically, choose which additions and backtest. Pretty simple. Should you think another addition would improve or you find a decent variation, please post or respond.


2021-08-04-TOS-CHARTS.png

Code:
###SWING_WAVES_SHORT_ENTRY
## mcdon030 additions
# changelog
# 20210804
#1.  long entry
#2. Strengthen pivots with RSI, Volume Spikes and Fisher

input n = 30;#hint n: For pivot and standard deviation
input addAtPercentStDev =50;#hint addAtPercentStDev: Add at this percent of standard deviation below previous low
input initialLots = 4;#hint initialLots: Set to preference
input lotsToAdd = 2;#hint lotsToAdd: Number of lots to add on a pull back
input stDevMult = 2;#hint stDevMult: ltrail stop multiplier
input labels = yes;
input barcolor = yes;
Input DirectionOnly=yes; # hint yes will hold your trade until complete. no is all signals
Input StrengtenType ={
     RSI,
     RSI_Vspike,
     RSI_Fish,
     Vspike,
     Vspike_Fish,
     Fish,
     Fish_Vspike,
     Default all,
       NA  }; # hint select NA for just pivots
INput StLength = 10; # location to pivot
def h = high;
def l = low;
def c = close;
def o = open;
def v = volume;
def bn = BarNumber();
def nan = Double.NaN;
def tick = if !IsNaN(TickSize()) then TickSize() else .01;
def openingLots = Max(4, initialLots);
def stDev = CompoundValue(1, StDev(c, n), nan);
def hh = h == Highest(h, n);
def ll = l == lowest(l, n);
def LPx = if hh then bn else nan;
def HPx = if ll then bn else nan;
def LP_low = if !IsNaN(LPx) then l else LP_Low[1];
def HP_high= if !IsNaN(HPx) then h else HP_high[1];
def LP_High = if !IsNaN(LPx) then h else LP_High[1];
def HP_Low= if !IsNaN(HPx) then l else HP_Low[1];
def Lconfirmed_count = if hh then 0 else
if c crosses below LP_Low
then Lconfirmed_count[1] + 1
else Lconfirmed_count[1];
def Hconfirmed_count = if ll then 0 else
if c crosses above HP_high
then Hconfirmed_count[1] + 1
else Hconfirmed_count[1];

## 2. RSI


 script LRSI{
input nFE = 14;#hint nFE: length for Fractal Energy calculation.
def h = high;
def l = low;
def c = close;
def o = open;
def CU1;
def CU2;
def CU;
def CD1;
def CD2;
def CD;
plot RSI;
# Calculations
def lao = (o + c[1]) / 2;
def lah = Max(h, c[1]);
def lal = Min(l, c[1]);
def lac =  (o + h + l + c) / 4;
def gamma = Log(Sum((Max(lah, lac[1]) - Min(lal, lac[1])), nFE) /
        (Highest(lah, nFE) - Lowest(lal, nFE)))
            / Log(nFE);
def L0 = (1 – gamma) * lac + gamma * L0[1];
def L1 = -gamma * L0 + L0[1] + gamma * L1[1];
def L2 = -gamma * L1 + L1[1] + gamma * L2[1];
def L3 = -gamma * L2 + L2[1] + gamma * L3[1];
if L0 >= L1
then {
    CU1 = L0 - L1;
    CD1 = 0;
} else {
    CD1 = L1 - L0;
    CU1 = 0;
}
if L1 >= L2
then {
    CU2 = CU1 + L1 - L2;
    CD2 = CD1;
} else {
    CD2 = CD1 + L2 - L1;
    CU2 = CU1;
}
if L2 >= L3
then {
    CU = CU2 + L2 - L3;
    CD = CD2;
} else {
    CU = CU2;
    CD = CD2 + L3 - L2;
}
RSI = if CU + CD <> 0 then CU / (CU + CD) else 0;
}
def RSI1 = LRSI(7);
def RSI2 = LRSI(20);
def RSIsig;
if RSI1 >= .78 {
    RSIsig = 100;
} else if  RSI1 <= .22 {
    RSIsig = -100;
} else if RSI2 >= .78 {
    RSIsig = 100;
} else if  RSI2 <= .22 {
    RSIsig = -100;
} else {
    RSIsig = 0;
}
def bullpivotRSI = If(100 == Highest(RSIsig, StLength ), 1, 0);
def bearpivotRSI = If(-100 == lowest(RSIsig,StLength ), 1, 0);



# Volume Spikes
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
          GetTime() <= RegularTradingEnd(GetYYYYMMDD());

# 1.  V spikes  Anchored
def start  =RTH && !RTH[1];
def cnt = if start then 1 else cnt[1]+1;
def SumV = compoundvalue(1, if start then  v else SumV [1]+v,0);
def RTHAvVol = SumV /cnt;
def VolumeOscRTH =if  ((Average(v, 1) - RTHAvVol) / RTHAvVol)>1 then 100 else 0;


# 2. Spikes
def VolumeOsc1 = if (Average(v, 1) - Average(v, 9)) / Average(v, 9) > 1 then 100 else 0;
def VolumeOsc2 = if  (Average(v, 1) - Average(v, 11)) / Average(v, 11) > 1 then 100 else 0;
def VolumeOsc3 = if  (Average(v, 1) - Average(v, 13)) / Average(v, 13) > 1 then 100 else 0;
def VolumeOsc4 = if (Average(v, 1) - Average(v, 15)) / Average(v, 15) > 1 then 100 else 0;
def VolumeOsc5 = if  (Average(v, 1) - Average(v, 17)) / Average(v, 17) > 1 then 100 else 0;
def VolumeOsc6 = if  (Average(v, 1) - Average(v, 20)) / Average(v, 20) > 1 then 100 else 0;
##
def VolumeOsc21 = if (Average(v, 2) - Average(v, 10)) / Average(v, 10) > 1 then 100 else 0;
def VolumeOsc22 = if  (Average(v, 2) - Average(v, 12)) / Average(v, 12) > 1 then 100 else 0;
def VolumeOsc23 = if  (Average(v, 2) - Average(v, 14)) / Average(v, 14) > 1 then 100 else 0;
def VolumeOsc24 = if (Average(v, 2) - Average(v, 16)) / Average(v, 16) > 1 then 10 else 0;
def VolumeOsc25 = if  (Average(v, 2) - Average(v, 18)) / Average(v, 18) > 1 then 100 else 0;
def VolumeOsc26 = if  (Average(v, 2) - Average(v, 21)) / Average(v, 21) > 1 then 100 else 0;
def VolumeOscSum1 =  VolumeOsc1 + VolumeOsc2 + VolumeOsc3 + VolumeOsc4 + VolumeOsc5 + VolumeOsc6;
def VolumeOscSum2 =  VolumeOsc21 + VolumeOsc22 + VolumeOsc23 + VolumeOsc24 + VolumeOsc25 + VolumeOsc26;

## 3 AL Relavitive StandardD
input length = 14;
input numDev = 1;
input allowNegativeValues = no;
def rawRelVol = (v - Average(v, length)) / StDev(v, length);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
def RevolState = if RelVol > numDev then 100 else 0;


# 4. Percent R
## 4 R
input lengthr  = 20;
def Hv = Highest(v, lengthr);
def Lv = Lowest(v, lengthr);
def VR = if ((v - Lv)  / (Hv - Lv)) > 1 then 100 else 0;

Def sumaVol = VolumeOscRTH+VolumeOscSum1+VolumeOscSum2 +RevolState+VR;
def isVolSpikes;
if sumaVol >=100 {
    isVolSpikes = 100;
} else {
    isVolSpikes = 0;
}
def pivotvol = If(100 == Highest(isVolSpikes,StLength), 1, 0);

## Fisher pivots
input price = hl2;
input lengthf = 10;
def maxHigh = Highest(price, lengthf);
def minLow = Lowest(price, lengthf);
def range = maxHigh - minLow;
rec value = if IsNaN(price)
    then Double.NaN
    else if IsNaN(range)
        then value[1]
        else if range == 0
            then 0
            else 0.66 * ((price - minLow) / range - 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
rec fish = 0.5 * (log((1 + truncValue) / (1 - truncValue)) + fish[1]);

def FTOneBarBack = fish;
def FT = fish;
def lagFish= .10*FTOneBarBack+.80*FTOneBarBack[1]+.10*FTOneBarBack[2];
def fishDir;
if Crosses(ft,lagFish, CrossingDirection.ABOVE){
fishDir=100;
} else if Crosses(ft,lagFish, CrossingDirection.below){
fishDir=-100;    
}else{
Fishdir=0;    
}
def bullpivotfish = If(100 == Highest(Fishdir,8 ), 1, 0);
def bearpivotfish= If(-100 == lowest(Fishdir,8 ), 1, 0);




def Lconfirmed;
def Hconfirmed;
switch (StrengtenType){
case RSI:
     Lconfirmed = bullpivotRSI &&  Lconfirmed_count crosses above 0;
     Hconfirmed = bearpivotRSI &&  Hconfirmed_count crosses above 0;
case RSI_Vspike:
     Lconfirmed = bullpivotRSI && pivotvol &&  Lconfirmed_count crosses above 0;
     Hconfirmed = bearpivotRSI && pivotvol &&  Hconfirmed_count crosses above 0;
case RSI_Fish:
     Lconfirmed = bullpivotRSI && pivotvol &&  bullpivotfish && Lconfirmed_count crosses above 0;
     Hconfirmed = bearpivotRSI && pivotvol && bearpivotfish &&  Hconfirmed_count crosses above 0;
case Vspike:
     Lconfirmed = pivotvol &&  Lconfirmed_count crosses above 0;
     Hconfirmed = pivotvol &&  Hconfirmed_count crosses above 0;
case Vspike_Fish:
     Lconfirmed = pivotvol &&  bullpivotfish &&  Lconfirmed_count crosses above 0;
     Hconfirmed = pivotvol &&  bearpivotfish &&   Hconfirmed_count crosses above 0;
case  Fish:
     Lconfirmed = bullpivotfish &&  Lconfirmed_count crosses above 0;
     Hconfirmed =  bearpivotfish &&  Hconfirmed_count crosses above 0;
case  Fish_Vspike:
     Lconfirmed = bullpivotfish && pivotvol &&  Lconfirmed_count crosses above 0;
     Hconfirmed =  bearpivotfish &&pivotvol &&    Hconfirmed_count crosses above 0;
case  all:
     Lconfirmed =  bullpivotRSI &&  pivotvol &&  bullpivotfish &&  Lconfirmed_count crosses above 0;
     Hconfirmed =  bearpivotRSI && pivotvol &&  bearpivotfish &&  Hconfirmed_count crosses above 0;
case  NA:
     Lconfirmed =  Lconfirmed_count crosses above 0;
     Hconfirmed =  Hconfirmed_count crosses above 0;
}

def sro;
def stcx;
def ltrail;
def Lretrace;
def Lro;
def btcx;
def htrail;
def hretrace;

def BTOopen;
def STOopen;
def tradedir;
if (BTOopen[1] && !STOopen[1]) {
    tradedir = 1;
} else if (!BTOopen[1] && !STOopen[1]) {
    tradedir = 0;
} else if ( !BTOopen[1] && STOopen[1]) {
    tradedir = -1;
} else if ( !BTOopen[1] && !STOopen[1]) {
    tradedir = 0;
} else {
    tradedir = tradedir[1];
}

 BTOOpen= CompoundValue(1,
if bn==1 then 0 else
if hconfirmed && tradedir==0 then 1 else
if hconfirmed && tradedir==1 then 1 else
if c<htrail && BTOOpen[1]==1  then 0 else
BTOOpen[1],0);

STOOpen= CompoundValue(1,
if bn==1 then 0 else
if lconfirmed &&  tradedir==0 then 1 else
if lconfirmed &&  tradedir==-1 then 1 else
if c>ltrail && STOOpen[1]==1  then 0 else
STOOpen[1],0);




if  Lconfirmed &&  if(DirectionOnly && tradedir==0,1,!DirectionOnly  ){
sro = Round((c - (LP_High - c) / (openingLots - 2)) / tick, 0) * tick;
stcx = LP_High;
ltrail = LP_High;
Lretrace = LP_High;
}else{
sro = CompoundValue(1, sro[1], nan);
stcx = stcx[1];
ltrail = Round(Min(ltrail[1], h[1] + stDev[1] * stDevMult) / tick, 0) * tick;
Lretrace = Round(Min(Lretrace[1], h[1] + StDev[1] * addAtPercentStDev / 100) / tick, 0) * tick;
}

if hconfirmed && if(DirectionOnly && tradedir==0,1,!DirectionOnly  ){
Lro = Round((c - (HP_low- c) / (openingLots - 2)) / tick, 0) * tick;
btcx = Hp_Low;
htrail = Hp_Low;
hretrace = Hp_Low;
}else{
Lro = CompoundValue(1, Lro[1], nan);
btcx = btcx[1];
htrail = Round(Max(htrail[1], l[1] -stDev[1] * stDevMult) / tick, 0) * tick;
hretrace = Round(Max(hretrace[1], l[1] -stDev[1] * addAtPercentStDev / 100) / tick, 0) * tick;
}


def sro_reached = if Lconfirmed then 0 else
if l < sro then 1 else sro_reached[1];
def ladded = if Lconfirmed then 0 else
if h crosses above Lretrace then 1 else ladded[1];
def Ltrail_hit = if Lconfirmed then 0 else
if c > ltrail then 1 else Ltrail_hit[1];
def lstop_hit = if Lconfirmed then 0 else
if h > stcx then 1 else lstop_hit[1];

def lro_Reached = if hconfirmed then 0 else
if h > lro then 1 else lro_Reached[1];
def hadded = if hconfirmed then 0 else
if l crosses above hretrace then 1 else hadded[1];
def htrail_hit = if hconfirmed then 0 else
if c < htrail then 1 else htrail_hit[1];
def hstop_hit = if hconfirmed then 0 else
if l < btcx then 1 else hstop_hit[1];




plot
Pivotconfirmed_L = Lconfirmed &&  tradedir==0;
Pivotconfirmed_L.SetDefaultColor(Color.Light_Red);
Pivotconfirmed_L.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot
Pivotconfirmed_h = hconfirmed&&  tradedir==0;
Pivotconfirmed_h.SetDefaultColor(Color.Light_green);
Pivotconfirmed_h.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);

plot
BuyToOpen = if Hconfirmed then c else nan;
BuyToOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BuyToOpen.SetDefaultColor(Color.Light_Green);
plot
SellToOpenx = if Lconfirmed then c else nan;
SellToOpenx.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SellToOpenx.SetDefaultColor(Color.Light_Green);

plot
LTrailingstop = if ! Ltrail_hit or Ltrail_hit crosses above 0 then ltrail else nan;
LTrailingstop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LTrailingstop.SetDefaultColor(Color.Pink);
plot
hTrailingstop = if ! htrail_hit or htrail_hit crosses above 0 then htrail else nan;
hTrailingstop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hTrailingstop.SetDefaultColor(Color.red);
plot
sAdd = if !ladded or ladded crosses above 0 then Lretrace else nan;
sAdd.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
sAdd.SetDefaultColor(Color.Dark_Green);

plot
lAdd = if !hadded or hadded crosses above 0 then hretrace else nan;
lAdd.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lAdd.SetDefaultColor(Color.Dark_Green);

plot
RiskOutl = if !sro_reached or sro_reached crosses above 0 then sro else nan;
RiskOutl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RiskOutl.SetDefaultColor(color.cyan);
plot
RiskOuth= if !lro_reached or lro_reached crosses above 0 then lro else nan;
RiskOuth.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RiskOuth.SetDefaultColor(color.cyan);

def colorstate =
if  tradedir==-1 then -100 else
if   tradedir==1 then 100 else  0;

AssignPriceColor(
if barcolor  then
if   tradedir==1 then Color.green else
if tradedir==-1  then Color.red else
 Color.GRAY else Color.CURRENT);


def BTO = If( BTOOpen && !BTOOpen[1], c, nan);
def STC = If(!BTOOpen &&  BTOOpen[1], c, nan);
def STO = If(STOOpen && !STOOpen[1], c, nan);
def BTC = If(!STOOpen && STOOpen[1], c,  nan);
def Bullcnt = CompoundValue(1, if bn == 1 then 0 else  if !IsNaN(STC) then Bullcnt[1] + 1  else Bullcnt[1], 0);
def Bearcnt = CompoundValue(1, if bn == 1 then 0 else  if !IsNaN(BTC) then Bearcnt[1] + 1  else Bearcnt[1], 0);
def BTOF = CompoundValue(1, if !IsNaN(BTO) then c else BTOF[1], 1);
def STCF = CompoundValue(1, if !IsNaN(STC) then c else STCF[1], 1);
def LongReturn = CompoundValue(1, if !IsNaN(STC) then STCF - BTOF else LongReturn[1], 1);
def LongReturnCnt = CompoundValue(1, if !IsNaN(STC) &&LongReturn>=0  then LongReturnCnt[1]+1 else LongReturnCnt[1], 0);
def LongReturnLossCnt = CompoundValue(1, if !IsNaN(STC) &&LongReturn<0  then LongReturnLossCnt[1]+1 else LongReturnLossCnt[1], 0);
def STOF = CompoundValue(1, if !IsNaN(STO) then c else STOF[1], 1);
def BTCF = CompoundValue(1, if !IsNaN(BTC) then c else BTCF[1], 1);
def ShortReturn = CompoundValue(1, if !IsNaN(BTC) then STOF - BTCF else ShortReturn[1], 1);
def ShortReturnCnt = CompoundValue(1, if !IsNaN(BTC)  && ShortReturn>=0  then ShortReturnCnt[1]+1 else ShortReturnCnt[1], 0);
def ShortReturnLossCnt = CompoundValue(1, if !IsNaN(BTC)  && ShortReturn<0  then ShortReturnLossCnt[1]+1 else ShortReturnLossCnt[1], 0);

def WLShort =  ShortReturnCnt/ (ShortReturnCnt+ShortReturnLossCnt);
def WLLong = LongReturnCnt/(LongReturnCnt+LongReturnLossCnt);


addlabel(1, "Mcdon030 -> Beta_Swing_Test:", color.orange);

addlabel(labels,"Pivot length|"+ n,color.white);
addlabel(labels,"stdev |"+ stDevMult,color.white);

addlabel(labels,StrengtenType,color.orange);
addlabel(labels, "DirectionOnly|"+( if  DirectionOnly then "yes" else "no"),color.orange);


AddLabel(labels,"Bull",  Color.light_green);
AddLabel(labels,"Trades"+  (LongReturnCnt+LongReturnLossCnt),  Color.WHITE);
AddLabel(labels,"WL ="+  AsPercent(WLLong),  Color.WHITE);
AddLabel(labels,"Bear",  Color.light_red);
AddLabel(labels, "Trades"+  (LongReturnCnt+LongReturnLossCnt),  Color.WHITE);
AddLabel(labels, "WL =" + AsPercent(WLshort),  Color.WHITE);
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
162 Online
Create Post

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