Working on Gaussian_FE_Box_Breakout. Need some help!

mcdon030

Member
2020-01-16-TOS-CHARTS.png


Here is a pretty good script i've been working on - it works as is. I frankly think anyone could trade it. Though, I would like a professional to assist with a few things. At some point I'll finish it without assistance, however, since my scripting skills consistent of trying everything until it works, it may be sometime until it's complete.
I would like to:

1. Shorten plot logic: I created a custom switch (without using a switch function), but it surely could be shortened to resemble something like SAR or ATR trailing stop logic.

2. Breakout signals: While they work quite well, it some instances it fires late. I don't want to change the current breakout signals as they keep the box intact with false breakout signals, so something added which does the same is important.

3. Box Repainting while trade is active. This could be solved with 1 above. This is the main priority. if anyone could do this, I can figure the rest out.

thanks, mcdon

Code:
### Name: Mcdon030_Compression Box Breakout _Version 1
## date: V1 1/9/2020
## signals from: Mobius Expansion Contraction Indicator (ECI):https://tos.mx/p8PbL4
## Notes:
## 1. Attempt at  painting a box around fractal energy signals
## 2. Basic trade logic has  inputs for full box range, mid range or input range multipler after breakout. Mobius suggested midrange i believe
## 3. Multiple attempts for better breakout signals. see below line 70
## inputs:
## 1. length2 always egreater than length1 - box finds previous highest and lowest from signal back as far as length2
## 2.  stdev input yes to add stdev levels to breakout
input length1 = 11;
input length2 =15;
input Compresslength = 2;  ##
input mult = .04;
input Compress  = .7;
input projectmult =.618;
input breakSD =yes;
input ShowLabels=yes;
input Showtrade=yes;
########################################## signal assist
def bn = BarNumber();
def bodyHeight = BodyHeight();
def IsUp = close > open;
def IsDown = close < open;
def LowVol = volume < Average(volume, 50);
def buybody = bodyHeight > Average(bodyHeight, length1);
script p {
    input data   = close;
    input Length = 20;
    def w = (2 * Double.Pi / (Length / 2));
    def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / Length) - 1);
    def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    def a = Power(alpha, 4) * data + 4 * (1 - alpha) * a[1] - 6 * Power(1 - alpha, 2) * a[2] + 4 * Power(1 - alpha, 3) * a[3] - Power(1 - alpha, 4) * a[4];
    plot line = a;
}
def o = p(open, Length = Length1);
def l = p(low, Length = Length1);
def h = p(high, Length = Length1);
def c = p(close, Length = Length1);
def bar = BarNumber();
def HMax = Highest(Max(h, c[1]), Length1);
def LMax = Lowest(Min(l, c[1]), Length1);
def TR = Max(h, c[1]) - Min(l, c[1]);
def R = Highest(h, Length1) - Lowest(l, Length1);
def F = Log(Sum(TR, Length1) / R) / Log(Length1);
def FE =(Log(Sum(Max(high, close[1]) - Min(low, close[1]), Length1) /  (Highest(high, Length1) - Lowest(low, Length1))) /  Log(Length1));
def consolidation =  if F crosses above Compress then close else if f> Compress then close else double.nan;
script ff {
    input v1 = 0.0 ;
    input v2 = 0.0;
    def bn = BarNumber();
    def lbar = HighestAll(if IsNaN(close) then 0 else bn);
    def va1 =  fold id = 1 to lbar with t = 0 while t == 0 do if GetValue(v1, -id) then id else 0;
    plot for =  GetValue(v2, -va1);
}
########################################## box values
def consave =  !isnan(consolidation) and sum(!isnan(consolidation),Compresslength )>=Compresslength ;
def con_ = if IsNaN(consave) then 0 else consave;
def start =  bn == ff(con_, bn)  - length2;
def start_ =  if IsNaN(start) then 0 else start;
def startcnt = if start_  then 1 else startcnt[1] + 1;
def startbn = if start then bn else startbn [1];
def endbn = if  con_  then bn else  endbn [1];
def gethigh = if con_  then Highest(high, length2) else gethigh[1];
def getlow = if con_  then Lowest(low, length2) else getlow[1];
def getstdev = if con_  then StDev(close, length2) else getstdev[1];
def getSVSD = (Highest(getstdev, length2) + Lowest(getstdev, length2)) / 2;
def highend = CompoundValue(1,  if start_ then  ff(con_,gethigh)  else highend[1], high);
def lowend = CompoundValue(1, if start_ then  ff(con_, getlow) else lowend[1], low);
def stdevend = CompoundValue(1, if start_ then ff(con_, getSVSD) else stdevend [1], 1);
########################################## breakout from highest high and lowest low or add standard deviation
def highend_ = if breakSD==no then highend else highend+stdevend ;
def lowend_ = if breakSD==no then lowend else lowend-stdevend ;
def stopH1 = buybody  and low> highend_ ;
def stopL1 = buybody  and high < lowend_;
def stopH2 = low> highend_ and high[1]<=highend_;
def stopL2 =  high <lowend_ and low[1]>=lowend_; ;
########################################## limit break signals
def stopHL2lmt = if stopH2 then stopHL2lmt[1] + 1  else if stopL2 then stopHL2lmt[1] + 1  else stopHL2lmt[1];
def stoph =  stopHL2lmt[1] >= 2  and stopH2 or stopH1;
def stopH_ =  if IsNaN(stoph) then 0 else stoph;
def stopl =  stopHL2lmt[1] >= 2 and stopL2 or stopL1;
def stopL_ =  if IsNaN(stopl) then 0 else stopl;
def stopHL =   stopH2 or stopL2 or stopH1  or stopL1;
def stopHL_ =  if IsNaN(stopHL) then 0 else stopHL;
### limit future signals below   1
def stopHLofst = CompoundValue(1, if start_ then 0 else if stopHL_ then 1 else stopHLofst[1], 0);
def stopHLofst_ = stopHLofst and !stopHLofst[1];
def activextend =  CompoundValue(1, if  start_ then 1 else if  stopHLofst_ then 0 else activextend[1], 0);
def breakout = ! activextend  and  activextend[1];
########################################## color
DefineGlobalColor("range", CreateColor(50, 80, 140));
DefineGlobalColor("range SD", CreateColor(100, 180, 160));
########################################## plot
plot dotss = consolidation;
dotss.SetPaintingStrategy(PaintingStrategy.POINTS);
dotss.SetLineWeight(1);
dotss.SetDefaultColor(Color.Yellow);
plot rangehigh = if activextend then highend  else Double.NaN;
rangehigh.SetLineWeight(2);
rangehigh.SetDefaultColor(Color.CYAN);
rangehigh.SetStyle(curve.Long_DASH);
plot rangelow = if activextend  then lowend else Double.NaN;
rangelow.SetLineWeight(2);
rangelow.SetDefaultColor(Color.CYAN);
rangelow.SetStyle(curve.Long_DASH);
plot rangehighSD = if activextend && breakSD then highend +stdevend  else Double.NaN;
rangehighSD.SetLineWeight(1);
rangehighSD .SetDefaultColor(Color.CYAN);
rangehighSD.SetPaintingStrategy(paintingStrategy.POINTS);
plot rangelowSD = if activextend && breakSD then lowend-stdevend  else Double.NaN;
rangelowSD.SetLineWeight(1);
rangelowSD.SetDefaultColor(Color.CYAN);
rangelowSD.SetPaintingStrategy(PaintingStrategy.points);
########################################## clouds
AddCloud(rangehigh, rangelow, globalcolor("range"));
AddCloud(rangehighsd, rangehigh,globalcolor("range SD"));
AddCloud(rangelow, rangelowsd, globalcolor("range SD"));
###################################################################################################################################
#################################################################### trade  #######################################################
###################################################################################################################################
def range =  highend_ - lowend_;
def mdrange = (highend_ - lowend_)/2;
def raTargmult = (highend_ - lowend_) * projectmult  ;
### create exit logic
def activetrade = !activextend && activextend[1] or !IsNaN(activextend[1]) and IsNaN(activextend) ;
### limit future signals below  2
def cntafterLmt = CompoundValue(1, if  activetrade  then 1 else if cntafterLmt[1] >= 1 and startcnt == 1 and startcnt[1] > 5 then cntafterLmt[1] else cntafterLmt[1] + 1, 1);
## limit entry  and exit signals
def findlmt = if activextend[1] and stopH_ then 1 else if activextend[1] and stopL_ then 2 else  if  activextend[1] and !stopL_ and  !stopH_ then double.nan else  findlmt[1];
##########################################  input targets
def targetswh;
def targetswl;
input projecttarget = { default fullRange, midRange, multRange};
switch (projecttarget ) {
case fullRange:
    targetswh =  highend_ + range ;
    targetswl = lowend_ - range;
case midRange:
    targetswh = highend_ + mdrange ;
    targetswl =  lowend_ - mdrange;
case multRange:
    targetswh =  highend_ + raTargmult ;
   targetswl =  lowend_ - raTargmult;
}
### projected targets
def trstopH1a = findlmt == 1 && high>targetswh ;
def trstopL1a = findlmt == 2 && low<targetswl;
def trstopH1b = if IsNaN(trstopH1a) then 0 else trstopH1a;
def trstopl1b = if IsNaN(trstopL1a) then 0 else trstopL1a;
def trstopH1c = if trstopH1b then 1  else trstopH1c [1] + 1;
def trstopl1c = if trstopl1b then 1 else  trstopl1c [1] + 1;
def tradestoph  = CompoundValue(1, if cntafterLmt>= 1 then lowend_  else tradestoph[1], 1);
def tradestopl  = CompoundValue(1, if cntafterLmt>= 1 then highend_ else tradestopl[1], 1);
def trstopH2a = findlmt==1 && low < tradestoph;
def trstopl2a = findlmt==2 &&  high > tradestopl ;
def trstopH2b =  if IsNaN(trstopH2a) then 0 else trstopH2a;
def trstopL2b = if IsNaN(trstopl2a) then 0 else trstopl2a;
def trstopH2c =  if trstopH2b then 1 else trstopH2c[1] + 1;
def trstopL2c = if trstopL2b then 1 else trstopL2c[1] + 1;
def trstopHL =  (trstopH1c >= 1 && trstopH1b or trstopH2c >= 1 && trstopH2b) or (trstopl1c >= 1 && trstopl1b or trstopL2c >= 1 && trstopL2b );
def trstopHL_ = if IsNaN(trstopHL ) then 0 else trstopHL ;
def activetrade_ = CompoundValue(1, if  activetrade then 1 else if trstopHL_[1] then 0 else activetrade_[1], 0);
### switch targetswh to plot
def switch1 = CompoundValue(1, if findlmt== 1 &&  cntafterLmt== 1 then targetswh else  if findlmt== 2 &&  cntafterLmt== 1 then  targetswl  else  switch1[1], double.nan);
def switch2 = CompoundValue(1, if findlmt==1  &&  cntafterLmt== 1 then highend_     else  if findlmt==2 &&  cntafterLmt== 1 then lowend_ else  switch2[1], double.nan);
def tradestop  = CompoundValue(1, if findlmt==1 &&  cntafterLmt==1  then lowend_ else if findlmt==2 && cntafterLmt==1  then highend_ else tradestop[1], 1);
def activeswitch = CompoundValue(1, if bn == 1 or Showtrade==no then double.nan else if activetrade_ then 1 else if trstopHL_[1]  then 0 else  activeswitch[1], double.nan);
def bueEn = !activextend and activextend[1];
def bueEx = !activeswitch and activeswitch[1];
plot rangeswitch2 = if  activeswitch then switch2 else Double.NaN;
rangeswitch2.SetLineWeight(2);
rangeswitch2.SetDefaultColor(Color.LIGHT_RED);
rangeswitch2.SetStyle(curve.Long_DASH);
plot rangeswitch1= if activeswitch then switch1 else Double.NaN;
rangeswitch1.SetLineWeight(2);
rangeswitch1.SetDefaultColor(Color.green);
rangeswitch1.SetStyle(curve.Long_DASH);
AddCloud(rangeswitch1, rangeswitch2,globalcolor("range"));
plot projectedstop = if activeswitch  then tradestop  else Double.NaN;
projectedstop.SetLineWeight(2);
projectedstop.SetDefaultColor(Color.light_RED);
projectedstop.SetStyle(curve.Long_DASH);
###### signals
plot bullEntry = findlmt==1 && bueEn ;
bullEntry.SetDefaultColor(Color.GREEN);
bullEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullEntry.SetLineWeight(2);
plot bearEntry = findlmt==2 && bueEn ;
bearEntry.SetDefaultColor(Color.GREEN);
bearEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearEntry.SetLineWeight(2);
plot bullExit = findlmt==1 && bueEx ;
bullExit.SetDefaultColor(Color.red);
bullExit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bullExit.SetLineWeight(2);
plot bearExit = findlmt==2 && bueEx ;
bearExit.SetDefaultColor(Color.RED);
bearExit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bearExit.SetLineWeight(2);
########################################## labels
def conscnt = CompoundValue(1, if !isnan(consolidation) then conscnt[1]+1 else 1, 1);
def cntuntil = if !isnan(consolidation) then Compresslength -conscnt[1] else double.nan;
AddLabel( ShowLabels,
" Inputs "+
" Length One: (" + Length1  +
") Length Two: (" + Length2 +")"+
") Compression Length  : (" + Compresslength +")"+
") Compress Value  : (" + Compress  +")"+
"  StDev : " +( if breakSD then "Yes" else "No")
, Color.WHITE );
AddLabel(Showtrade,
if activextend
then "  High Break at: " +highend_ + "  low Break at: "+ lowend_
else if !isnan(consolidation)
then "Forming Pattern In  = " +conscnt + "  Gauss FE  = "  + F   + " Normal FE  " + FE
else if activeswitch
then "  Target at: " +switch2 + "  Target at: "+ switch1
else "No Pattern Forming :  Gauss FE  = "  + F   + " Normal FE  " + FE
, if activextend or activeswitch
then color.green
else color.light_Green);
########################################## alerts
alert(consave , "Consolidation Pattern", alert.bar, sound.Ring);
alert(breakout, "Breakout", alert.bar, sound.Ring);
 
Last edited by a moderator:
@mcdon030, Just found this script. Looks awesome. Good work! Have been looking at a lot of articles, videos related to market maker method and this seem very useful.

Wanted to ask about the function of the dots. What are they there for? I can see it’s marking “consolidation” but how is it used to before a trade?

Also did you ever build a scan for it?
 
Last edited:
@mcdon030, Just found this script. Looks awesome. Good work! Have been looking at a lot of articles, videos related to market maker method and this seem very useful.

Wanted to ask about the function of the dots. What are they there for? I can see it’s marking “consolidation” but how is it used to before a trade?

Also did you ever build a scan for it?

It's fractional energy. It's not trend. Might help to research a little.

I wouldn't personally use particular script as it repaints. I could build quick scan and i think there already is one, but again probably need to correct this one.

I've totally been consumed with another project so I've been unable to complete this one. I have no idea when I'll be finished - the point when it's determined to be profitable or not :) - we will see.
 
Finished. no repaint: strategy built in as well

2020-06-12-TOS-CHARTS-Copy.png


https://tos.mx/HLTihEN
Code:
### study: Compression Box Breakout  V3
## author: Mcdon0330
## date: 6/12/2020
## signals from: Mobius Expansion Contraction Indicator (ECI):https://tos.mx/p8PbL4
## Notes:
## - uses Languerre Pivots and FE for signal and Box formation


