//@version=4 strategy("FS ATR & PS (MA)", overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=5000, currency=currency.USD, calc_on_every_tick=true) // Strategy Buy = input(true) Sell = input(true) // Time Period start_year = input(title='Start year' ,defval=2019) start_month = input(title='Start month' ,defval=1) start_day = input(title='Start day' ,defval=1) start_hour = input(title='Start hour ' ,defval=0) start_minute = input(title='Start minute' ,defval=0) end_time = input(title='set end time?',defval=false) end_year = input(title='end year' ,defval=2019) end_month = input(title='end month' ,defval=12) end_day = input(title='end day' ,defval=31) end_hour = input(title='end hour' ,defval=23) end_minute = input(title='end minute' ,defval=59) // MA ema_period = input(title='EMA period',defval=10) wma_period = input(title='WMA period',defval=20) ema = ema(close,ema_period) wma = wma(close,wma_period) // Entry Condition longCondition = crossover(ema,wma) and Buy and nz(strategy.position_size) == 0 and time > timestamp(start_year, start_month, start_day, start_hour, start_minute) and (end_time?(time < timestamp(end_year, end_month, end_day, end_hour, end_minute)):true) shortCondition = crossunder(ema,wma) and Sell and nz(strategy.position_size) == 0 and time > timestamp(start_year, start_month, start_day, start_hour, start_minute) and (end_time?(time < timestamp(end_year, end_month, end_day, end_hour, end_minute)):true) // Exit Condition a = input(20)*10 b = input(40)*10 c = a*syminfo.mintick d = b*syminfo.mintick long_stop_level = float(na) long_profit_level1 = float(na) long_profit_level2 = float(na) long_even_level = float(na) short_stop_level = float(na) short_profit_level1 = float(na) short_profit_level2 = float(na) short_even_level = float(na) long_stop_level := longCondition ? close - c : long_stop_level [1] long_profit_level1 := longCondition ? close + c : long_profit_level1 [1] long_profit_level2 := longCondition ? close + d : long_profit_level2 [1] long_even_level := longCondition ? close + 0 : long_even_level [1] short_stop_level := shortCondition ? close + c : short_stop_level [1] short_profit_level1 := shortCondition ? close - c : short_profit_level1 [1] short_profit_level2 := shortCondition ? close - d : short_profit_level2 [1] short_even_level := shortCondition ? close + 0 : short_even_level [1] // Position Sizing Risk = input(defval=10, title="Risk per trade%", step=1, minval=0, maxval=100)/100 size = floor(strategy.equity * Risk / c ) // Strategy if longCondition strategy.entry("Buy" , strategy.long, qty=size) strategy.exit ("Exit1", stop=long_stop_level, limit=long_profit_level1, qty=size/2) strategy.exit ("Exit2", stop=long_stop_level, limit=long_profit_level2) if shortCondition strategy.entry("Sell" , strategy.short, qty=size) strategy.exit ("Exit3", stop=short_stop_level, limit=short_profit_level1, qty=size/2) strategy.exit ("Exit4", stop=short_stop_level, limit=short_profit_level2) // Plot plot(strategy.position_size <= 0 ? na : long_stop_level , color=#dc143c, style=plot.style_linebr, linewidth=1) plot(strategy.position_size <= 0 ? na : long_profit_level1 , color=#00ced1, style=plot.style_linebr, linewidth=1) plot(strategy.position_size <= 0 ? na : long_profit_level2 , color=#00ced1, style=plot.style_linebr, linewidth=1) plot(strategy.position_size <= 0 ? na : long_even_level , color=#ffffff, style=plot.style_linebr, linewidth=1) plot(strategy.position_size >= 0 ? na : short_stop_level , color=#dc143c, style=plot.style_linebr, linewidth=1) plot(strategy.position_size >= 0 ? na : short_profit_level1, color=#00ced1, style=plot.style_linebr, linewidth=1) plot(strategy.position_size >= 0 ? na : short_profit_level2, color=#00ced1, style=plot.style_linebr, linewidth=1) plot(strategy.position_size >= 0 ? na : short_even_level , color=#ffffff, style=plot.style_linebr, linewidth=1) plot(ema,color=#00ced1) plot(wma,color=#dc143c)