Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- //
- //This alert script is for use with Autoview.
- //Use the corresponding strategy script to backtest parameters and fill in the defaults here with the best results.
- //Checks for correlated action on US Dollar Index (DXY), GOLD:USD (XAU), and the currency being traded against USD (CUR).
- // Modify DXY with any quote currency strength meter,
- // GOLD:QUOTE (thus the need for a GOLD:BTC pair),
- // and any currency pair trading against the quote currency.
- // Experiment with different triangular correlations in strategy mode.
- //
- //Original "BTCbot HullMA 3x Pair" script written by SeaSide420
- //
- study("BTCbot2", shorttitle="BTCbot2", overlay=true)
- keh=input(title="HullMA Length",type=integer,defval=7, minval=1)
- dt = 0.001
- ot=1
- src = ohlc4[1]
- tf='60' //Set desired timeframe. This can only be set manually here.
- //
- DXY=(security("DXY",tf, src)) //USDollar index... Quote currency strength.
- e2ma=2*wma(DXY,round(keh/2))
- ema=wma(DXY,keh)
- ediff=e2ma-ema
- esqn=round(sqrt(keh))
- e2ma1=2*wma(DXY[1],round(keh/2))
- ema1=wma(DXY[1],keh)
- ediff1=e2ma1-ema1
- esqn1=round(sqrt(keh))
- e1=wma(ediff,esqn)
- e2=wma(ediff1,esqn)
- XAU=(security("XAUUSD", tf, src)) //Gold:USD or correlated asset.
- n2ma=2*wma(XAU,round(keh/2))
- nma=wma(XAU,keh)
- ndiff=n2ma-nma
- nsqn=round(sqrt(keh))
- n2ma1=2*wma(XAU[1],round(keh/2))
- nma1=wma(XAU[1],keh)
- ndiff1=n2ma1-nma1
- nsqn1=round(sqrt(keh))
- n1=wma(ndiff,nsqn)
- n2=wma(ndiff1,nsqn)
- CUR=(security("BTCUSD", tf, src)) //Crypto:USD pair being traded.
- s2ma=2*wma(CUR,round(keh/2))
- sma=wma(CUR,keh)
- sdiff=s2ma-sma
- ssqn=round(sqrt(keh))
- s2ma1=2*wma(CUR[1],round(keh/2))
- sma1=wma(CUR[1],keh)
- sdiff1=s2ma1-sma1
- ssqn1=round(sqrt(keh))
- s1=wma(sdiff,ssqn)
- s2=wma(sdiff1,ssqn)
- confidence=(security(tickerid, 'D', src)-security(tickerid, 'D', src[1]))/security(tickerid, 'D', src[1])
- //
- //Hull Ribbon Chart Visuals
- b=s1>s2?lime:black
- c=s1>s2?black:red
- c1=plot(s1, color=b, title="hull1", linewidth=2, transp=0)
- c2=plot(s2, color=c, title="hull1", linewidth=2, transp=0)
- fill(c1, c2, color=c, transp=75)
- //Original Triggers
- //closelong = e1>e2 and confidence<dt
- //if (closelong)
- // strategy.close("Long")
- //
- //Comment out short triggers for buy-sell strategy
- //
- //closeshort = e1<e2 and confidence>dt
- //if (closeshort)
- // strategy.close("Short")
- //
- //longCondition = e1<e2 and n1>n2 and s1>s2 and strategy.opentrades<ot and confidence>dt
- //if (longCondition)
- // strategy.entry("Long",strategy.long)
- //
- //shortCondition = e1>e2 and n1<n2 and s1<s2 and strategy.opentrades<ot and confidence<dt
- //if (shortCondition)
- // strategy.entry("Short",strategy.short)
- //
- //Short condition triggers commented out for a buy-sell strategy
- ////////////////////////===ANION=CODE====///////////////////////////////////
- // //
- // ULTIMATE PINE INJECTOR V1.2 + rs fix //
- // //
- ////////////////////////////////////////////////////////////////////////////
- // === Conditions ===
- long_entry = e1<e2 and n1>n2 and s1>s2 and confidence>dt //Long Or Buy Condition Here
- short_entry = e1>e2 and n1<n2 and s1<s2 and confidence<dt //Short Or Sell Condition Here
- long_exit = e1>e2 and confidence<dt //Close Long Condition Here (Optional)
- short_exit = e1<e2 and confidence>dt //Close Short Condition Here (Optional)
- // === /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")
- pyr = 1
- 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
- // === Stop Loss (Long) ===
- isSLl = input(false, "Stop Loss (Long)")
- sll = input(0, "Stop Loss %", type=float, step=0.2, minval=0, maxval=100) / 100
- long_call_sl = last_open_longCondition * (1 - sll)
- long_sl = isSLl and low <= long_call_sl and longCondition == 0
- // === /END
- // === Stop Loss (Short) ===
- isSLs = input(false, "Stop Loss (Short)")
- sls = input(0, "Stop Loss %", type=float, step=0.2, minval=0, maxval=100) / 100
- short_call_sl = last_open_shortCondition * (1 + sls)
- short_sl = isSLs and high >= short_call_sl and shortCondition == 0
- // === /END
- // === Trailing Stop ===
- last_high = na
- last_low = na
- last_high := in_longCondition ? (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1]) : na
- last_low := in_shortCondition ? (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1]) : na
- isTSl = input(true, "Trailing Stop Long")
- tsil = input(19, "Activate Trailing Stop % Long", type=float, step=1, minval=0, maxval=100) / 100
- tsl = input(2, "Trailing Stop % Long", type=float, step=1, minval=0, maxval=100) / 100
- long_call_ts = last_high * (1 - tsl)
- long_call_tsi = last_open_longCondition * (1 + tsil)
- long_ts = isTSl and not na(last_high) and low <= long_call_ts and longCondition == 0 and last_high >= long_call_tsi
- isTSs = input(true, "Trailing Stop Short")
- tsis = input(19, "Activate Trailing Stop % Short", type=float, step=1, minval=0, maxval=100) / 100
- tss = input(2, "Trailing Stop % Short", type=float, step=1, minval=0, maxval=100) / 100
- short_call_ts = last_low * (1 + tss)
- short_call_tsi = last_open_shortCondition * (1 - tsis)
- short_ts = isTSs and not na(last_low) and high >= short_call_ts and shortCondition == 0 and last_low <= short_call_tsi
- // === /END
- // === Create Single Close For All Closing Conditions ===
- closelong = long_sl or long_ts or longX
- closeshort = short_sl or short_ts 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
- ////////////////////////////////////////////////////////////////////////////
- // === Alarm Settings ===
- alertcondition(longCondition==1, title='LONG', message='LONG')
- alertcondition(closelong==1, title='EXIT LONG', message='EXIT LONG')
- alertcondition(shortCondition==1, title='SHORT', message='SHORT')
- alertcondition(closeshort==1, title='EXIT SHORT', message='EXIT SHORT')
- // === /END
- ////////////////////////////////////////////////////////////////////////////
- // === Debugs Here ===
- //Remove "//" To Check/Debug The Code Above
- // Signal Shapes
- plotshape(longCondition[1]==1, title='LONG', style=shape.triangleup, size=size.large, color=#02CB80, location= location.belowbar)
- plotshape(shortCondition[1]==1, title='SHORT', style=shape.triangledown, size=size.large, color=#DC143C, location=location.abovebar)
- plotshape(shortCondition[1]==0 and closelong[1]==1, title='EXIT LONG', style=shape.xcross, color=#02CB80, location=location.belowbar, transp=0)
- plotshape(longCondition[1]==0 and closeshort[1]==1, title='EXIT SHORT', style=shape.xcross, color=#DC143C, location=location.abovebar, transp=0)
- // SL Plot
- slColor = (isSLl or isSLs) and (in_longCondition or in_shortCondition) ? red : white
- plot(isSLl and in_longCondition ? long_call_sl : na, "Long SL", slColor, style=3, linewidth=2)
- plot(isSLs and in_shortCondition ? short_call_sl : na, "Short SL", slColor, style=3, linewidth=2)
- // TP Plot
- //tpColor = isTP and (in_longCondition or in_shortCondition) ? purple : white
- //plot(isTP and in_longCondition ? long_call_tp : na, "Long TP", tpColor, style=3, linewidth=2)
- //plot(isTP and in_shortCondition ? short_call_tp : na, "Short TP", tpColor, style=3, linewidth=2)
- // TS Plot
- tsColor = (isTSl or isTSs) and (in_longCondition or in_shortCondition) ? orange : white
- tsiColor = (isTSl or isTSs) and (in_longCondition or in_shortCondition) ? white : orange
- plot(isTSl and in_longCondition ? long_call_tsi : na, "Long Trailing", tsiColor, style=3, linewidth=2)
- plot(isTSs and in_shortCondition ? short_call_tsi : na, "Short Trailing", tsiColor, style=3, linewidth=2)
- plot(isTSl and in_longCondition and last_high > long_call_tsi ? long_call_ts : na, "Long Trailing", tsColor, style=2, linewidth=2)
- plot(isTSs and in_shortCondition and last_low < short_call_tsi ? short_call_ts : na, "Short Trailing", tsColor, style=2, linewidth=2)
- // === /END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement