Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study("Sniper XBTUSD Full", overlay=true)
- /////////////////////////////////////
- //* Put your strategy logic below *//
- /////////////////////////////////////
- sourcein=high
- haclose = security(heikinashi(tickerid), period, close)
- hullper=input(title="Hull Length", type=integer, defval=1, minval=1,maxval=500)
- hull = vwma(2*sma(sourcein,round(hullper/2))-sma(sourcein,hullper),round(sqrt(hullper)))
- price = ema(close,1)
- topdecay = input(1, "Top Decay")
- decayt = atr(topdecay)*0.005
- topstage = input(-22, "Top Stage Length")
- topmalength = input(150, "TopMa Length")
- botdecay = input(1, "Bot Decay")
- decayb = atr(botdecay)*0.005
- botstage = input(-15, "Bot Stage Length")
- botmalength = input(1, "Bot Ma Length")
- topvector01 = 0.0
- topvector01finalcounter = 0.0
- pretopvector01 = nz(topvector01[2], sourcein)
- topvector01 := sourcein >= pretopvector01 ? sourcein : pretopvector01 - (decayt * topvector01finalcounter[1])
- topvector01counter = n - valuewhen(sourcein >= topvector01, n, 0)
- topvector01finalcounter := topvector01counter <= 87 ? topstage : topvector01counter <= 87*4 ? 15 : 12
- botvector01 = 0.0
- botvector01finalcounter = 0.0
- prebotvector01 = nz(botvector01[1], sourcein)
- botvector01 := sourcein <= prebotvector01 ? sourcein : prebotvector01 + (decayb * botvector01finalcounter[1])
- botvector01counter = n - valuewhen(sourcein <= botvector01, n, 0)
- botvector01finalcounter := botvector01counter <= 87 ? botstage : botvector01counter <= 87*4 ? 15 : 12
- topvecMA = sma(topvector01,topmalength)
- botvecMA = sma(botvector01,botmalength)
- // Long/Short Logic
- // Long/Short Logic
- longLogic = crossunder(hull,botvecMA) ? 1 : 0 or high[0] > high[1] and high[0] > high[2] and high[0] > high[3] and high[0] > high[4] and high[0] > high[5] and high[0] > high[6] and high[0] > high[7]? 1 : 0
- shortLogic = crossunder(hull,topvecMA) ? 1 : 0 or low[1] < low[2] and low[0] < low[5] and low[0] < low[6] and low[0] < low[7]? 1 : 0 //crossover(hull,topvecMA) ? 1 : 0 or
- // Bar Colors and signals
- //plotshape(longLogic, title= "ReversalLong", location=location.belowbar, color=green, style=shape.triangleup, text="BUY")
- //plotshape(shortLogic, title= "ReversalShort", location=location.abovebar, color=red, style=shape.triangledown, text="SELL")
- shortflipvalue = valuewhen(shortLogic,open+10,0)
- longflipvalue = valuewhen(longLogic,open-10,0)
- longflip = crossunder(price,longflipvalue) or crossunder(price,shortflipvalue)
- shortflip = crossover(price,shortflipvalue) or crossover(price,longflipvalue)
- long_entry = longLogic //Long Or Buy Condition Here
- short_entry = shortLogic //Short Or Sell Condition Here
- ////////////////////////////////////////////////////////////////////////////
- //Replace Only If Valid Exit Conditions
- long_exit = short_entry
- short_exit = long_entry
- // === /END
- ///////////////////////////////////////////////////////////////////////////
- // init these values here, they will get updated later as more decisions are made
- last_long_close = na
- last_short_close = na
- // === Long position detection ===
- // longs open
- longo = 0
- longo := nz(longo[1])
- // longs closed
- longc = 0
- longc := nz(longc[1])
- if long_entry
- longo := longo + 1
- longc := 0
- if long_exit
- longc := longc + 1
- longo := 0
- // === /END
- // === Short position detection ===
- shorto = 0
- shorto := nz(shorto[1])
- shortc = 0
- shortc := nz(shortc[1])
- if short_entry
- shorto := shorto + 1
- shortc := 0
- if short_exit
- shortc := shortc + 1
- shorto := 0
- // === /END
- // === Pyramiding Settings ===
- pyr = input(1, title="Pyramiding Setting")
- longCondition = long_entry and longo <= pyr
- longX = long_exit and longc <= pyr
- shortCondition = short_entry and shorto <=pyr
- shortX = short_exit and shortc <=pyr
- // === /END
- // === Get Last Position Price ===
- last_open_longCondition = na
- last_open_shortCondition = na
- // last open prices
- last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
- last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])
- // === /END
- // === Check For Long/Short ===
- last_longCondition = na
- last_shortCondition = na
- // last open times
- last_longCondition := longCondition ? time : nz(last_longCondition[1])
- last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
- last_longClose = longX ? time : nz(last_long_close[1])
- last_shortClose = shortX ? time : nz(last_short_close[1])
- in_longCondition = last_longCondition > last_shortCondition and last_longCondition >= last_longClose
- in_shortCondition = last_shortCondition > last_longCondition and last_shortCondition >= last_shortClose
- // === /END
- isSL = input(false, "Take Profit")
- longSLlevel = input(17, "Long TP % above entry")
- shortSLlevel = input(60, "Short TP % below entry")
- longentry = valuewhen(longCondition,close,0)
- shortentry = valuewhen(shortCondition,close,0)
- longmath = (longentry * longSLlevel) / 100
- shortmath = (shortentry * shortSLlevel) / 100
- longstop = longentry + longmath
- shortstop = shortentry - shortmath
- long_sl = isSL and in_longCondition and crossover(price,longstop)
- short_sl = isSL and in_shortCondition and crossunder(price,shortstop)
- longSLcol = in_longCondition[1] ? lime : black
- shortSLcol = in_shortCondition[1] ? red : black
- //Create Single Close For All Closing Conditions ===
- closelong = long_sl or longX
- closeshort = short_sl or shortX
- // Get Last Close
- last_long_close := closelong ? time : nz(last_long_close[1])
- last_short_close := closeshort ? time : nz(last_short_close[1])
- // Check For Close Since Last Open
- if closelong and last_long_close[1] > last_longCondition
- closelong := 0
- if closeshort and last_short_close[1] > last_shortCondition
- closeshort := 0
- // === /END
- // longCloseCol = na
- // shortCloseCol = na
- // longCloseCol := long_tp ? purple : long_sl ? maroon : longCloseCol[1]
- // shortCloseCol := short_tp ? purple : short_sl ? maroon : shortCloseCol[1]
- // tpColor = isTP and in_longCondition ? purple : isTP and in_shortCondition ? purple : white
- slColor = isSL and in_shortCondition and crossunder(price,shortstop)? lime : isSL and in_longCondition? lime : isSL and in_longCondition and crossover(price,longstop) ? white : red
- //==Plots==
- c2 = in_longCondition ? lime :in_shortCondition ? red : black// slColor// in_shortCondition and isSL ? red : isSL and in_longCondition ? lime : black
- n1t=plot(topvecMA, "Top MA", color = red, linewidth= 8, transp=65)
- n1b=plot(botvecMA, "Bot MA", color = lime, linewidth= 8, transp=65)
- n2b=plot(hull, "Signal MA", color=c2, transp=5)
- fill(n1b, n1t, color=c2, transp=85)
- ///////////////////////////////
- //======[ Alert Plots ]======//
- ///////////////////////////////
- // New Signal Plots
- plotshape(series=longCondition, title="Long",text = "Sniper long", style=shape.triangleup, location=location.belowbar, color=lime, size=size.small)
- plotshape(series=shortCondition, title="Short",text = "Sniper short", style=shape.triangledown, location=location.abovebar, color=red, size=size.small)
- //plotshape(series=long_sl, title="Take money long", text = "Take money long", style=shape.triangledown, location=location.abovebar, color=red, size=size.tiny)
- //plotshape(series=short_sl, title="Take money short", text = "Take money short", style=shape.triangleup, location=location.belowbar, color=lime, size=size.tiny)
- //plotshape(series=long_sl3, title="SL", text = "SL", style=shape.triangledown, location=location.abovebar, color=red, size=size.tiny)
- //plotshape(series=short_sl3, title="SL", text = "SL", style=shape.triangleup, location=location.belowbar, color=lime, size=size.tiny)
- alertcondition(condition=longCondition, title="Long", message="/Market_Buy*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
- alertcondition(condition=shortCondition, title="Short", message="/Market_Sell*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
- alertcondition(condition=long_sl, title="Take money long", message="/close*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
- alertcondition(condition=short_sl, title="Take money short",message ="/close*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement