Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Maurizio-Ciullo
- // Candelstick Pattern Morning-Evening-Star
- //@version=4
- strategy(title="Bot Good-Evening-Morning-Star ETH/PERP FTX 4H LONG E SHORT", shorttitle = "E/M Star", overlay=true,
- pyramiding=0, initial_capital=150,
- commission_type=strategy.commission.percent,
- commission_value=0.1, slippage=3,
- default_qty_type=strategy.percent_of_equity,
- default_qty_value=27.5)
- // Inputs
- input_take_prof_long_mult = input(title="take_prof_long_mult", type=input.float, defval=2.5, minval=0, maxval=100000, step=0.1, group="Profit")
- input_stop_loss_long_mult = input(title="stop_loss_long_mult", type=input.float, defval=2.5, minval=0, maxval=100000, step=0.1, group="Stop")
- input_take_prof_short_mult = input(title="take_prof_short_mult", type=input.float, defval=2.5, minval=0, maxval=100000, step=0.1, group="Profit")
- input_stop_loss_short_mult = input(title="stop_loss_short_mult", type=input.float, defval=2.5, minval=0, maxval=100000, step=0.1, group="Stop")
- // Variables
- stop_loss_long_ticks = abs(strategy.position_avg_price - high[2]) / syminfo.mintick
- plot(stop_loss_long_ticks, title="stop_loss_long_ticks", linewidth=3, color=color.orange)
- stop_loss_long_mult = stop_loss_long_ticks * input_stop_loss_long_mult / 100
- plot(stop_loss_long_mult, title="stop_loss_long_mult", color=color.purple, transp=3, linewidth=4)
- stop_loss_long_e_mult_ticks = stop_loss_long_ticks + stop_loss_long_mult
- plot(stop_loss_long_e_mult_ticks, title="stop_loss_long_e_mult_ticks", color=color.red, transp=3, linewidth=4)
- stop_loss_long = strategy.position_avg_price + stop_loss_long_e_mult_ticks / 10
- plot(stop_loss_long, title="stop_loss_long", color=color.yellow, transp=3, linewidth=4)
- //* imput_stop_loss_long
- // Detect morning/shooting star start /////////////////////////////////////////////////////////////////////////////////////////////
- //candle1 = left candle, candle2 = middle candle, candle3 = right candle
- candle1_Open = open[2]
- candle1_Close = close [2]
- candle2_Open = open[1]
- candle2_Close = close[1]
- candle2_Low = low[1]
- candle2_High = high[1]
- candle3_Open = open
- candle3_Close = close
- //bullish calc first
- candle1_BodySize = candle1_Open - candle1_Close
- candle2_BodySize = candle2_Close - candle2_Open
- candle2_WickLength = candle2_High - candle2_Close
- candle3_BodySize = candle3_Close - candle3_Open
- //logic to figure out bullishish Star pattern formed
- bullishStar = (candle1_Close < candle1_Open) and ((candle2_Open <= candle2_Close) and (candle2_BodySize <= (.333333*(candle1_BodySize))) and (candle2_WickLength > candle2_BodySize)) and ((candle3_Open >= candle2_Close) and (candle3_Close > candle3_Open) and (candle2_BodySize <= (.333333*(candle3_BodySize))) and (candle3_Close > candle1_Open))
- //plot the indicator on chart
- plotshape(bullishStar, style = shape.triangleup, location = location.belowbar, color=color.green, size = size.small)
- //now calc bearish
- candle1_BodySize := candle1_Close - candle1_Open
- candle2_BodySize := candle2_Open - candle2_Close
- candle2_WickLength := candle2_Close - candle2_Low
- candle3_BodySize := candle3_Open - candle3_Close
- //logic to figure out bearish Star pattern forming
- bearishStar = (candle1_Close > candle1_Open) and ((candle2_Open >= candle2_Close) and (candle2_BodySize <= (.333333*(candle1_BodySize))) and (candle2_WickLength > candle2_BodySize)) and ((candle3_Open >= candle2_Close) and (candle3_Close < candle3_Open) and (candle2_BodySize <= (.333333*(candle3_BodySize))) and (candle3_Close < candle1_Open))
- //plot the indicator on chart
- plotshape(bearishStar, style = shape.triangledown, location = location.abovebar, color=color.red, size = size.small)
- //below allows you to setup alerts
- alertcondition(bullishStar, title = "Bullish Star", message = "[CurrencyPair] [TimeFrame], Bullish Star formed")
- alertcondition(bearishStar, title = "Bearish Star", message = "[CurrencyPair] [TimeFrame], Bearish Star formed")
- ////================================BACKTEST================================//Uncomment this section if backtesting (must also switched this from a study to a strategy above)
- // // === INPUT BACKTEST RANGE ===
- // FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
- // FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
- // FromYear = input(defval = 2017, title = "From Year", minval = 2017)
- // ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
- // ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
- // ToYear = input(defval = 9999, title = "To Year", minval = 2017)
- // // === FUNCTION EXAMPLE ===
- // start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
- // finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
- // window() => time >= start and time <= finish ? true : false // create function "within window of time"
- // // === EXECUTION === //Keep this commented out unless backtesting
- // strategy.entry("L", strategy.long, 25000, when = bullishStar == 1 and window()) // buy long when "within window of time" AND crossover
- // strategy.exit("exit", "L", profit = 40, loss = 20)
- // strategy.entry("S", strategy.short, 25000, when = bearishStar == 1 and window()) // buy long when "within window of time" AND crossover
- // // strategy.exit("exit", "S", profit = 40, loss = 20)
- // Detect morning/shooting star end /////////////////////////////////////////////////////////////////////////////////////////////
- // STEP 1 DATARANGE:
- // Make input options that configure backtest date range
- startDate = input(title="Start Date", type=input.integer,
- defval=18, minval=1, maxval=31, group="Periodo")
- startMonth = input(title="Start Month", type=input.integer,
- defval=08, minval=1, maxval=12, group="Periodo")
- startYear = input(title="Start Year", type=input.integer,
- defval=2017, minval=1800, maxval=2100, group="Periodo")
- endDate = input(title="End Date", type=input.integer,
- defval=01, minval=1, maxval=31, group="Periodo")
- endMonth = input(title="End Month", type=input.integer,
- defval=01, minval=1, maxval=12, group="Periodo")
- endYear = input(title="End Year", type=input.integer,
- defval=2121, minval=1800, maxval=2100, group="Periodo")
- // STEP 2 DATARANGE:
- // Look if the close time of the current bar
- // falls inside the date range
- inDateRange = (time >= timestamp(syminfo.timezone, startYear,
- startMonth, startDate, 0, 0)) and
- (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
- //Condizione Entry Long: Chiusura candela bullishStar
- condEntryLong = bullishStar and inDateRange
- //Condizione Exit Long: Low candela - percentuale moltiplicatore stop
- condExitLong = close < low[4] //- input_stop_loss_long_mult
- // Condizione Entry Short: Chiusura candela bearishStar
- condEntryShort = bearishStar and inDateRange
- // Condizione Exit Short: High candela + percentuale moltiplicatore stop
- condExitShort = close > high[4] //+ input_stop_loss_short_mult
- // Esecuzione Ordini
- if (condEntryLong)
- strategy.entry("long", true)
- strategy.exit("stop loss", from_entry = "long", stop = low[1])
- //if (condExitLong)
- // strategy.close(id="long")
- if (condEntryShort)
- strategy.entry("short", false)
- strategy.exit("stop loss", from_entry = "short", stop = high[1])
- //if (condExitShort)
- // strategy.close(id="short")
- //from_entry_to_stop = (strategy.position_avg_price - high[2])
- //plot(from_entry_to_stop, title="from_entry_to_stop")
- //plot(high[2] - strategy.position_avg_price * 0.01 * 10, title="stop_loss_limit_short", color=color.purple, transp=3, linewidth=4)
- //plot(abs(strategy.position_avg_price - high[2]) / syminfo.mintick / 100 * 100, title="stop_loss_long")//* imput_stop_loss_long
Add Comment
Please, Sign In to add comment