// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © yashp1334 //@version=4 //@version=3 strategy("Evening/Morning Star Pattern", shorttitle = "E/M Star", overlay=true)//comment this out if backtesting //strategy("Evening/Morning Doji")//uncomment this if backtesting //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) //INTRADAY s=input(title="INTRA DAY TRADE SESSION",type=input.session,defval="0915-1450") st=time(timeframe.period,s) e=input(title="END SESSION",type=input.session,defval="1515-1520") et=time(timeframe.period,e) quant=input(title="Trade Quantity",defval=1) //adding stoploss and target option ut=input(defval=false,title="USE TARGET") us=input(defval=false,title="USE STOPLOSS") tar=input(defval=10.0,title="TARGET IN RS") stop=input(defval=7.0,title="STOP LOSS IN RS") tar:=tar/syminfo.mintick stop:=stop/syminfo.mintick //setting automated alerts required by apibridge lxse="TYPE: LX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) sxle="TYPE: SX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) le="TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) lx="TYPE:LX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) se="TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) sx="TYPE:SX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) if(bullishStar and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(bearishStar and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(bullishStar and st and strategy.position_size!=0) strategy.entry("BUY",strategy.long,comment=sxle) if(bearishStar and st and strategy.position_size!=0) strategy.entry("SELL",strategy.short,comment=lxse) if(ut==true and us==false) strategy.exit(id="LX",from_entry="BUY",profit=tar,comment=lx) strategy.exit(id="SX",from_entry="SELL",profit=tar,comment=sx) if(us==true and ut==false) strategy.exit(id="LX",from_entry="BUY",loss=stop,comment=lx) strategy.exit(id="SX",from_entry="SELL",loss=stop,comment=sx) if(ut==true and us==true) strategy.exit(id="LX",from_entry="BUY",profit=tar,loss=stop,comment=lx) strategy.exit(id="SX",from_entry="SELL",profit=tar,loss=stop,comment=sx) strategy.close(id="BUY",when=et,comment=lx) strategy.close(id="SELL",when=et,comment=sx)