Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Indicatore Run-Up Drawdown //
- // Esempio Futures @S Soia Long E Short //
- // ==========================================================================================================================================================================================//
- // ESEMPIO STRATEGIA SOLO LONG
- // ==========================================================================================================================================================================================//
- // Apertura posizione long il 1° giorno del mese
- if DayOfMonth(Date) = 1 and MarketPosition = 0 then
- buy ("LongStart") next bar at market;
- // Chiusura long il 7 del mese
- if MarketPosition = 1 and DayOfMonth(Date) = 7 then
- sell ("LongExit") next bar at market;
- // ==========================================================================================================================================================================================//
- // SOLO LONG
- // ==========================================================================================================================================================================================//
- // BLOCCO DRAWNDOWN INTEGRATO SOLO LONG "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
- // ==========================================================================================================================================================================================//
- // Moltiplicatore contratto @S (1 punto = 50$)
- Vars: ContractMultiplier(50); // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
- // Variabili drawdown
- Vars: MyEntryPrice(0), MinPriceDuringTrade(0), MinPriceDate(0), MinPriceTime(0),
- TradeEntryDate(0), TradeEntryTime(0), TradeExitDate(0), TradeExitTime(0), TradeExitPrice(0),
- DrawdownPerc(0), DrawdownDollar(0), SumDrawdownPerc(0), SumDrawdownDollar(0), NumTrades(0);
- // ===============================
- // REGISTRAZIONE PREZZO D'ENTRATA E MINIMO DURANTE IL TRADE
- // ===============================
- if MarketPosition = 1 and MyEntryPrice = 0 then begin
- MyEntryPrice = EntryPrice(0);
- MinPriceDuringTrade = MyEntryPrice;
- MinPriceDate = Date;
- MinPriceTime = Time;
- TradeEntryDate = Date;
- TradeEntryTime = Time;
- end;
- // Aggiorna minimo intratrade
- if MarketPosition = 1 then begin
- if Low < MinPriceDuringTrade then begin
- MinPriceDuringTrade = Low;
- MinPriceDate = Date;
- MinPriceTime = Time;
- end;
- end;
- // ===============================
- // CALCOLO DRAWDOWN ALLA CHIUSURA DEL TRADE O FINE BAR
- // ===============================
- if (MarketPosition(1) = 1 and MarketPosition = 0) or
- (LastBarOnChart and MarketPosition = 1) then
- begin
- if MarketPosition = 0 then
- TradeExitPrice = ExitPrice(1)
- else
- TradeExitPrice = Close;
- TradeExitDate = Date;
- TradeExitTime = Time;
- if MyEntryPrice > 0 then begin
- // Drawdown %
- DrawdownPerc = ((MinPriceDuringTrade - MyEntryPrice) / MyEntryPrice) * 100;
- // Drawdown in $ per contratto
- DrawdownDollar = (MinPriceDuringTrade - MyEntryPrice) * ContractMultiplier;
- // accumula somme per media
- SumDrawdownPerc = SumDrawdownPerc + DrawdownPerc;
- SumDrawdownDollar = SumDrawdownDollar + DrawdownDollar;
- NumTrades = NumTrades + 1;
- // stampa dettagli del trade
- Print("Trade ", NumTrades,
- " | Entry Price: ", MyEntryPrice:0:2,
- " | Entry Date: ", TradeEntryDate,
- " | Entry Time: ", TradeEntryTime,
- " | Exit Price: ", TradeExitPrice:0:2,
- " | Exit Date: ", TradeExitDate,
- " | Exit Time: ", TradeExitTime,
- " | Min Price: ", MinPriceDuringTrade:0:2,
- " | Min Date: ", MinPriceDate,
- " | Min Time: ", MinPriceTime,
- " | Drawdown %: ", DrawdownPerc:5:2,
- " | Drawdown $: ", DrawdownDollar:0:2);
- end;
- // reset variabili drawdown per prossimo trade
- MyEntryPrice = 0;
- MinPriceDuringTrade = 0;
- MinPriceDate = 0;
- MinPriceTime = 0;
- TradeEntryDate = 0;
- TradeEntryTime = 0;
- TradeExitDate = 0;
- TradeExitTime = 0;
- TradeExitPrice = 0;
- end;
- // ===============================
- // STAMPA MEDIA FINALE
- // ===============================
- if LastBarOnChart then
- begin
- if NumTrades > 0 then
- Print("Media Drawdown % = ", (SumDrawdownPerc / NumTrades):5:2,
- " | Media Drawdown $ = ", (SumDrawdownDollar / NumTrades):0:2)
- else
- Print("Nessun trade eseguito.");
- end;
- // ==========================================================================================================================================================================================//
- // SOLO LONG
- // ==========================================================================================================================================================================================//
- // BLOCCO RUN-UP INTEGRATO SOLO LONG "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
- // ==========================================================================================================================================================================================//
- // Moltiplicatore contratto @S (1 punto = 50$)
- {Vars: ContractMultiplier(50); // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
- // Variabili run-up
- Vars: MyEntryPrice(0), MaxPriceDuringTrade(0), MaxPriceDate(0), MaxPriceTime(0),
- TradeEntryDate(0), TradeEntryTime(0), TradeExitDate(0), TradeExitTime(0), TradeExitPrice(0),
- RunupPerc(0), RunupDollar(0), SumRunupPerc(0), SumRunupDollar(0), NumTrades(0);
- // ===============================
- // REGISTRAZIONE PREZZO D'ENTRATA E MASSIMO DURANTE IL TRADE
- // ===============================
- if MarketPosition = 1 and MyEntryPrice = 0 then begin
- MyEntryPrice = EntryPrice(0);
- MaxPriceDuringTrade = MyEntryPrice;
- MaxPriceDate = Date;
- MaxPriceTime = Time;
- TradeEntryDate = Date;
- TradeEntryTime = Time;
- end;
- // Aggiorna massimo intratrade
- if MarketPosition = 1 then begin
- if High > MaxPriceDuringTrade then begin
- MaxPriceDuringTrade = High;
- MaxPriceDate = Date;
- MaxPriceTime = Time;
- end;
- end;
- // ===============================
- // CALCOLO RUN-UP ALLA CHIUSURA DEL TRADE O FINE BAR
- // ===============================
- if (MarketPosition(1) = 1 and MarketPosition = 0) or
- (LastBarOnChart and MarketPosition = 1) then
- begin
- if MarketPosition = 0 then
- TradeExitPrice = ExitPrice(1)
- else
- TradeExitPrice = Close;
- TradeExitDate = Date;
- TradeExitTime = Time;
- if MyEntryPrice > 0 then begin
- // Run-Up %
- RunupPerc = ((MaxPriceDuringTrade - MyEntryPrice) / MyEntryPrice) * 100;
- // Run-Up in $ per contratto
- RunupDollar = (MaxPriceDuringTrade - MyEntryPrice) * ContractMultiplier;
- // accumula somme per media
- SumRunupPerc = SumRunupPerc + RunupPerc;
- SumRunupDollar = SumRunupDollar + RunupDollar;
- NumTrades = NumTrades + 1;
- // stampa dettagli del trade
- Print("Trade ", NumTrades,
- " | Entry Price: ", MyEntryPrice:0:2,
- " | Entry Date: ", TradeEntryDate,
- " | Entry Time: ", TradeEntryTime,
- " | Exit Price: ", TradeExitPrice:0:2,
- " | Exit Date: ", TradeExitDate,
- " | Exit Time: ", TradeExitTime,
- " | Max Price: ", MaxPriceDuringTrade:0:2,
- " | Max Date: ", MaxPriceDate,
- " | Max Time: ", MaxPriceTime,
- " | Run-up %: ", RunupPerc:5:2,
- " | Run-up $: ", RunupDollar:0:2);
- end;
- // reset variabili run-up per prossimo trade
- MyEntryPrice = 0;
- MaxPriceDuringTrade = 0;
- MaxPriceDate = 0;
- MaxPriceTime = 0;
- TradeEntryDate = 0;
- TradeEntryTime = 0;
- TradeExitDate = 0;
- TradeExitTime = 0;
- TradeExitPrice = 0;
- end;
- // ===============================
- // STAMPA MEDIA FINALE
- // ===============================
- if LastBarOnChart then
- begin
- if NumTrades > 0 then
- Print("Media Run-up % = ", (SumRunupPerc / NumTrades):5:2,
- " | Media Run-up $ = ", (SumRunupDollar / NumTrades):0:2)
- else
- Print("Nessun trade eseguito.");
- end; }
- // ==========================================================================================================================================================================================//
- // ESEMPIO STRATEGIA SOLO SHORT
- // ==========================================================================================================================================================================================//
- // 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;
- // ==========================================================================================================================================================================================//
- // SOLO SHORT
- // ==========================================================================================================================================================================================//
- // ==========================================================================================================================================================================================//
- // BLOCCO DRAWNDOWN INTEGRATO SOLO SHORT "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
- // ==========================================================================================================================================================================================//
- // Moltiplicatore contratto @S (1 punto = 50$)
- {Vars: ContractMultiplier(50); // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
- // Variabili drawdown Short
- Vars: MyEntryPriceS(0), MaxPriceDuringTrade(0), MaxPriceDate(0), MaxPriceTime(0),
- TradeEntryDateS(0), TradeEntryTimeS(0), TradeExitDateS(0), TradeExitTimeS(0), TradeExitPriceS(0),
- DrawdownPercS(0), DrawdownDollarS(0), SumDrawdownPercS(0), SumDrawdownDollarS(0), NumTradesS(0);
- // ===============================
- // REGISTRAZIONE PREZZO D'ENTRATA E MASSIMO DURANTE IL TRADE SHORT
- // ===============================
- if MarketPosition = -1 and MyEntryPriceS = 0 then begin
- MyEntryPriceS = EntryPrice(0);
- MaxPriceDuringTrade = MyEntryPriceS;
- MaxPriceDate = Date;
- MaxPriceTime = Time;
- TradeEntryDateS = Date;
- TradeEntryTimeS = Time;
- end;
- // Aggiorna massimo intratrade (short)
- if MarketPosition = -1 then begin
- if High > MaxPriceDuringTrade then begin
- MaxPriceDuringTrade = High;
- MaxPriceDate = Date;
- MaxPriceTime = Time;
- end;
- end;
- // ===============================
- // CALCOLO DRAWDOWN ALLA CHIUSURA DEL TRADE O FINE BAR SHORT
- // ===============================
- if (MarketPosition(1) = -1 and MarketPosition = 0) or
- (LastBarOnChart and MarketPosition = -1) then
- begin
- if MarketPosition = 0 then
- TradeExitPriceS = ExitPrice(1)
- else
- TradeExitPriceS = Close;
- TradeExitDateS = Date;
- TradeExitTimeS = Time;
- if MyEntryPriceS > 0 then begin
- // Drawdown % Short
- DrawdownPercS = ((MaxPriceDuringTrade - MyEntryPriceS) / MyEntryPriceS) * 100;
- // Drawdown in $ per contratto Short
- DrawdownDollarS = (MaxPriceDuringTrade - MyEntryPriceS) * ContractMultiplier;
- // accumula somme per media
- SumDrawdownPercS = SumDrawdownPercS + DrawdownPercS;
- SumDrawdownDollarS = SumDrawdownDollarS + DrawdownDollarS;
- NumTradesS = NumTradesS + 1;
- // stampa dettagli trade Short
- Print("Trade ", NumTradesS,
- " | Entry Price: ", MyEntryPriceS:0:2,
- " | Entry Date: ", TradeEntryDateS,
- " | Entry Time: ", TradeEntryTimeS,
- " | Exit Price: ", TradeExitPriceS:0:2,
- " | Exit Date: ", TradeExitDateS,
- " | Exit Time: ", TradeExitTimeS,
- " | Max Price: ", MaxPriceDuringTrade:0:2,
- " | Max Date: ", MaxPriceDate,
- " | Max Time: ", MaxPriceTime,
- " | Drawdown %: ", DrawdownPercS:5:2,
- " | Drawdown $: ", DrawdownDollarS:0:2);
- end;
- // reset variabili per prossimo trade Short
- MyEntryPriceS = 0;
- MaxPriceDuringTrade = 0;
- MaxPriceDate = 0;
- MaxPriceTime = 0;
- TradeEntryDateS = 0;
- TradeEntryTimeS = 0;
- TradeExitDateS = 0;
- TradeExitTimeS = 0;
- TradeExitPriceS = 0;
- end;
- // ===============================
- // STAMPA MEDIA FINALE SHORT
- // ===============================
- if LastBarOnChart then
- begin
- if NumTradesS > 0 then
- Print("Media Drawdown % = ", (SumDrawdownPercS / NumTradesS):5:2,
- " | Media Drawdown $ = ", (SumDrawdownDollarS / NumTradesS):0:2)
- else
- Print("Nessun trade eseguito.");
- end; }
- // ==========================================================================================================================================================================================//
- // SOLO SHORT
- // ==========================================================================================================================================================================================//
- // BLOCCO RUN-UP INTEGRATO SOLO SHORT "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
- // ==========================================================================================================================================================================================//
- // Moltiplicatore contratto @S (1 punto = 50$)
- {Vars: ContractMultiplier(50); // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
- // Variabili run-up Short
- Vars: MyEntryPriceS(0), MinPriceDuringTrade(0), MinPriceDate(0), MinPriceTime(0),
- TradeEntryDateS(0), TradeEntryTimeS(0), TradeExitDateS(0), TradeExitTimeS(0), TradeExitPriceS(0),
- RunupPercS(0), RunupDollarS(0), SumRunupPercS(0), SumRunupDollarS(0), NumTradesS(0);
- // ===============================
- // REGISTRAZIONE PREZZO D'ENTRATA E MINIMO DURANTE IL TRADE SHORT
- // ===============================
- if MarketPosition = -1 and MyEntryPriceS = 0 then begin
- MyEntryPriceS = EntryPrice(0);
- MinPriceDuringTrade = MyEntryPriceS;
- MinPriceDate = Date;
- MinPriceTime = Time;
- TradeEntryDateS = Date;
- TradeEntryTimeS = Time;
- end;
- // Aggiorna minimo intratrade (short)
- if MarketPosition = -1 then begin
- if Low < MinPriceDuringTrade then begin
- MinPriceDuringTrade = Low;
- MinPriceDate = Date;
- MinPriceTime = Time;
- end;
- end;
- // ===============================
- // CALCOLO RUN-UP ALLA CHIUSURA DEL TRADE O FINE BAR SHORT
- // ===============================
- if (MarketPosition(1) = -1 and MarketPosition = 0) or
- (LastBarOnChart and MarketPosition = -1) then
- begin
- if MarketPosition = 0 then
- TradeExitPriceS = ExitPrice(1)
- else
- TradeExitPriceS = Close;
- TradeExitDateS = Date;
- TradeExitTimeS = Time;
- if MyEntryPriceS > 0 then begin
- // Run-up % Short
- RunupPercS = ((MyEntryPriceS - MinPriceDuringTrade) / MyEntryPriceS) * 100;
- // Run-up in $ per contratto Short
- RunupDollarS = (MyEntryPriceS - MinPriceDuringTrade) * ContractMultiplier;
- // accumula somme per media
- SumRunupPercS = SumRunupPercS + RunupPercS;
- SumRunupDollarS = SumRunupDollarS + RunupDollarS;
- NumTradesS = NumTradesS + 1;
- // stampa dettagli trade Short
- Print("Trade ", NumTradesS,
- " | Entry Price: ", MyEntryPriceS:0:2,
- " | Entry Date: ", TradeEntryDateS,
- " | Entry Time: ", TradeEntryTimeS,
- " | Exit Price: ", TradeExitPriceS:0:2,
- " | Exit Date: ", TradeExitDateS,
- " | Exit Time: ", TradeExitTimeS,
- " | Min Price: ", MinPriceDuringTrade:0:2,
- " | Min Date: ", MinPriceDate,
- " | Min Time: ", MinPriceTime,
- " | Run-up %: ", RunupPercS:5:2,
- " | Run-up $: ", RunupDollarS:0:2);
- end;
- // reset variabili per prossimo trade Short
- MyEntryPriceS = 0;
- MinPriceDuringTrade = 0;
- MinPriceDate = 0;
- MinPriceTime = 0;
- TradeEntryDateS = 0;
- TradeEntryTimeS = 0;
- TradeExitDateS = 0;
- TradeExitTimeS = 0;
- TradeExitPriceS = 0;
- end;
- // ===============================
- // STAMPA MEDIA FINALE SHORT
- // ===============================
- if LastBarOnChart then
- begin
- if NumTradesS > 0 then
- Print("Media Run-up % = ", (SumRunupPercS / NumTradesS):5:2,
- " | Media Run-up $ = ", (SumRunupDollarS / NumTradesS):0:2)
- else
- Print("Nessun trade eseguito.");
- end; }
Advertisement
Add Comment
Please, Sign In to add comment