##############################  Begin Inputs #####################################
input version = "20200612";
input length1 = 11;
input Compresslength = 1;  ##
input mult = .04;
input Compress  = .618;
input projectmult =.318;
input breakSD =yes;
input showlabel = yes;
##############################  END Inputs #####################################

##############################  Begin color  #####################################
DefineGlobalColor("range", CreateColor(50, 80, 140));
DefineGlobalColor("range SD", CreateColor(100, 180, 160));
##############################  END color #####################################
def bn = BarNumber();
def lbar = HighestAll(if IsNaN(close) then 0 else bn);

##############################  Begin Languerre PIvots #####################################


input price = close;
input gamma = 0.2;
rec L00 = (1 - gamma) * price + gamma * L00[1];
rec L11 = -gamma * L00 + L00[1] + gamma * L11[1];
rec L22 = -gamma * L11 + L11[1] + gamma * L22[1];
rec L33 = -gamma * L22 + L22[1] + gamma * L33[1];
def FIlt2 = (L00 + 2 * L11 + 2 * L22 + L33) / 6;
def FIR2 = (price + 2 * price[1] + 2 * price[2] + price[3]) / 6;
def plot3 = FIlt2;
def Plot4 = FIR2;

script ff {
    input v1 = 0.0 ;
    input v2 = 0.0;
    def bn = BarNumber();
    def lv1bar = HighestAll(if v1 then bn else 0);
    def lbar = HighestAll(if IsNaN(close) then 0 else bn);
    def va1 =  fold id = 1 to lbar with t = 0 while t == 0 do if GetValue(v1, -id) then id else 0;
    plot fva1 =  GetValue(v2, -va1);
def fva2 =  GetValue(v2, fva1 );
}
def hact = Plot4 > Plot3;
def lact = Plot4 < Plot3;
def htrigg =  if Plot4 <= Plot3 and Plot4[1] >= Plot3[1]  then 1 else Double.NaN;
def ltrigg =  if Plot4 >= Plot3 and Plot4[1] <= Plot3[1] then 1 else Double.NaN;
def htr = If(!IsNaN(htrigg[-1]), 1, 0);
def ltr = If(!IsNaN(ltrigg[-1]), 1, 0);
def stp = (hact or lact) and bn == lbar;
def stop = if IsNaN(stp) then 0 else stp;
def hpv = if IsNaN(htr) then 0 else htr ;
def lpv = if IsNaN(ltr) then 0 else ltr;
def hpvs = if !hpv then stop else hpv;
def lpvs = if !lpv then stop else lpv;
def lowv = if hpv then low else if low < lowv[1] then low else lowv[1];
def highv = if lpv  then high else if high > highv[1] then high   else highv[1];
def PLow = if hpv then ff(lpvs, lowv)  else PLow[1];
def Phigh = if lpv then ff(hpvs, highv) else Phigh[1];
def pl_ = low == PLow;
def ph_ = high == Phigh ;
def plcnt = if pl_[1] then 1 else plcnt[1]+1;
def phcnt = if ph_[1] then 1 else phcnt[1]+1;
def pla =  pl_ && !pl_[1];
def pha = ph_ && !ph_[1];
def pvtl =(plcnt >=phcnt && pla and pha) or (pla and !pha && phcnt<plcnt );
def pvth =(phcnt >=plcnt && pha and pla) or (pha and !pla && plcnt<phcnt);
def phbn1 = compoundValue(1,if pvth  then bn else phbn1[1],bn);
def phbn2 =compoundValue(1, if pvth && phbn1!=phbn1[1] then phbn1[1] else phbn2[1],bn);
def phminbn = Min(lowestall(phbn1),lowestall(phbn2));
def plbn1 = compoundValue(1,if pvtl   then bn else plbn1[1],bn);
def plbn2 = compoundValue(1,if pvtl && plbn1!=plbn1[1] then plbn1[1] else plbn2[1],bn);
def plminbn = Min(lowestall(plbn1),lowestall(plbn2));
def phlminbn = Min(plbn2,phbn2);
def ph1  = if pvth then high else ph1 [1];
def ph2 = if pvth && ph1 <>ph1[1] then ph1 [1] else ph2[1];
def ph3 = if pvth && ph2 <>ph2[1] then ph2[1] else ph3[1];
def ph4 = if pvth && ph3 <>ph3[1] then ph3[1] else ph4[1];
def ph5 = if pvth && ph4 <>ph4[1] then ph4[1] else ph5[1];
def pl1 = if pvtl then low else pl1[1];
def pl2 = if pvtl && pl1<>pl1[1] then pl1[1] else pl2[1];
def pl3 = if pvtl && pl2<>pl2[1] then pl2[1] else pl3[1];
def pl4 = if pvtl && pl3<>pl3[1] then pl3[1] else pl4[1];
def pl5= if pvtl && pl4<>pl4[1] then pl4[1] else pl5[1];

##############################  END Pivots #####################################

##############################  Begin Signals  #####################################
def Boxpivotpattern = if ph1 <=ph2 && pl1 >=pl2  then 1 else double.nan;
def bodyHeight = BodyHeight();
def IsUp = close > open;
def IsDown = close < open;
def LowVol = volume < Average(volume, 50);
def buybody = bodyHeight > Average(bodyHeight, length1);
### begin Mobius gaussion FE
script p {
    input data   = close;
    input Length = 20;
    def w = (2 * Double.Pi / (Length / 2));
    def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / Length) - 1);
    def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    def a = Power(alpha, 4) * data + 4 * (1 - alpha) * a[1] - 6 * Power(1 - alpha, 2) * a[2] + 4 * Power(1 - alpha, 3) * a[3] - Power(1 - alpha, 4) * a[4];
    plot line = a;
}
def o = p(open, Length = Length1);
def l = p(low, Length = Length1);
def h = p(high, Length = Length1);
def c = p(close, Length = Length1);
def bar = BarNumber();
def HMax = Highest(Max(h, c[1]), Length1);
def LMax = Lowest(Min(l, c[1]), Length1);
def TR = Max(h, c[1]) - Min(l, c[1]);
def R = Highest(h, Length1) - Lowest(l, Length1);
def F = Log(Sum(TR, Length1) / R) / Log(Length1);
def consolidation =  if F crosses above Compress then close else if f> Compress then close else double.nan;
###  end  Mobius gaussion FE

def consave =  Boxpivotpattern && !isnan(consolidation) and sum(!isnan(consolidation[1]),Compresslength )==Compresslength ;
def con_ = if IsNaN(consave) then 0 else consave;
def savemaxn = if con_ && !con_[1]  then bn else savemaxn[1];
def conbn = if con_  then bn else conbn[1];
def startcnt = if con_ then startcnt[1] + 1 else startcnt[1];
def gethigh = compoundvalue(1, if  con_ && !con_[1]  then  max(ph1[1],high) else gethigh[1],high);
def getlow = compoundvalue(1,  if con_  && !con_[1]   then min(pl1[1],low)  else getlow[1],low);
def getstdev= compoundvalue(1, if con_  && !con_[1]  then StDev(close, length1) else getstdev[1],0);
def getSVSD = compoundvalue(1, if con_  && !con_[1] then (Highest(getstdev, length1) + Lowest(getstdev, length1)) / 2 else getsvsd[1],0);
##############################  END Signals  #####################################

##############################  Begin Variables and Limiter #####################################
def gethigh_ = if breakSD==no then gethigh else gethigh+getSVSD;
def getlow_ = if breakSD==no then getlow else getlow-getSVSD;
def stopH1 = buybody  and low>= gethigh_ or close crosses above gethigh_*1.002;
def stopL1 = buybody  and high<= getlow_ or close crosses below getlow_*.998;
def stopH2 = low> gethigh_ and high[1]<=gethigh_;
def stopL2 =  high <getlow_ and low[1]>=getlow_;
def bull1 =   (stopH1 or stopH2);
def bull1_ = if IsNaN(bull1 ) then 0 else bull1 ;
def bear1 =  (stopL1 or stopL2);
def bear1_ = if IsNaN(bear1) then 0 else bear1;
def bulllmt =  CompoundValue(1, if bn==1 then 0
                                else  if   con_ && !bulllmt[1] then 1
                                else if bull1_[1] then 0                                     
                                else bulllmt[1], 0);
