Hi All,
I seem to always get stuck on this. I can't get my strategy to repeat each historical occurrence of the setup and trigger. It only finds the most recent occurrence. Any idea what I did wrong?
Thanks!!!
I seem to always get stuck on this. I can't get my strategy to repeat each historical occurrence of the setup and trigger. It only finds the most recent occurrence. Any idea what I did wrong?
Thanks!!!
Code:
def bn = BarNumber();
def TimeFrame = getaggregationperiod();
#######################################################################################################
#PIVOT SECTION
input LBPeriod = 10;
#--------------------------------------------------------------
def HH = Highest(high(Period = TimeFrame), LBPeriod);
def marketHigh1 = if HH > HH[-LBPeriod] then HH else HH[-LBPeriod];
def markedHigh1 = high(Period = TimeFrame) == marketHigh1;
def lastMarkedHigh1 = CompoundValue(1, if IsNaN( markedHigh1) then lastMarkedHigh1[1] else if markedHigh1 then high(Period = TimeFrame) else lastMarkedHigh1[1], high(Period = TimeFrame));
#-------------------------------------------------------------
plot HP = lastMarkedHigh1;
def HPBN = if high(Period = TimeFrame) == HP then bn else HPBN[1];
#--------------------------------------------------------------
def LL = Lowest(low(Period = TimeFrame), LBPeriod);
#--------------------------------------------------------------
def marketLow1 = if LL < LL[-LBPeriod] then LL else LL[-LBPeriod];
def markedLow1 = low(Period = TimeFrame) == marketLow1;
def lastMarkedLow1 = CompoundValue(1, if IsNaN(markedLow1) then lastMarkedLow1[1] else if markedLow1 then low(Period = TimeFrame) else lastMarkedLow1[1], low(Period = TimeFrame));
plot LV = lastMarkedLow1 ;
#--------------------------------------------------------------
HP.SetPaintingStrategy(PaintingStrategy.DASHES);
HP.SetDefaultColor(Color.GREEN);
#--------------------------------------------------------------
LV.SetPaintingStrategy(PaintingStrategy.DASHES);
LV.SetDefaultColor(Color.RED);
def High1Val = if bn == HPBN then high else High1Val[1];
def HighCrossbn = if high crosses above High1Val then bn else 0;
def HighestAllHighCrossbn = HighestAll(HighCrossbn);
AddChartBubble(bn == HighestAllHighCrossbn, high, "High Stop Run", Color.RED);
def lowpattern = low < low[1] and low < low[-1] ;
def islowpatternbn = if lowpattern then bn else 0;
def lowpatternbn = if bn > HighestAllHighCrossbn then Double.NaN else if islowpatternbn then islowpatternbn else Double.NaN;
def highestalllowpatternbn = HighestAll(lowpatternbn) ;
AddChartBubble(bn == highestalllowpatternbn, low, "Displacement Low", Color.RED);
def highestalllowpatternvalue = if bn == highestalllowpatternbn then low else highestalllowpatternvalue[1];
def islowpatternvalid = bn > highestalllowpatternbn ;
def ShortWatchActivated = if islowpatternvalid and low crosses below highestalllowpatternvalue then 1 else ShortWatchActivated[1];
#AddChartBubble(ShortWatchActivated, low, "Short Watch Active", Color.RED);
# FVG Fair Value Gaps Bearish & Bullish Levels
# @TradeForOpp 5/6/2022
input threshold = 0.001;
def aggregation = GetAggregationPeriod();
def fvgBear = if low(period = aggregation)[2] - high(period = aggregation) > 0 then 1 else 0;
def fvgBearPctg = if AbsValue((high(period = aggregation) - low(period = aggregation)[2]) / low(period = aggregation)[2]) > threshold then 1 else 0;
def fvgBearH = if ShortWatchActivated and fvgBear and fvgBearPctg then low(period = aggregation)[2] else 0;
def fvgBearL = if fvgBearH then high(period = aggregation) else Double.NaN;
def fvgBearMem1 = if fvgBearH then fvgBearH else fvgBearMem1[1];
def fvgBearMem2 = if fvgBearH then fvgBearL else fvgBearMem2[1];
plot fvgBearM1 = fvgBearMem1;
plot fvgBearM2 = fvgBearMem2;
fvgBearM1.SetLineWeight(3);
fvgBearM2.SetLineWeight(3);
fvgBearM1.SetDefaultColor(Color.MAGENTA);
fvgBearM2.SetDefaultColor(Color.MAGENTA);
fvgBearM1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fvgBearM2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
def BearBreach = high crosses above fvgBearM2 ;
def BearBreachBN = if BearBreach then bn else BearBreachBN[1];
addchartbubble(BearBreach, high, BearBreach, color.yellow);
###TRIGGERS###
def ShortTrigger = bearbreach;
def SE = ShortTrigger ;
def SEBN = if se then bn else SEBN[1];
def LAllSEBN = lowestall(BearBreachBN);
def HighStop = if bn == LAllSEBN then Low[4] else 0;
def sxstop = high > HighStop;
AddOrder(OrderType.SELL_TO_OPEN, SE[-1], arrowcolor = Color.WHITE, tickcolor = Color.YELLOW, name = "SE", price = high[0]);
AddOrder(OrderType.BUY_TO_CLOSE, high[-1] crosses above fvgBearMem1, tickcolor = Color.WHITE, arrowcolor = Color.Magenta, name = "SX Stop", price = fvgBearMem1);