# indie:lang_version = 5
from indie import ( indicator, MainContext, sec_context, plot, color, TimeFrame )
from math import nan
# ========================== # Daily Context # ========================== @sec_context def DailyContext(self): # Previous completed daily candle return self.high[1], self.low[1]
# ========================== # Indicator # ========================== @indicator("Previous Day Sweep", overlay_main_pane=True)
@plot.line("PDH", color=color.RED, line_width=2)
@plot.line("PDL", color=color.GREEN, line_width=2)
@plot.marker( title="PDH Sweep", text="PDH", color=color.RED, position=plot.marker_position.ABOVE, style=plot.marker_style.LABEL, )
@plot.marker( title="PDL Sweep", text="PDL", color=color.GREEN, position=plot.marker_position.BELOW, style=plot.marker_style.LABEL, )
class Main(MainContext):
def __init__(self):
self.prevHigh, self.prevLow = self.calc_on( sec_context=DailyContext, time_frame=TimeFrame.from_str("1D") )
def calc(self):
pdh = self.prevHigh[0] pdl = self.prevLow[0]
bearishSweep = ( self.high[0] > pdh and self.close[0] < pdh )
bullishSweep = ( self.low[0] < pdl and self.close[0] > pdl )
return ( pdh, pdl, self.high[0] if bearishSweep else nan, self.low[0] if bullishSweep else nan )


Be the first to comment
Publish your first comment to unleash the wisdom of crowd.