# indie:lang_version = 5 from indie import indicator, MainContext, param, source, color, plot, line_style from indie.algorithms import Bb from indie.math import cross_over, cross_under from indie.schedule import Schedule, ScheduleRule, WORKDAYS from datetime import time from math import nan
@indicator('XAU/USD BB Breakout Scalper', overlay_main_pane=True) @param.int('bb_length', default=20, min=1, title='BB Length') @param.float('bb_mult', default=2.0, min=0.1, title='BB Multiplier') @param.int('sl_points', default=50, min=1, title='SL Points (reference)') @param.int('tp_points', default=100, min=1, title='TP Points (reference)') @param.float('order_size', default=0.1, min=0.01, title='Order Size (reference)') @plot.line('lower_bb', title='Lower BB', color=color.BLUE(0.7), line_width=1) @plot.line('middle_bb', title='Middle BB', color=color.GRAY(0.5), line_width=1, line_style=line_style.DASHED) @plot.line('upper_bb', title='Upper BB', color=color.BLUE(0.7), line_width=1) @plot.fill('lower_bb', 'upper_bb', color=color.BLUE(0.05)) @plot.marker('Buy Signal', style=plot.marker_style.LABEL, text='BUY', position=plot.marker_position.BELOW, color=color.GREEN, size=3) @plot.marker('Sell Signal', style=plot.marker_style.LABEL, text='SELL', position=plot.marker_position.ABOVE, color=color.RED, size=3) @plot.background(color=color.GREEN(0.07)) class Main(MainContext): def __init__(self, bb_length, bb_mult, sl_points, tp_points, order_size): london_rule = ScheduleRule(start=time(hour=8), end=time(hour=12), days=WORKDAYS) ny_rule = ScheduleRule(start=time(hour=13), end=time(hour=17), days=WORKDAYS) self._session_schedule = Schedule(rules=[london_rule, ny_rule], timezone='UTC')
def calc(self, bb_length, bb_mult, sl_points, tp_points, order_size): lower_bb, middle_bb, upper_bb = Bb.new(self.close, bb_length, bb_mult)
in_session = self.time[0] in self._session_schedule
buy_signal = cross_over(self.close, upper_bb) and in_session sell_signal = cross_under(self.close, lower_bb) and in_session
buy_marker = self.low[0] if buy_signal else nan sell_marker = self.high[0] if sell_signal else nan
bg = plot.Background() if in_session else plot.Background(color=color.TRANSPARENT)
return lower_bb[0], middle_bb[0], upper_bb[0], plot.Fill(), buy_marker, sell_marker, bg


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