def bearlmt =  CompoundValue(1, if bn==1 then 0
                                else  if   con_ && !bearlmt[1] then 1
                                else if bear1_[1]  then 0                                     
                                else  bearlmt [1], 0);
def actlmt = bulllmt or  bearlmt ;
def range =     gethigh_ - getlow_;
def mdrange =   (gethigh_ - getlow_)/2;
def raTargmult = (gethigh_ - getlow_) * projectmult  ;
##########################################  input targets
def targetswh;
def targetswl;
input projecttarget = {fullRange,  default midRange, multRange};
switch (projecttarget ) {
case fullRange:
    targetswh =  gethigh_ + range ;
    targetswl =getlow_- range;
case midRange:
    targetswh = gethigh_ + mdrange ;
    targetswl = getlow_- mdrange;
case multRange:
    targetswh =  gethigh_ + raTargmult ;
   targetswl = getlow_- raTargmult;
}
### projected targets
def bulle1 =actlmt && startcnt[1]>=1 && high>targetswh ;
def beare1 = actlmt &&startcnt[1]>=1 && low<targetswl;
def bulle1_ = if IsNaN(bulle1) then 0 else bulle1;
def beare1_ = if IsNaN(beare1 ) then 0 else beare1 ;
def bulle1cnt = if bulle1_  then 1  else bulle1cnt[1] + 1;
def beara1cnt = if beare1_ then 1 else  beara1cnt[1] + 1;
def tradestoph  = CompoundValue(1, if bulle1cnt >= 1 or beara1cnt>=1 then getlow_*.998 else tradestoph[1], 1);
def tradestopl  = CompoundValue(1, if bulle1cnt >= 1 or beara1cnt>=1 then gethigh_*1.002 else tradestopl[1], 1);
def tradestophx  = CompoundValue(1, if bulle1cnt >= 1 or beara1cnt>=1 then getlow*.998 else tradestophx[1], 1);
def tradestoplx  = CompoundValue(1, if bulle1cnt >= 1 or beara1cnt>=1 then gethigh*1.002  else tradestoplx[1], 1);
def bulle2 = close<= tradestoph or close crosses below tradestoph   or close crosses below tradestoplx ;
def beare2 =  close>= tradestopl  or close crosses above tradestopl  or close crosses above tradestophx  ;
def bulle2_ =  if IsNaN(bulle2) then 0 else  bulle2 ;
def beare2_ = if IsNaN(beare2) then 0 else beare2 ;               
def bull2lmt =  CompoundValue(1,if !bulllmt && bulllmt[1] then 1
                                else if bulle1_[1] && bull2lmt[1]then 0
                                else if  bulle2_[1] && bull2lmt[1] then 0
                                else bull2lmt[1], 0);               
def bear2lmt =  CompoundValue(1,if !bearlmt && bearlmt[1] then 1
                                else if beare1_[1] && bear2lmt[1]
                                then 0 else if  beare2_[1] && bear2lmt[1]
                                then 0 else bear2lmt[1], 0);
def activeBuy= CompoundValue(1, if bearlmt && !bulllmt && bulllmt[1]then 1
                                else if !bearlmt &&  !bull2lmt&& bull2lmt[1]  then 0 
                                else if !bull2lmt&& bull2lmt[1] then 0
                                else activeBuy[1], 0);
def activesell = CompoundValue(1,if bulllmt && !bearlmt && bearlmt[1] then 1
                                else  if bulllmt && !bearlmt && bearlmt[1] then 0
                                else if !bear2lmt&& bear2lmt[1]  then 0
                                else activesell[1], 0);
 def buyopen = CompoundValue(1,if activeBuy&& !activeBuy[1]  then 1
                                else  if !activeBuy && activeBuy[1] then 0
                                else  buyopen[1], 0);   
def startbox =(bulllmt && !bulllmt[1]  or bearlmt && !bearlmt[1]) ;
def stopbox =activeBuy or activesell ;
def stopboxx = if isnan(stopbox) then 0 else stopbox;
def stoptradex = !activeBuy&& activeBuy[1] or !activesell and activesell[1];
def stoptradexx =if isnan(stoptradex ) then 0 else stoptradex ;
def activebox = CompoundValue(1,if bn==1 then 0
                                else  if   con_ && !activebox[1] then 1
                                else  if   con_ && activebox[1] && !stopboxx then 1
                                else  if stopboxx[1] then 0
                                else activebox[1], 0);
def gethighx = compoundvalue(1, if  startbox then gethigh
                                else if  !stopboxx && gethigh!=gethigh[1]then gethighx[1]
                                else if stopboxx then gethighx[1]
                                else gethighx[1],double.nan );
def getlowx = compoundvalue(1, if  startbox then getlow
                                else if  !stopboxx && getlow!=getlow[1]then getlowx[1]
                                else  if stopboxx    then getlowx[1]
                                else getlowx[1],double.nan );
def gethighsdx = compoundvalue(1, if  startbox then gethigh + getSVSD
                                else if  !stopboxx && gethigh!=gethigh[1]then gethighsdx[1]
                                else if stopboxx then gethighsdx[1]
                                else gethighsdx[1],double.nan );
def getlowsdx = compoundvalue(1, if  startbox then getlow - getSVSD
                                else if  !stopboxx && getlow!=getlow[1]then getlowsdx[1]
                                else  if stopboxx    then getlowsdx[1]
                                else getlowsdx[1],double.nan );               
def BTO=  activeBuy&& !activeBuy[1];
def STO = activesell and !activesell[1];
def STC =!activeBuy&& activeBuy[1];
def BTC =!activesell and activesell[1];
def activetrade = CompoundValue(1, if bn==1 then 0
                                else  if !activebox && activebox[1] then 1             
                                else  if con_ && activetrade[1] && !stoptradexx then 1
                                else  if stoptradexx[1] then 0 else activetrade[1],0);
def switchh = CompoundValue(1, if bn==1 then 0
                                else  if activetrade && !activetrade[1] &&  BTO[1]&&  !STO[1] then targetswh             
                                else  if activetrade && !activetrade[1]&&  STO[1]&&  !BTO[1] then getlowx
                                else  switchh [1],double.nan);
def switchl = CompoundValue(1, if bn==1 then 0
                                else  if activetrade && !activetrade[1] &&  BTO[1]&&  !STO[1] then gethighx           
                                else  if activetrade && !activetrade[1]&&  STO[1]&&  !BTO[1] then targetswl
                                else  switchl[1],double.nan);

##############################  END Variables and Limiter #####################################

##NOTE takeout ## below to activevate strategy ;
##AddOrder(OrderType.BUY_TO_OPEN,BTO[-1], tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LE");
##AddOrder(OrderType.SELL_TO_CLOSE,STC[-1],tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "lx");
##AddOrder(OrderType.SELL_TO_OPEN,STO[-1], tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");
##AddOrder(OrderType.BUY_TO_CLOSE,BTC[-1],tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "Sx");


