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/
- //Il trading system completo Study- Swing-Trend (Strategia Trend Following Con Swing Di Posizione) - parte 2
- // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Giorni=Sabato) (Esclusione Mesi=Ottobre)
- // (Take Profit Long/Short= Market Close Sopra/Sotto Medie) (Stop Loss Limit= -2,5% Tradingview-Hub) (Stop Loss Emergenza Long/Short = Market Close Sopra/Sotto Medie)
- // Nello Study non c'è lo stop loss limit perchè è impostato a -2.5% su tradingview-hub
- //@version=4
- study(title="Study Swing-Trend ETH/PERP FTX 4H LONG E SHORT", overlay=false)
- input_ema_long_apertura = input(title="Media Long Apertura", type=input.integer, defval=45, minval=0, maxval=500, group="Medie")
- input_ema_long_chiusura = input(title="Media Long Chiusura", type=input.integer, defval=35, minval=0, maxval=500, group="Medie")
- input_ema_short_apertura = input(title="Media Short Apertura", type=input.integer, defval=40, minval=0, maxval=500, group="Medie")
- input_ema_short_chiusura = input(title="Media Short Chiusura", type=input.integer, defval=30, minval=0, maxval=500, group="Medie")
- perc_apertura_minima_long = input(title="perc_apertura_minima_long", type=input.float, defval=0, step=0.1, group="Filtri Posizione")
- perc_apertura_massima_long = input(title="perc_apertura_massima_long", type=input.float, defval=2, step=0.1, group="Filtri Posizione ")
- perc_chiusura_minima_long = input(title="perc_chiusura_minima_long", type=input.float,defval=1.5, step=0.1, group="Filtri Posizione")
- perc_apertura_minima_short = input(title="perc_apertura_minima_short", type=input.float, defval=0.75, step=0.01, group="Filtri Posizione")
- perc_apertura_massima_short = input(title="perc_apertura_massima_short", type=input.float, defval=2, step=0.1, group="Filtri Posizione")
- perc_chiusura_minima_short = input(title="perc_chiusura_minima_short", type=input.float, defval=1, step=0.1, group="Filtri Posizione")
- onlyLong = input(title="Solo long trade", type=input.bool, defval=false, inline="1", group="Direzione")
- onlyShort = input(title="Solo short trade", type=input.bool, defval=false, inline="1", group="Direzione")
- input_stop_loss = input(title="stop_loss_long", type=input.float, defval=2.5, minval=0, maxval=100, step=0.1, group="Stop")
- input_risk = input(title="Percentuale rischio", type=input.float, defval=27.5, minval=0, maxval=100, step = 0.01, group="Stop")
- ema_long_apertura = ema(close, input_ema_long_apertura)
- ema_long_chiusura = ema(close, input_ema_long_chiusura)
- ema_short_apertura = ema(close,input_ema_short_apertura)
- ema_short_chiusura = ema(close,input_ema_short_chiusura)
- //Calcolo filtri e stop loss
- apertura_minima_long = (ema_long_apertura / 100) * perc_apertura_minima_long
- apertura_massima_long = (ema_long_apertura / 100) * perc_apertura_massima_long
- chiusura_minima_long = (ema_long_chiusura / 100) * perc_chiusura_minima_long
- apertura_minima_short = (ema_short_apertura / 100) * perc_apertura_minima_short
- apertura_massima_short = (ema_short_apertura / 100) * perc_apertura_massima_short
- chiusura_minima_short = (ema_short_chiusura / 100) * perc_chiusura_minima_short
- //Entry/Exit Conditions
- //Condizione Entry Long: Chiusura candela sopra media lenta con differenziale medie e media veloce maggiore media ExitLong
- condEntryLong = close > (ema_long_apertura + apertura_minima_long) and close < (ema_long_apertura + apertura_massima_long) and close > open and not onlyShort and dayofweek != 7 and month !=10
- //Condizione Exit Long: Crossunder di due medie
- condExitLong = close < (ema_long_chiusura - chiusura_minima_long)
- // Condizione Entry Short: Crossunder di due medie con il prezzo di chiusura che è comunque sotto una terza media con differenziale delle medie
- condEntryShort = close < (ema_short_apertura - apertura_minima_short) and close > (ema_short_apertura - apertura_massima_short) and close < open and not onlyLong and dayofweek != 7 and month !=10
- // Condizione Exit Short: Crossover di medie con il prezzo di chiusura che è comunque sopra una terza media
- condExitShort = close > (ema_short_chiusura + chiusura_minima_short)
- //definizione variabili posizioni aperte
- IsLongOpen = false
- IsLongOpen := condEntryLong[1] ? true : condExitLong[1] ? false : condEntryShort[1] ? false : IsLongOpen[1]
- IsShortOpen = false
- IsShortOpen := condEntryShort[1] ? true : condExitShort[1] ? false : condEntryLong[1] ? false : IsShortOpen[1]
- IsFlat = true
- IsFlat := not IsLongOpen and not IsShortOpen
- //conversione bool -> float, per debug
- IsLongOpenFloat = if IsLongOpen == true
- 1
- else
- 0
- IsShortOpenFloat = if IsShortOpen == true
- 1
- else
- 0
- IsFlatFloat = if IsFlat == true
- 1
- else
- 0
- //plot posizioni aperte, per debug
- //plot (IsLongOpenFloat)
- //plot (IsShortOpenFloat,color=color.yellow)
- //plot (IsFlatFloat,color=color.red)
- //variabili apertura e chiusura posizione
- OpenLong = condEntryLong //and not IsLongOpen
- CloseLong = condExitLong and IsLongOpen and not condEntryShort
- OpenShort = condEntryShort //and not IsShortOpen
- CloseShort = condExitShort and IsShortOpen and not condEntryLong
- //conversione bool -> float, per debug
- OpenShortFloat = if OpenShort == true
- 1
- else
- 0
- CloseShortFloat = if CloseShort == true
- 1
- else
- 0
- OpenLongFloat = if OpenLong == true
- 1
- else
- 0
- CloseLongFloat = if CloseLong == true
- 1
- else
- 0
- //plot aperture ordini, per debug
- plot (OpenShortFloat,color=color.red)
- plot (CloseShortFloat,color=color.yellow)
- plot (OpenLongFloat,color=color.blue)
- plot (CloseLongFloat,color=color.white)
- //alert
- // Plot entry ed exit degli allert
- //plotshape(series=OpenLong, text="entry_long", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
- //plotshape(series=CloseLong, text="close_long", style=shape.triangleup, location=location.belowbar, color=color.olive, size=size.small)
- //plotshape(series=OpenShort, text="entry_short", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
- //plotshape(series=CloseShort, text="close_short", style=shape.triangledown, location=location.abovebar, color=color.purple, size=size.small)
- alertcondition(OpenLong,title="Open Long")
- alertcondition(CloseLong,title="Close Long")
- alertcondition(OpenShort,title="Open Short")
- alertcondition(CloseShort,title="Close Short")
Add Comment
Please, Sign In to add comment