Advertisement
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/
- // © gabriele_t84
- // ATTENZIONE QUESTO STUDY SARA' QUELLO CHE GENERERA' GLI ALERT A TV-HUB PERCHE' GIRA AL TICK
- // Questa strategia era la vecchia Scalping Exponential Bot forse con qualcosa di diverso non lo so ... ma ottimizzata sui dati di bybit e non ftx come
- // lo era la precedente.
- // Questa strategia è stata finita solo da Gabriele ma non ho niente apparte il codice strategia, no report/ no altro.
- // Non è stata testata bene, è rimasta nel casseto a metà, è stata solo ottimizzata da Gabriele sui nuovi dati di Bybit
- // ma non è mai stata attivata o convalidata.
- // Questo è uno study il quale stavamo facendo delle prove per andare live direttamente dallo study perchè lo strategy
- // si incasina con varip "tick indicatori e source".
- // C'è un'altro strategy che abbiamo creato identico a questo e non uno study
- // ma stò aspettando Gabriele che me lo passa.
- //Scalping exponetial bot tendenza data da due medie, close sopra la terza media, trailing stop doppio,
- //Periodo in sample 1/5/21 - 1/10/21
- //Periodo out of sample 1/10/21 - 28/04/22
- //@version=5
- indicator("Study Bot Scalping-Exponential-Tick ETH/PERP Ver-5 BYBIT 5M LONG E SHORT", overlay = true, precision = 2,
- max_bars_back=500 )
- //// variabili varip ///////
- //////close varip
- varip price = 0.0
- price := close
- if barstate.isrealtime and price != close
- price := close
- plot(price, title='price')
- ///// vlow varip
- varip vlow = 0.0
- vlow := low
- if barstate.isrealtime and vlow != low
- vlow := low
- //// high varip
- varip vhigh = 0.0
- vhigh := high
- if barstate.isrealtime and vhigh != high
- vhigh := high
- // if barstate.isnew
- // ticks := 0
- // lastPrice := close
- // Input
- input_target_long = input.float(title="input_take_profit_long", defval=5.0, minval=0.1, maxval=1000, group='Target')
- input_stop_loss_long = input.float(title="input_stop_loss_long", defval=1.3, minval=0.1, maxval=1000, group='Stop Loss')
- input_target_short = input.float(title="input_take_profit_short", defval=10.0, minval=0.1, maxval=1000, group='Target')
- input_stop_loss_short = input.float(title="input_stop_loss_short", defval=1.1, minval=0.1, maxval=1000, group='Stop Loss')
- lunghezza_adx = input.int(title="lunghezza adx", defval=9, minval=0, maxval=1000, group='Differenziale Dmi')
- differenziale_adx_basso_long = input.float(title="differenziale_adx_basso_long", defval=0.0, minval=0.0, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- differenziale_adx_alto_long = input.float(title="differenziale_adx_alto_long", defval=27.0, minval=0.1, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- differenziale_adx_basso_short = input.float(title="differenziale_adx_basso_short", defval=30.0, minval=0.1, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- differenziale_adx_alto_short = input.float(title="differenziale_adx_alto_short", defval=60.0, minval=0.1, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- lunghezza_rsi = input.int(title="lunghezza_rsi", defval=9, minval=1, maxval=1000, group='Differenziale Rsi', tooltip="Opera In Base Ai Range Rsi")
- differenziale_rsi_long = input.float(title="differenziale_rsi_long", defval=65.0, minval=0.1, maxval=1000, group='Differenziale Rsi', tooltip="Opera In Base Ai Range Rsi")
- differenziale_rsi_short = input.float(title="differenziale_rsi_short", defval=45.0, minval=0.1, maxval=1000, group='Differenziale Rsi', tooltip="Opera In Base Ai Range Rsi")
- lunghezza_media_long = input.int(title="media_long", defval=130, minval=1, maxval=1000, group='Medie')
- lunghezza_media_short = input.int(title="media_short", defval=110, minval=1, maxval=1000, group='Medie')
- lunghezza_media_tendenza_veloce_long = input.int(title="media_tendenza_veloce_long", defval=42, minval=1, maxval=1000, group='Medie')
- lunghezza_media_tendenza_lenta_long = input.int(title="media_tendenza_lenta_long", defval=216, minval=1, maxval=1000, group='Medie')
- lunghezza_media_tendenza_veloce_short = input.int(title="media_tendenza_veloce_short", defval=54, minval=1, maxval=1000, group='Medie')
- lunghezza_media_tendenza_lenta_short = input.int(title="media_tendenza_lenta_short", defval=108, minval=1, maxval=1000, group='Medie')
- input_trailing_stop_trigger_long1 = input.int(title="trigger long 1", defval=50, minval=1, maxval=1000, group='Trailing')
- input_trailing_stop_close_long1 = input.int(title="close long 1", defval=20, minval=1, maxval=1000, group='Trailing')
- input_trailing_stop_trigger_long2 = input.int(title="trigger long 2", defval=70, minval=1, maxval=1000, group='Trailing')
- input_trailing_stop_close_long2 = input.int(title="close long 2", defval=50, minval=1, maxval=1000, group='Trailing')
- input_trailing_stop_trigger_short1 = input.int(title="trigger short 1", defval=40, minval=1, maxval=1000, group='Trailing')
- input_trailing_stop_close_short1 = input.int(title="close short 1", defval=20, minval=1, maxval=1000, group='Trailing')
- input_trailing_stop_trigger_short2 = input.int(title="trigger short 2", defval=70, minval=1, maxval=1000, group='Trailing')
- input_trailing_stop_close_short2 = input.int(title="close short 2", defval=50, minval=1, maxval=1000, group='Trailing')
- perc_apertura_minima_long = input.float(title="perc_apertura_minima_long", defval=0.07, minval=0.01, maxval=1000, group='apertura minima')
- perc_apertura_minima_short = input.float(title="perc_apertura_minima_short", defval=0.05, minval=0.01, maxval=1000, group='apertura minima')
- in_solo_long = input.bool(title='Solo long', defval=false, inline='1', group='Direzione')
- in_solo_short = input.bool(title='Solo short', defval=false, inline='1', group='Direzione')
- // Medie Mobili
- media_long = ta.ema(close, lunghezza_media_long)
- plot(media_long, color=color.new(color.blue, 0), title='Ema Long', linewidth=2)
- media_tendenza_lenta_long = ta.ema(close, lunghezza_media_tendenza_lenta_long)
- media_tendenza_veloce_long = ta.ema(close, lunghezza_media_tendenza_veloce_long)
- plot(media_tendenza_lenta_long, color=color.new(color.purple, 0), title='media_tendenza_lenta_long', linewidth=2)
- plot(media_tendenza_veloce_long, color=color.new(color.aqua, 0), title='media_tendenza_veloce_long', linewidth=2)
- media_short = ta.ema(close, lunghezza_media_short)
- plot(media_short, color=color.new(color.red, 0), title='Ema Short', linewidth=2)
- media_tendenza_lenta_short = ta.ema(close, lunghezza_media_tendenza_lenta_short)
- media_tendenza_veloce_short = ta.ema(close, lunghezza_media_tendenza_veloce_short)
- plot(media_tendenza_lenta_short, color=color.new(color.olive, 0), title='media_tendenza_lenta', linewidth=2)
- plot(media_tendenza_veloce_short, color=color.new(color.lime, 0), title='media_tendenza_veloce', linewidth=2)
- //Apertura minima
- apertura_minima_long = (media_long / 100) * perc_apertura_minima_long
- apertura_minima_short = (media_short / 100) * perc_apertura_minima_short
- // Variabili Rsi Long e Short
- valore_rsi = ta.rsi(close, lunghezza_rsi)
- plot(valore_rsi, title = "valore_rsi", color=color.blue)
- // Variabili Adx
- [di_pos, di_neg, adx] = ta.dmi(lunghezza_adx, lunghezza_adx)
- valore_adx = adx
- plot(adx, title="adx_long")
- // Calcolo del tempo con il tempo attuale
- var orario_barra = 0.0
- varip secondi = 0.0
- if barstate.isrealtime and secondi != timenow
- secondi := timenow
- plot(secondi, title="secondi")
- //Condizioni entrata
- // condEntryLong = close > (media_long + apertura_minima_long) and valore_adx > differenziale_adx_long_basso and valore_adx < differenziale_adx_long_alto and valore_rsi < differenziale_rsi_long and not in_solo_short
- //condEntryLong_Provvissoria = close > media_long
- //condEntryShort_Provvisoria = close < media_short
- condEntryLong_Provvisoria = ta.crossover(close, media_long) and close > (media_long + apertura_minima_long) and media_tendenza_veloce_long > media_tendenza_lenta_long and valore_adx > differenziale_adx_basso_long and valore_adx < differenziale_adx_alto_long and valore_rsi < differenziale_rsi_long and not in_solo_short
- condEntryShort_Provvisoria = ta.crossunder(close, media_short) and close < (media_short - apertura_minima_short) and media_tendenza_lenta_short > media_tendenza_veloce_short and valore_adx > differenziale_adx_basso_short and valore_adx < differenziale_adx_alto_short and valore_rsi > differenziale_rsi_short and not in_solo_long
- var openlong = 0
- if condEntryLong_Provvisoria
- openlong += 1
- plot(openlong, title ='openlong')
- var openshort = 0
- if condEntryShort_Provvisoria
- openshort += 1
- plot(openshort, title ='openshort')
- condEntryLong = condEntryLong_Provvisoria and openlong == 1 and not in_solo_short and openshort == 0
- entryprice_long = ta.valuewhen(condEntryLong, close, 0)
- plotshape(condEntryLong)
- condEntryShort = condEntryShort_Provvisoria and openshort == 1 and not in_solo_long and openlong == 0
- entryprice_short = ta.valuewhen(condEntryShort, close, 0)
- plotshape(condEntryShort)
- var contaoperazionilong=0
- if condEntryLong
- contaoperazionilong +=1
- plot(contaoperazionilong, title = 'numero operazioni long')
- var indice_entry_bar_long = 0
- if condEntryLong[1]
- indice_entry_bar_long := bar_index
- lunghezza_trailing_long = bar_index - indice_entry_bar_long +1
- plot(lunghezza_trailing_long, title = 'lunghezza trailing long')
- varip highesthigh=0.0
- highesthigh := ta.highest(vhigh, lunghezza_trailing_long)
- /// USCITE STOP TARGET E TRAIL
- stop_loss_long_price =(entryprice_long - (entryprice_long * input_stop_loss_long) / 100)
- take_profit_long_price = (entryprice_long + (entryprice_long * input_target_long) / 100)
- trailing_stop_trigger_long1 = entryprice_long + (entryprice_long * input_target_long /100) * (input_trailing_stop_trigger_long1/100)
- trailing_stop_close_long1 = entryprice_long + (entryprice_long * input_target_long /100) * (input_trailing_stop_close_long1/100)
- trailing_stop_trigger_long2 = entryprice_long + (entryprice_long * input_target_long /100) * (input_trailing_stop_trigger_long2/100)
- trailing_stop_close_long2 = entryprice_long + (entryprice_long * input_target_long /100) * (input_trailing_stop_close_long2/100)
- //condExitLongStop = (openlong >=1 and ((vlow <= stop_loss_long_price and lunghezza_trailing != 2 ) or (vlow <= stop_loss_long_price and lunghezza_trailing == 2 and close<open)))
- condExitLongStop = (openlong[1] >=1 and (vlow <= stop_loss_long_price))
- condExitLongTarget = (openlong[1]>=1 and (vhigh >= take_profit_long_price))
- if condExitLongStop
- openlong:=0
- openshort:=0
- if condExitLongTarget
- openlong:=0
- openshort:=0
- condExitLongStopint = if condExitLongStop == true
- 1
- else
- 0
- plot(condExitLongStopint, title = 'cond uscita stop long')
- condExitLongTargetint = if condExitLongTarget == true
- 1
- else
- 0
- plot(condExitLongTargetint, title = 'cond uscita target long')
- // IsLongOpen := condEntryLong[1] ? true : condExitLong[1] ? false : IsLongOpen[1]
- // //plot(IsLongOpen ? highesthigh : na, title='highesthigh', style = plot.style_cross, linewidth = 1)
- // trailing_long1 = openlong[1] >=1 and ((highesthigh >= trailing_stop_trigger_long1) and ( vlow <= trailing_stop_close_long1) and not (vlow < trailing_stop_close_long1 and vhigh > trailing_stop_trigger_long1))
- // trailing_long2 = openlong[1] >=1 and ((highesthigh >= trailing_stop_trigger_long2) and ( vlow <= trailing_stop_close_long2) and not (vlow < trailing_stop_close_long2 and vhigh > trailing_stop_trigger_long2))
- trailing_long1 = (openlong[1] >=1 and ((highesthigh >= trailing_stop_trigger_long1 and highesthigh < trailing_stop_trigger_long2 ) and ( vlow <= trailing_stop_close_long1) and not (vlow < trailing_stop_close_long1 and vhigh == highesthigh and high[1] != highesthigh))) or (openlong[1] >=1 and (highesthigh == vhigh and highesthigh != high[1]) and ((highesthigh >= trailing_stop_trigger_long1 and highesthigh < trailing_stop_trigger_long2) and (price <= trailing_stop_close_long1)))
- trailing_long2 = (openlong[1] >=1 and ((highesthigh >= trailing_stop_trigger_long2 and highesthigh < take_profit_long_price) and ( vlow <= trailing_stop_close_long2) and not (vlow < trailing_stop_close_long2 and vhigh == highesthigh and high[1] != highesthigh))) or (openlong[1] >=1 and (highesthigh == vhigh and highesthigh != high[1]) and ((highesthigh >= trailing_stop_trigger_long2 and highesthigh < take_profit_long_price) and (price <= trailing_stop_close_long2)))
- if trailing_long1 or trailing_long2
- openlong:=0
- openshort:=0
- IsLongOpen = false
- IsLongOpen := condEntryLong[1] ? true : condExitLongStop[1] ? false : condExitLongTarget[1] ? false : trailing_long1[1] ? false : trailing_long2[1] ? false : IsLongOpen[1]
- IsLongOpenint = if IsLongOpen == true
- 1
- else
- 0
- plot(IsLongOpenint, title = 'islongopen')
- // Contatori
- varip contatraillong1 = 0
- if highesthigh >= trailing_stop_trigger_long1
- contatraillong1 += 1
- plot(contatraillong1, title = 'contatraillong1')
- varip contatraillong2 = 0
- if highesthigh >= trailing_stop_trigger_long2
- contatraillong2 += 1
- plot(contatraillong2, title = 'contatraillong2')
- plot(IsLongOpen ? entryprice_long : na , color = color.blue , style=plot.style_linebr, linewidth=2, title="Entry Price Long") // stampa l'entry price in rosso se short in blu se long
- plot(IsLongOpen ? stop_loss_long_price : na, color=color.red, style=plot.style_cross, linewidth=2, title="Stop Loss Long")
- plot(IsLongOpen ? take_profit_long_price : na, color=color.green, style=plot.style_cross, linewidth=2, title="Target Long")
- plot(IsLongOpen ? trailing_stop_trigger_long1 : na, color= color.blue , style=plot.style_cross, linewidth=2, title="Trigger1 Long")
- plot(IsLongOpen ? trailing_stop_close_long1 : na, color= color.blue , style=plot.style_cross, linewidth=2, title="Close 1 Long")
- plot(IsLongOpen ? trailing_stop_trigger_long2 : na, color= color.blue , style=plot.style_cross, linewidth=2, title="Trigger2 Long")
- plot(IsLongOpen ? trailing_stop_close_long2 : na, color= color.blue , style=plot.style_cross, linewidth=2, title="Close 2 Long")
- plot(IsLongOpen ? highesthigh : na, title='highesthigh', style = plot.style_cross, linewidth = 1)
- ////Alert//////
- // Esempio inserire ticker nel command
- // short = '{"pair":"'+ syminfo.basecurrency + syminfo.currency +'","unitsPercent":"10","unitsType" ETC... ETC... ETC...
- // Nei command sotto inseriamo il prezzo del trailing in tempo reale
- entry_command_long = '{"pair":"ETHUSDT","unitsPercent":90,"unitsType":"percentBalance","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isBuy":true,"isMarket":true,"stopLossPercent":"-1.3","stopLossType":"percent","leverage":"1","marginType":"ISOLATED","targets":[{"idx":1,"amount":"100","takeProfitPercent":"5"}],"targetType":"percent","targetAmountInPercent":true,"closeCurrentPosition":true,"preventPyramiding":true,"cancelAllOrders":true}' // Buy Long + Stop + Target TV-Hub
- //stop_limit_command_long = '{stop_limit_command_long' + str.tostring(price) + '}' // Solo Per Uscite Stop Limit Exchange Supportati
- exit_stop_market_command_long = '{"pair":"ETHUSDT","unitsPercent":90,"exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}'//'{exit_stop_market_command_long' + str.tostring(price) + '}' // Close Long TV-Hub
- exit_target_command_long = '{"pair":"ETHUSDT","unitsPercent":90,"exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}'//'{exit_target_command_long' + str.tostring(price) + '}' // Close Long TV-Hub
- trailing1_limit_command_long = '{"pair":"ETHUSDT","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isStopLoss":true,"stopLossSizeType":"currentPosition","stopLossPercent":"","stopLossType":"absolute","stopLoss":'+str.tostring(trailing_stop_close_long1)+',"isBuy":true}' // Buy Stop Loss Use Absolute Value TV-Hub
- trailing1_market_command_long = '{"pair":"ETHUSDT","unitsPercent":90,"exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}'//'{trailing1_market_command_long' + str.tostring(price) + '}' // Close Long TV-Hub
- trailing2_limit_command_long = '{"pair":"ETHUSDT","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isStopLoss":true,"stopLossSizeType":"currentPosition","stopLossPercent":"","stopLossType":"absolute","stopLoss":'+str.tostring(trailing_stop_close_long2)+',"isBuy":true}' // Buy Stop Loss Use Absolute Value TV-Hub
- trailing2_market_command_long = '{"pair":"ETHUSDT","unitsPercent":90,"exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}'//'{Trailing Long 2 market ' + str.tostring(price) + ' }' // Close Long TV-Hub
- // inseriamo ordine ingresso market con target limit senza stop stringa tvhub
- // Facciamo una sorta di screen del tempo reale che si aggiorna ad ogni tick appena entriamo in posizione e lo confrontiamo con i secondi normali dandogli una differenza in millesecondi aggiunti
- // prima di mandare altri ordini per non instasare gli ordini.
- if condEntryLong[1]
- alert(entry_command_long)
- // orario_barra := last_bar_time
- //if condEntryLong[1] and (secondi - orario_barra) > 10000 // 10 secondi di ritardo circa in "millisecondi"
- // alert(stop_limit_command_long) // reduce only {2nda schermata sell solo stop-loss} {Use SL size from current position}
- //plot(secondi - tempo_attuale, "title=sec-temp")
- //plot(tempo_attuale, title="temp_att")
- // usciamo a stop market se non siamo usciti stop limit stringa tvhub
- if condExitLongStop and IsLongOpen
- alert(exit_stop_market_command_long) // reduce only
- // usciamo a target market reduce only se non siamo usciti target limit stringa tvhub
- if condExitLongTarget and IsLongOpen
- alert(exit_target_command_long) // reduce only
- // piazzo un limit sul close long 1 stringa tvhub
- if openlong[1] >=1 and IsLongOpen and highesthigh >= trailing_stop_trigger_long1 and contatraillong1 == 1
- alert(trailing1_limit_command_long) // reduce only
- // mando un ordine market chiusura emergenza al tocco di close long 1 stringa tv hub
- if trailing_long1 and IsLongOpen
- alert(trailing1_market_command_long) //reduce only
- // piazzo un limit sul close long 2 stringa tvhub
- if openlong[1] >=1 and IsLongOpen and highesthigh >= trailing_stop_trigger_long2 and contatraillong2 == 1
- alert(trailing2_limit_command_long) // reduce only
- // mando un ordine market chiusura emergenza al tocco di close long 1 stringa tv hub
- if trailing_long2 and IsLongOpen
- alert(trailing2_market_command_long) //reduce only
- if IsLongOpen == false
- contatraillong1:=0
- contatraillong2:=0
- lunghezza_trailing_long:=0
- //contaalert:=0
- if IsLongOpen
- openshort:=0
- ///////////////////////////////////////////////////////SHORT////////////////////////////////////////////////////////////
- //condEntryShort = close < (media_short - apertura_minima_short) and valore_adx > differenziale_adx_short_basso and valore_adx < differenziale_adx_short_alto and valore_rsi > differenziale_rsi_short and not in_solo_long
- var contaoperazionishort=0
- if condEntryShort
- contaoperazionishort +=1
- plot(contaoperazionishort, title = 'numero operazioni short')
- plotshape(condEntryShort, color = color.red)
- var indice_entry_bar_short = 0
- if condEntryShort[1]
- indice_entry_bar_short := bar_index
- lunghezza_trailing_short = bar_index - indice_entry_bar_short +1
- plot(lunghezza_trailing_short, title = 'lunghezza trailing short')
- varip lowestlow=0.0
- lowestlow := ta.lowest(vlow, lunghezza_trailing_short)
- /// USCITE STOP TARGET E TRAIL
- stop_loss_short_price =(entryprice_short + (entryprice_short * input_stop_loss_short) / 100)
- take_profit_short_price = (entryprice_short - (entryprice_short * input_target_short) / 100)
- trailing_stop_trigger_short1 = entryprice_short - (entryprice_short * input_target_short /100) * (input_trailing_stop_trigger_short1/100)
- trailing_stop_close_short1 = entryprice_short - (entryprice_short * input_target_short /100) * (input_trailing_stop_close_short1/100)
- trailing_stop_trigger_short2 = entryprice_short - (entryprice_short * input_target_short /100) * (input_trailing_stop_trigger_short2/100)
- trailing_stop_close_short2 = entryprice_short - (entryprice_short * input_target_short /100) * (input_trailing_stop_close_short2/100)
- //condExitLongStop = (openlong >=1 and ((vlow <= stop_loss_long_price and lunghezza_trailing != 2 ) or (vlow <= stop_loss_long_price and lunghezza_trailing == 2 and close<open)))
- condExitShortStop = (openshort[1] >=1 and (vhigh >= stop_loss_short_price))
- condExitShortTarget = (openshort[1]>=1 and (vlow <= take_profit_short_price))
- if condExitShortStop
- openshort:=0
- openlong:=0
- if condExitShortTarget
- openshort:=0
- openlong:=0
- condExitShortStopint = if condExitShortStop == true
- 1
- else
- 0
- plot(condExitShortStopint, title = 'cond uscita stop short')
- condExitShortTargetint = if condExitShortTarget == true
- 1
- else
- 0
- plot(condExitShortTargetint, title = 'cond uscita target short')
- trailing_short1 = (openshort[1] >=1 and ((lowestlow <= trailing_stop_trigger_short1 and lowestlow > trailing_stop_trigger_short2 ) and ( vhigh >= trailing_stop_close_short1) and not (vhigh > trailing_stop_close_short1 and vlow == lowestlow and low[1] != lowestlow))) or (openshort[1] >=1 and (lowestlow == vlow and lowestlow != low[1]) and ((lowestlow <= trailing_stop_trigger_short1 and lowestlow > trailing_stop_trigger_short2) and (price >= trailing_stop_close_short1)))
- trailing_short2 = (openshort[1] >=1 and ((lowestlow <= trailing_stop_trigger_short2 and lowestlow > take_profit_short_price ) and ( vhigh >= trailing_stop_close_short2) and not (vhigh > trailing_stop_close_short2 and vlow == lowestlow and low[1] != lowestlow))) or (openshort[1] >=1 and (lowestlow == vlow and lowestlow != low[1]) and ((lowestlow <= trailing_stop_trigger_short2 and lowestlow > take_profit_short_price) and (price >= trailing_stop_close_short2)))
- if trailing_short1 or trailing_short2
- openshort:=0
- openlong:=0
- IsShortOpen = false
- IsShortOpen := condEntryShort[1] ? true : condExitShortStop[1] ? false : condExitShortTarget[1] ? false : trailing_short1[1] ? false : trailing_short2[1] ? false : IsShortOpen[1]
- IsShortOpenint = if IsShortOpen == true
- 1
- else
- 0
- plot(IsShortOpenint, title = 'isshortopen')
- // Contatori
- varip contatrailshort1 = 0
- if lowestlow <= trailing_stop_trigger_short1
- contatrailshort1 += 1
- plot(contatrailshort1, title = 'contatrailshort1')
- varip contatrailshort2 = 0
- if lowestlow >= trailing_stop_trigger_short2
- contatrailshort2 += 1
- plot(contatrailshort2, title = 'contatrailshort2')
- plot(IsShortOpen ? entryprice_short : na , color = color.red , style=plot.style_linebr, linewidth=2, title="Entry Price Short") // stampa l'entry price in rosso se short in blu se long
- plot(IsShortOpen ? stop_loss_short_price : na, color=color.red, style=plot.style_cross, linewidth=2, title="Stop Loss Short ")
- plot(IsShortOpen ? take_profit_short_price : na, color=color.green, style=plot.style_cross, linewidth=2, title="Target Short")
- plot(IsShortOpen ? trailing_stop_trigger_short1 : na, color= color.red , style=plot.style_cross, linewidth=2, title="Trigger1 Short")
- plot(IsShortOpen ? trailing_stop_close_short1 : na, color= color.red , style=plot.style_cross, linewidth=2, title="Close1 Short")
- plot(IsShortOpen ? trailing_stop_trigger_short2 : na, color= color.red , style=plot.style_cross, linewidth=2, title="Trigger2 Short")
- plot(IsShortOpen ? trailing_stop_close_short2 : na, color= color.red , style=plot.style_cross, linewidth=2, title="Close1 Short")
- plot(IsShortOpen ? lowestlow : na, title='lowestlow', style = plot.style_cross, color= color.red, linewidth = 1)
- ////Alert//////
- entry_command_short = '{"pair":"ETHUSDT","unitsPercent":"90","unitsType":"percentBalance","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isSell":true,"isMarket":true,"stopLossPercent":"-1.1","stopLossType":"absolute","stopLoss":"1845.07","leverage":"1","marginType":"ISOLATED","targets":[{"idx":1,"amount":"100","takeProfitPercent":"10"}],"targetType":"percent","targetAmountInPercent":true,"closeCurrentPosition":true,"preventPyramiding":true,"cancelAllOrders":true}' // Sell Short + Stop + Target TV-Hub
- //stop_limit_command_short = '{stop_limit_command_short'+ str.tostring(price) + '}' // Solo Per Uscite Stop Limit Exchange Supportati
- exit_stop_market_command_short = '{"pair":"ETHUSDT","unitsPercent":"90","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}' // Close Short TV-Hub
- exit_target_command_short = '{"pair":"ETHUSDT","unitsPercent":"90","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}' // Close Short TV-Hub
- trailing1_limit_command_short= '{"pair":"ETHUSDT","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isStopLoss":true,"stopLossSizeType":"currentPosition","stopLossPercent":"","stopLossType":"absolute","stopLoss":'+str.tostring(trailing_stop_close_short1)+',"isSell":true}' // Sell Stop Loss Use Absolute Value TV-Hub
- trailing1_market_command_short = '{"pair":"ETHUSDT","unitsPercent":"90","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}' // Close Short TV-Hub
- trailing2_limit_command_short = '{"pair":"ETHUSDT","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isStopLoss":true,"stopLossSizeType":"currentPosition","stopLossPercent":"","stopLossType":"absolute","stopLoss":'+str.tostring(trailing_stop_close_short2)+',"isSell":true}' // Sell Stop Loss Use Absolute Value TV-Hub
- trailing2_market_command_short = '{"pair":"ETHUSDT","unitsPercent":"90","exchange":"Bybit","apiKey":"Main Account","broadcastSignal":"061e29d2-b9e8-47b6-8c69-9cbd95e55550","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true}' // Close Short TV-Hub
- // entry_command_short = '{}' //'{entry_command_short' + str.tostring(price) + '}'
- // stop_limit_command_short = '{stop_limit_command_short'+ str.tostring(price) + '}'
- // exit_stop_market_command_short = '{exit_stop_market_command_short' + str.tostring(price) + '}'
- // exit_target_command_short = '{exit_target_command_short' + str.tostring(price) + '}'
- // trailing1_limit_command_short= '{trailing1_limit_command_short' + str.tostring(price) + '}'
- // trailing1_market_command_short = '{trailing1_market_command_short' + str.tostring(price) + '}'
- // trailing2_limit_command_short = '{trailing2_limit_command_short' + str.tostring(price) + '}'
- // trailing2_market_command_short = '{trailing2_market_command_short' + str.tostring(price) + '}'
- // inseriamo ordine ingresso market con target limit senza stop stringa tvhub
- if condEntryShort[1]
- alert(entry_command_short)
- // orario_barra := last_bar_time
- //if condEntryShort[1] and (secondi - orario_barra) > 10000 // 10 secondi di ritardo circa in "millisecondi"
- // alert(stop_limit_command_short) // reduce only {2nda schermata sell solo stop-loos} {Use SL size from current position}
- //plot(secondi - tempo_attuale, "title=sec-temp")
- //plot(tempo_attuale, title="temp_att")
- // usciamo a stop market se non siamo usciti stop limit stringa tvhub
- if condExitShortStop and IsShortOpen
- alert(exit_stop_market_command_short) // reduce only
- // usciamo a target market reduce only se non siamo usciti target limit stringa tvhub
- if condExitShortTarget and IsShortOpen
- alert(exit_target_command_short) // reduce only
- // piazzo un limit sul close long 1 stringa tvhub
- if openshort[1] >=1 and IsShortOpen and lowestlow <= trailing_stop_trigger_short1 and contatrailshort1 == 1
- alert(trailing1_limit_command_short) // reduce only
- // mando un ordine market chiusura emergenza al tocco di close long 1 stringa tv hub
- if trailing_short1 and IsShortOpen
- alert(trailing1_market_command_short) //reduce only
- // piazzo un limit sul close long 2 stringa tvhub
- if openshort[1] >=1 and IsShortOpen and lowestlow <= trailing_stop_trigger_short2 and contatrailshort2 == 1
- alert(trailing2_limit_command_short) // reduce only
- // mando un ordine market chiusura emergenza al tocco di close long 1 stringa tv hub
- if trailing_short2 and IsShortOpen
- alert(trailing2_market_command_short) //reduce only
- if IsShortOpen == false
- contatrailshort1:=0
- contatrailshort2:=0
- lunghezza_trailing_short:=0
- if IsShortOpen
- openlong:=0
- //contaalert:=0
- ///////////////////////////////////////////////CONTROLLO ERROTI////////////////////////////////////////////////
- errore = (vlow < trailing_stop_close_long1 and vhigh > trailing_stop_trigger_long1) or (vlow < trailing_stop_close_long2 and vhigh > trailing_stop_trigger_long2)
- //plotshape(errore, color= color.red , size = size.large)
- var contaerrori = 0
- if errore
- contaerrori +=1
- plot(contaerrori, title = 'conta errori')
- // Nome Alert: Study Scalping Exponential Tick 5M
- // URl Webhook: https://alerts.tv-hub.org/api/ExecuteTradeSignalClassic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement