Why is my strategy only recording the most recent signal and trigger?

greco26

Active member
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!!!

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);
 
Just kidding. Figured it out. I keep forgetting to use HighestAll() in my pattern.
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  highestall(islowpatternbn) then highestall(islowpatternbn) else 0;
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 0;
#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 highestall(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 = highestall(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);
 

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