Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ============================================================
- // *** INDICATORE BREAKEVEN BUFFER PERCENTUALE AZIONARIO 1440 MIN *** //
- // ============================================================
- // ============================================================
- // ATTENZIONE: TRAILING E BREAK-EVEN
- // ============================================================
- // Questo blocco di codice è progettato **per una sola posizione aperta per ticker**.
- // Se mai dovessi aprire più ingressi sullo stesso ticker (scale-in o multi-entry),
- // le variabili MaxPriceDuringTrade e StopPlaced verrebbero condivise tra tutte le posizioni,
- // causando stop confusi e break-even non corretti.
- // Per sicurezza: aprire **una sola posizione per ticker alla volta**.
- // Aggiornamento MaxPriceDuringTrade a chiusura barra !!!.
- // ATTENZIONE: Testato solo SU BARRE 1440 Min
- // ============================================================
- Inputs:
- Qty(100); // numero di azioni da comprare
- // VARIABILI ENTRY
- Vars:
- DummyVar(0);
- // ============================================================
- // ENTRY LONG
- // ============================================================
- If MarketPosition = 0 Then Begin
- // Compra sempre la quantità definita al mercato
- Buy Qty shares next bar at Market;
- End;
- // ============================================================================
- // EXIT LONG
- // ============================================================================
- // ============================================================
- // BREAKEVEN + BUFFER LONG CON STOP DINAMICO %
- // ============================================================
- Inputs:
- TrailingActive(True),
- InpBreakEvenPercent(50), // 50 = 0.5%
- InpMaxProfitPercent(300); // 300 = 3%
- Vars:
- IntraBarPersist MaxPriceDuringTrade(0), // Massimo intratrade
- IntraBarPersist StopPlaced(False);
- // ============================================================
- // LOGICA TRADE LONG
- // ============================================================
- If TrailingActive and MarketPosition = 1 Then Begin
- // Registrazione prezzo ingresso
- If MaxPriceDuringTrade = 0 Then
- MaxPriceDuringTrade = EntryPrice;
- // Aggiorna massimo intratrade
- MaxPriceDuringTrade = MaxList(MaxPriceDuringTrade, High);
- // Se supero la soglia profitto
- If ((MaxPriceDuringTrade - EntryPrice) / EntryPrice * 10000) >= InpMaxProfitPercent Then Begin
- // Calcolo livello stop
- Vars: StopPrice(0);
- StopPrice = EntryPrice * (1 + InpBreakEvenPercent / 10000);
- // Set stop intrabar sulla posizione intera
- SetStopPosition;
- Sell ("BEPlusStopLong") next bar at StopPrice stop;
- StopPlaced = True;
- End;
- End;
- // ============================================================
- // RESET VARIABILI ALLA CHIUSURA
- // ============================================================
- If MarketPosition = 0 Then Begin
- MaxPriceDuringTrade = 0;
- StopPlaced = False;
- End;
Advertisement
Add Comment
Please, Sign In to add comment