##############################  Begin PLots #####################################
plot dotss = if con_ then close else double.nan;
dotss.SetPaintingStrategy(PaintingStrategy.POINTS);
dotss.SetLineWeight(5);
dotss.SetDefaultColor(Color.Yellow);
plot bullentry =  if BTO then close else double.nan;
bullentry.AssignValueColor(Color.green);
bullentry.SetPaintingStrategy(paintingStrategy.ARROW_UP);
bullentry.SetLineWeight(2);
plot bullexit = if STC then close else double.nan;
bullexit.AssignValueColor( Color.red);
bullexit.SetPaintingStrategy(paintingStrategy.ARROW_DOWN);
bullexit.SetLineWeight(2);
plot bearentry =  if  STO  then close else double.nan;
bearentry.AssignValueColor(Color.green);
bearentry.SetPaintingStrategy(paintingStrategy.ARROW_down);
bearentry.SetLineWeight(2);
plot bearexit = if BTC then close else double.nan;
bearexit.AssignValueColor( Color.red);
bearexit.SetPaintingStrategy(paintingStrategy.ARROW_up);
bearexit.SetLineWeight(2);
plot rangehigh =if activebox  then  gethighx else Double.NaN;
rangehigh.SetLineWeight(2);
rangehigh.SetDefaultColor(Color.CYAN);
rangehigh.SetStyle(curve.Long_DASH);
plot rangelow = if activebox  then  getlowx else Double.NaN;
rangelow.SetLineWeight(2);
rangelow.SetDefaultColor(Color.green);
rangelow.SetStyle(curve.Long_DASH);
plot rangehighSD =if activebox  then  gethighsdx  else Double.NaN;
rangehighSD.SetLineWeight(1);
rangehighSD.SetDefaultColor(Color.green);
rangehighSD.SetPaintingStrategy(paintingStrategy.POINTS);
rangehighSD.SetHiding(!breakSD);
plot rangelowSD = if activebox  then  getlowsdx else Double.NaN;
rangelowSD.SetLineWeight(1);
rangelowSD.SetDefaultColor(Color.cyan);
rangelowSD.SetPaintingStrategy(paintingStrategy.POINTS);
rangelowSD.SetHiding(!breakSD);
plot rangehightgt =if activetrade then  switchh else Double.NaN;
rangehightgt .SetLineWeight(1);
rangehightgt .assignValueColor( if rangehightgt==targetswh then color.green else color.red);
rangehightgt .setPaintingStrategy(paintingStrategy.HORIZONTAL);;
plot rangelowtgt =if activetrade then  switchl else Double.NaN;
rangelowtgt .SetLineWeight(1);
rangelowtgt .assignValueColor( if rangelowtgt==targetswl then color.green else color.red);
rangelowtgt .setPaintingStrategy(paintingStrategy.HORIZONTAL);;
AddCloud(rangehightgt,rangelowtgt, color.gray,color.gray);
AddCloud(rangehigh, rangelow, globalcolor("range"));
AddCloud(rangehighsd, rangelowsd, globalcolor("range SD"));


##############################  End PLots #####################################

##############################  start labels and alerts #####################################
AddLabel(1, "FE_Box->" + version, Color.ORANGE);
AddLabel(showlabel ,
if activebox
then "  High Break at: " +gethighx + "  low Break at: "+ getlowx
else if !isnan(consolidation)
then "  Gauss FE  = "  +F
else if activetrade && switchh==targetswh
then "  Target at: " +switchh + " Stop at : "+ switchl
else if activetrade && switchh==getlowx
then "  Target at: " +switchl + " Stop at : "+ switchh
else "No Pattern Forming :  Gauss FE  = "  + F
, if activebox or activetrade
then color.green
else color.light_Green);
########################################## alerts
alert(consave , "Consolidation Pattern", alert.bar, sound.Ring);
alert(stopbox, "Breakout", alert.bar, sound.Ring);
##############################  end labels and alerts #####################################

## end code
 
Last edited by a moderator:
Hi Mcdon! Where can I read how to use this indicator?

Hi there,

the only difference between this and most other FE scrips is the pivot pattern which is this line:

Code:
def Boxpivotpattern = if ph1 <=ph2 && pl1 >=pl2  then 1 else double.nan;

According to everything I've read and been told, FE just says something is about to change. I probably should have written more guidance as the line above was a compression pattern/ contracting triangle. My attempt was confluence of price pattern and "change"/FE. add the below to review the last 4 pivots before the box paints.

Code:
### pivot points
input boffset = .025;
input showpivot =yes;
plot phplot = if  showpivot &&  pvth  then  high + boffset * ticksize()  else double.nan;
phplot.AssignValueColor(Color.red);
phplot.SetPaintingStrategy(paintingStrategy.ARROW_down);
phplot.SetLineWeight(2);
plot plplot =if showpivot &&  pvtl   then low - boffset * ticksize() else double.nan;
plplot.AssignValueColor( Color.green);
plplot.SetPaintingStrategy(paintingStrategy.ARROW_up);
plplot.SetLineWeight(2);

With all custom scripts, it can be approved. Personally, I would only touch the trade logic itself and i may do that soon.

cheers.

mcdon030
 

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
414 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