Advertisement
Maurizio-Ciullo

35 Lezione Personale Attivare Un Trigger Orer Touched

Nov 3rd, 2022 (edited)
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --------------------------------------------*(35 Lezione Personale Attivare Un Trigger Orer Touched)*-------------------------------------------------
  2.  
  3. QUESTO PEZZO DI CODICE SERVE A IMPOSTARE DEI LIVELLI DA INPUT E VERIFICARE SE L'HIGHEST O IL LOWEST PER TUTTA LA NOSTRA POSIZIONE HA OLTREPASSATO QUEL LIVELLO.
  4. E' MOLTO UTILE NEL CASO AVESSIMO ORDINI PENDENTI PER VERIFICARE SE POI SUCCESSIVAMENTE CANCELLARE UN ORDINE O PER QUALSIASI ALTRA AZIONE.
  5.  
  6. ES: SICCOME NON SAPPIAMO MAI SE VERREMO ESEGUITI SUL NOSTRO EXCHANGE DOPO AVER IMMESSO UN INGRESSO LIMIT, CON QUESTO CODICE POSSIAMO ALMENO
  7. SAPERE SE "DATO UN MARGINE DI SPREAD DA INPUT" QUEL MARGINE E' STATO RAGGIUNTO E ANCHE SE NON ABBIAMO MAI LA CERTEZZA E' COMUNQUE UN UTILE AIUTO
  8.  
  9. ES: INGRESSO LIMIT LONG 5,46 / LIVELLI IMPOSTATO A 5.40 / SE IL LOWEST LOW NELLE CANDELE CHE COMPRENDE TUTTO IL MIO TRADE E' PIU' BASSO
  10. O UGUALE AL MIO LIVELLO, SARA' PIU' PROBABILE CHE IL MIO ORDINE SIA STATO FILLATO E POTREI PRENDERE DELLE DECISIONI AD ESEMPIO DI NON CANCELLARE
  11. PIU' GLI ORDINI PENDENTI.
  12.  
  13. ALTRO MODO DI UTILIZZO PER VERIFICARE SE IL TAKE PROFIT O STOP LOSS E' STATO TOCCATO FACENDO POI CANCELLARE GLI ORDINI PENDENTI
  14.  
  15. //------------------------------------ Inizio Codice se voglio attivare un trigger ored touched ------------------------------------//
  16.  
  17.  
  18. //@version=5
  19. strategy(title="Study Test Alert/Ingre Limit/Canc Ord Pend", overlay=true, precision = 4, ETC...
  20.  
  21.  
  22.  
  23. // Variabili Trigger Fill Or Cancel Long
  24. input_trigger_fill_or_cancel_long = input.float(title='trigger_fill_or_cancel_long', defval=0.02, minval=0, maxval=100, step=0.01, group='Trigger Fill Or Cancel')
  25. input_trigger_fill_or_cancel_short = input.float(title='trigger_fill_or_cancel_short', defval=0.02, minval=0, maxval=100, step=0.01, group='Trigger Fill Or Cancel')
  26.  
  27. trigger_fill_or_cancel_long = (strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_trigger_fill_or_cancel_long) / 100)
  28. //plot(trigger_fill_or_cancel_long, title="fill_or_canc_l", color=color.yellow)
  29.  
  30. // take_profit_long_price = (strategy.opentrades.entry_price(0) + ((strategy.opentrades.entry_price(0) * input_take_profit_long) / 100))
  31.  
  32. // Variabili Trigger Fill Or Cancel Long
  33. trigger_fill_or_cancel_short = (strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_trigger_fill_or_cancel_short) / 100)
  34. plot(trigger_fill_or_cancel_short, title="fill_or_canc_s", color=color.yellow)
  35.  
  36. // take_profit_short_price = (strategy.opentrades.entry_price(0) - ((strategy.opentrades.entry_price(0) * input_take_profit_short) / 100))
  37.  
  38.  
  39.  
  40.  
  41. range_barre_trailing = bar_index - strategy.opentrades.entry_bar_index(0) +1
  42. plot(range_barre_trailing, title = 'lunghezza')
  43.  
  44. highesthigh = strategy.opentrades ==1 ? ta.highest(high, range_barre_trailing): na
  45. plot(highesthigh, title="hh",  color=color.rgb(238, 68, 187))
  46.  
  47. lowestlow = strategy.opentrades ==1 ? ta.lowest(low, range_barre_trailing): na
  48. //plot(lowestlow, title="ll", color=color.rgb(68, 238, 68))
  49.  
  50.  
  51.  
  52.  
  53. pending_cancelled_l = 0
  54. if trigger_fill_or_cancel_long <= lowestlow
  55.     pending_cancelled_l := 1
  56. else
  57.     pending_cancelled_l := 0
  58. plot(pending_cancelled_l, title="pen_canc_l")
  59.  
  60. pending_cancelled_s = 0
  61. if trigger_fill_or_cancel_short >= highesthigh
  62.     pending_cancelled_s := 1
  63. else
  64.     pending_cancelled_s := 0
  65. plot(pending_cancelled_s, title="pen_canc_s")
  66.  
  67.  
  68.  
  69.  
  70. // // Cancel the pending take profit and stop loss orders left once they are hit QUESTO FUNZIONA MA VA TESTATO
  71. // // var int hit_tk = 0
  72. // var int hit_tk_sl = 0
  73.  
  74. // if high >= take_profit_long or low <= stop_loss_long or low <= take_profit_short or high >=  stop_loss_short
  75. //     hit_tk_sl := 0
  76. // else
  77. //     hit_tk_sl := 1
  78. // //plot(hit_tk_sl)
  79.  
  80.  ... IF pending_cancelled_l == 1
  81. //       strategy.cancel("operazioneLong") // when = CancelLong
  82. //      alert(message='{"pair":"LEO-PERP","unitsPercent":"6","exchange":"Ftx","apiKey":"FTX","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isLimit":true,"price":4.2992,"limitPriceType":"bestPrice","stopLossPercent":"-12","stopLossType":"percent","leverage":1,"marginType":"ISOLATED","targets":[{"idx":1,"amount":"100","takeProfitPercent":"9"}],"targetType":"percent","targetAmountInPercent":true,"closeCurrentPosition":true,"preventPyramiding":true,"cancelAll":true}', freq=alert.freq_once_per_bar_close)
  83. // plotshape(... == ..., title="pending_tk_stop_l")
  84.  
  85.  
  86. //------------------------------------ Fine Codice se voglio attivare un trigger ored touched ------------------------------------//
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement