Maurizio-Ciullo

Indicatore Breakeven Buffer Percent Azion

Apr 2nd, 2026
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.                                                         // ============================================================
  4.                                                         // *** INDICATORE BREAKEVEN BUFFER PERCENTUALE AZIONARIO 1440 MIN  *** //
  5.                                                         // ============================================================
  6.  
  7.  
  8. // ============================================================
  9. // ATTENZIONE: TRAILING E BREAK-EVEN
  10. // ============================================================
  11. // Questo blocco di codice è progettato **per una sola posizione aperta per ticker**.
  12. // Se mai dovessi aprire più ingressi sullo stesso ticker (scale-in o multi-entry),
  13. // le variabili MaxPriceDuringTrade e StopPlaced verrebbero condivise tra tutte le posizioni,
  14. // causando stop confusi e break-even non corretti.
  15. // Per sicurezza: aprire **una sola posizione per ticker alla volta**.
  16.  
  17. // Aggiornamento MaxPriceDuringTrade a chiusura barra !!!.
  18.  
  19. // ATTENZIONE: Testato solo SU BARRE 1440 Min
  20. // ============================================================
  21.  
  22. Inputs:
  23.     Qty(100);  // numero di azioni da comprare
  24.  
  25. // VARIABILI ENTRY
  26. Vars:
  27.     DummyVar(0);
  28.  
  29. // ============================================================
  30. // ENTRY LONG
  31. // ============================================================
  32.  
  33. If MarketPosition = 0 Then Begin
  34.     // Compra sempre la quantità definita al mercato
  35.     Buy Qty shares next bar at Market;
  36. End;
  37.  
  38. // ============================================================================
  39. // EXIT LONG  
  40. // ============================================================================
  41. // ============================================================
  42. // BREAKEVEN + BUFFER LONG CON STOP DINAMICO %
  43. // ============================================================
  44.  
  45. Inputs:
  46.     TrailingActive(True),
  47.     InpBreakEvenPercent(50),    // 50 = 0.5%
  48.     InpMaxProfitPercent(300);   // 300 = 3%
  49.  
  50. Vars:
  51.     IntraBarPersist MaxPriceDuringTrade(0),  // Massimo intratrade
  52.     IntraBarPersist StopPlaced(False);
  53. // ============================================================
  54. // LOGICA TRADE LONG
  55. // ============================================================
  56. If TrailingActive and MarketPosition = 1 Then Begin
  57.  
  58.     // Registrazione prezzo ingresso
  59.     If MaxPriceDuringTrade = 0 Then
  60.         MaxPriceDuringTrade = EntryPrice;
  61.  
  62.     // Aggiorna massimo intratrade
  63.     MaxPriceDuringTrade = MaxList(MaxPriceDuringTrade, High);
  64.  
  65.     // Se supero la soglia profitto
  66.     If ((MaxPriceDuringTrade - EntryPrice) / EntryPrice * 10000) >= InpMaxProfitPercent Then Begin
  67.  
  68.         // Calcolo livello stop
  69.         Vars: StopPrice(0);
  70.         StopPrice = EntryPrice * (1 + InpBreakEvenPercent / 10000);
  71.  
  72.         // Set stop intrabar sulla posizione intera
  73.         SetStopPosition;
  74.         Sell ("BEPlusStopLong") next bar at StopPrice stop;
  75.         StopPlaced = True;
  76.     End;
  77.  
  78. End;
  79.  
  80. // ============================================================
  81. // RESET VARIABILI ALLA CHIUSURA
  82. // ============================================================
  83. If MarketPosition = 0 Then Begin
  84.     MaxPriceDuringTrade = 0;
  85.     StopPlaced = False;
  86. End;
Advertisement
Add Comment
Please, Sign In to add comment