Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Indicatore Break Even Con Buffer //
- // * Quando in posizione, ad un certo prezzo di guadagno si innesca il break even con un buffer sopra entry price, il tutto ottimizzabile da input * //
- // ==========================================================================================================================================================================================//
- // ESEMPIO STRATEGIA SOLO LONG CON BREAKEVEN + BUFFER
- // ==========================================================================================================================================================================================//
- // ==========================================================================================================================================================================================//
- // INPUT E VARS BREAK EVEN CON BUFFER LONG
- // ==========================================================================================================================================================================================//
- Inputs:
- BPV(50), // Big Point Value Dello Strumento. Es: Soia @S 50$. Per Crypto 1$
- breakEvenPriceLong(1000), // Movimento In $ Per Innesco
- profitBufferLong(800); // Buffer Chiusura Posizione Sopra EntryPrice
- Vars:
- bufferPointsLong(0),
- MaxPriceDuringTrade(0);
- // Conversione in punti
- Once bufferPointsLong = profitBufferLong / BPV;
- // ==========================================================================================================================================================================================//
- // INIZIO INCOLLA LA TUA STRATEGIA
- // ==========================================================================================================================================================================================//
- // Apertura long
- If DayOfMonth(Date) = 1 and MarketPosition = 0 Then
- Buy ("LongStart") next bar at market;
- // Chiusura forzata
- If MarketPosition = 1 and DayOfMonth(Date) = 7 Then
- Sell ("LongExit") next bar at market;
- // ==========================================================================================================================================================================================//
- // FINE INCOLLA LA TUA STRATEGIA
- // ==========================================================================================================================================================================================//
- // BREAKEVEN + BUFFER
- If MarketPosition = 1 and DayOfMonth(Date) <> 7 Then Begin
- If BarsSinceEntry = 0 Then
- MaxPriceDuringTrade = EntryPrice;
- If High > MaxPriceDuringTrade Then
- MaxPriceDuringTrade = High;
- If (MaxPriceDuringTrade - EntryPrice) * BPV >= breakEvenPriceLong Then
- Sell ("BEPlusStopLong") next bar
- at EntryPrice + bufferPointsLong stop;
- End;
- // Reset
- If MarketPosition = 0 Then
- MaxPriceDuringTrade = 0;
- // ==========================================================================================================================================================================================//
- // ESEMPIO STRATEGIA SOLO SHORT CON BREAKEVEN + BUFFER
- // ==========================================================================================================================================================================================//
- // ==========================================================================================================================================================================================//
- // INPUT E VARS BREAK EVEN CON BUFFER SHORT
- // ==========================================================================================================================================================================================//
- {Inputs:
- BPV(50), // Big Point Value dello strumento (es: Soia @S = 50$, Crypto = 1$)
- breakEvenPriceShort(1000), // Movimento in $ per innesco BE
- profitBufferShort(800); // Buffer chiusura posizione sotto EntryPrice
- Vars:
- bufferPointsShort(0),
- MinPriceDuringTrade(0);
- // Conversione in punti
- Once bufferPointsShort = profitBufferShort / BPV;
- // ==========================================================================================================================================================================================//
- // INIZIO INCOLLA LA TUA STRATEGIA
- // ==========================================================================================================================================================================================//
- // Apertura posizione short il 1° giorno del mese
- If DayOfMonth(Date) = 1 and MarketPosition = 0 Then
- SellShort ("ShortStart") next bar at market;
- // Chiusura short il 7 del mese
- If MarketPosition = -1 and DayOfMonth(Date) = 7 Then
- BuyToCover ("ShortExit") next bar at market;
- // ==========================================================================================================================================================================================//
- // FINE INCOLLA LA TUA STRATEGIA
- // ==========================================================================================================================================================================================//
- // ============================================================
- // BREAKEVEN + BUFFER SHORT
- // ============================================================
- If MarketPosition = -1 and DayOfMonth(Date) <> 7 Then Begin
- // Inizio trade: registra minimo intratrade
- If BarsSinceEntry = 0 Then
- MinPriceDuringTrade = EntryPrice;
- // Aggiorna minimo intratrade
- If Low < MinPriceDuringTrade Then
- MinPriceDuringTrade = Low;
- // Attiva breakeven + buffer se profitto raggiunto
- If (EntryPrice - MinPriceDuringTrade) * BPV >= breakEvenPriceShort Then
- BuyToCover ("BEPlusStopShort") next bar
- at EntryPrice - bufferPointsShort stop;
- End;
- // ============================================================
- // RESET VARIABILI ALLA CHIUSURA DEL TRADE
- // ============================================================
- If MarketPosition = 0 Then
- MinPriceDuringTrade = 0; }
Advertisement
Add Comment
Please, Sign In to add comment