Maurizio-Ciullo

Indicatore Run-Up Drawdown

Dec 12th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.                                                                                    // Indicatore Run-Up Drawdown //
  3.                                                                             //  Esempio Futures @S Soia Long E Short //
  4.                                                                                    
  5. // ==========================================================================================================================================================================================//                            
  6. //                                                                                          ESEMPIO STRATEGIA SOLO LONG                                
  7. // ==========================================================================================================================================================================================//                                                                                    
  8.                                                                        
  9. // Apertura posizione long il 1° giorno del mese
  10. if DayOfMonth(Date) = 1 and MarketPosition = 0 then
  11.     buy ("LongStart") next bar at market;
  12.  
  13. // Chiusura long il 7 del mese
  14. if MarketPosition = 1 and DayOfMonth(Date) = 7 then
  15.     sell ("LongExit") next bar at market;    
  16.                                                                                                                                                                    
  17. // ==========================================================================================================================================================================================//                            
  18. //                                                                                          SOLO LONG                                  
  19. // ==========================================================================================================================================================================================//                                                                                                              
  20. // BLOCCO DRAWNDOWN INTEGRATO SOLO LONG "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
  21. // ==========================================================================================================================================================================================//
  22.  
  23. // Moltiplicatore contratto @S (1 punto = 50$)
  24. Vars: ContractMultiplier(50);                                           // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
  25.  
  26. // Variabili drawdown
  27. Vars: MyEntryPrice(0), MinPriceDuringTrade(0), MinPriceDate(0), MinPriceTime(0),
  28.       TradeEntryDate(0), TradeEntryTime(0), TradeExitDate(0), TradeExitTime(0), TradeExitPrice(0),
  29.       DrawdownPerc(0), DrawdownDollar(0), SumDrawdownPerc(0), SumDrawdownDollar(0), NumTrades(0);
  30.  
  31. // ===============================
  32. // REGISTRAZIONE PREZZO D'ENTRATA E MINIMO DURANTE IL TRADE
  33. // ===============================
  34. if MarketPosition = 1 and MyEntryPrice = 0 then begin
  35.     MyEntryPrice = EntryPrice(0);
  36.     MinPriceDuringTrade = MyEntryPrice;
  37.     MinPriceDate = Date;
  38.     MinPriceTime = Time;
  39.  
  40.     TradeEntryDate = Date;
  41.     TradeEntryTime = Time;
  42. end;
  43.  
  44. // Aggiorna minimo intratrade
  45. if MarketPosition = 1 then begin
  46.     if Low < MinPriceDuringTrade then begin
  47.         MinPriceDuringTrade = Low;
  48.         MinPriceDate = Date;
  49.         MinPriceTime = Time;
  50.     end;
  51. end;
  52.  
  53. // ===============================
  54. // CALCOLO DRAWDOWN ALLA CHIUSURA DEL TRADE O FINE BAR
  55. // ===============================
  56. if (MarketPosition(1) = 1 and MarketPosition = 0) or
  57.    (LastBarOnChart and MarketPosition = 1) then
  58. begin
  59.     if MarketPosition = 0 then
  60.         TradeExitPrice = ExitPrice(1)
  61.     else
  62.         TradeExitPrice = Close;
  63.  
  64.     TradeExitDate = Date;
  65.     TradeExitTime = Time;
  66.  
  67.     if MyEntryPrice > 0 then begin
  68.         // Drawdown %
  69.         DrawdownPerc = ((MinPriceDuringTrade - MyEntryPrice) / MyEntryPrice) * 100;
  70.  
  71.         // Drawdown in $ per contratto
  72.         DrawdownDollar = (MinPriceDuringTrade - MyEntryPrice) * ContractMultiplier;
  73.  
  74.         // accumula somme per media
  75.         SumDrawdownPerc = SumDrawdownPerc + DrawdownPerc;
  76.         SumDrawdownDollar = SumDrawdownDollar + DrawdownDollar;
  77.  
  78.         NumTrades = NumTrades + 1;
  79.  
  80.         // stampa dettagli del trade
  81.         Print("Trade ", NumTrades,
  82.               " | Entry Price: ", MyEntryPrice:0:2,
  83.               " | Entry Date: ", TradeEntryDate,
  84.               " | Entry Time: ", TradeEntryTime,
  85.               " | Exit Price: ", TradeExitPrice:0:2,
  86.               " | Exit Date: ", TradeExitDate,
  87.               " | Exit Time: ", TradeExitTime,
  88.               " | Min Price: ", MinPriceDuringTrade:0:2,
  89.               " | Min Date: ", MinPriceDate,
  90.               " | Min Time: ", MinPriceTime,
  91.               " | Drawdown %: ", DrawdownPerc:5:2,
  92.               " | Drawdown $: ", DrawdownDollar:0:2);
  93.     end;
  94.  
  95.     // reset variabili drawdown per prossimo trade
  96.     MyEntryPrice = 0;
  97.     MinPriceDuringTrade = 0;
  98.     MinPriceDate = 0;
  99.     MinPriceTime = 0;
  100.     TradeEntryDate = 0;
  101.     TradeEntryTime = 0;
  102.     TradeExitDate = 0;
  103.     TradeExitTime = 0;
  104.     TradeExitPrice = 0;
  105. end;
  106.  
  107. // ===============================
  108. // STAMPA MEDIA FINALE
  109. // ===============================
  110. if LastBarOnChart then
  111. begin
  112.     if NumTrades > 0 then
  113.         Print("Media Drawdown % = ", (SumDrawdownPerc / NumTrades):5:2,
  114.               " | Media Drawdown $ = ", (SumDrawdownDollar / NumTrades):0:2)
  115.     else
  116.         Print("Nessun trade eseguito.");
  117. end;      
  118.  
  119.  
  120. // ==========================================================================================================================================================================================//                            
  121. //                                                                                          SOLO LONG                                  
  122. // ==========================================================================================================================================================================================//
  123. // BLOCCO RUN-UP INTEGRATO SOLO LONG "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
  124. // ==========================================================================================================================================================================================//                                
  125.  
  126. // Moltiplicatore contratto @S (1 punto = 50$)
  127. {Vars: ContractMultiplier(50);                                          // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
  128.  
  129. // Variabili run-up
  130. Vars: MyEntryPrice(0), MaxPriceDuringTrade(0), MaxPriceDate(0), MaxPriceTime(0),
  131.       TradeEntryDate(0), TradeEntryTime(0), TradeExitDate(0), TradeExitTime(0), TradeExitPrice(0),
  132.       RunupPerc(0), RunupDollar(0), SumRunupPerc(0), SumRunupDollar(0), NumTrades(0);
  133.  
  134. // ===============================
  135. // REGISTRAZIONE PREZZO D'ENTRATA E MASSIMO DURANTE IL TRADE
  136. // ===============================
  137. if MarketPosition = 1 and MyEntryPrice = 0 then begin
  138.     MyEntryPrice = EntryPrice(0);
  139.     MaxPriceDuringTrade = MyEntryPrice;
  140.     MaxPriceDate = Date;
  141.     MaxPriceTime = Time;
  142.  
  143.     TradeEntryDate = Date;
  144.     TradeEntryTime = Time;
  145. end;
  146.  
  147. // Aggiorna massimo intratrade
  148. if MarketPosition = 1 then begin
  149.     if High > MaxPriceDuringTrade then begin
  150.         MaxPriceDuringTrade = High;
  151.         MaxPriceDate = Date;
  152.         MaxPriceTime = Time;
  153.     end;
  154. end;
  155.  
  156. // ===============================
  157. // CALCOLO RUN-UP ALLA CHIUSURA DEL TRADE O FINE BAR
  158. // ===============================
  159. if (MarketPosition(1) = 1 and MarketPosition = 0) or
  160.    (LastBarOnChart and MarketPosition = 1) then
  161. begin
  162.     if MarketPosition = 0 then
  163.         TradeExitPrice = ExitPrice(1)
  164.     else
  165.         TradeExitPrice = Close;
  166.  
  167.     TradeExitDate = Date;
  168.     TradeExitTime = Time;
  169.  
  170.     if MyEntryPrice > 0 then begin
  171.         // Run-Up %
  172.         RunupPerc = ((MaxPriceDuringTrade - MyEntryPrice) / MyEntryPrice) * 100;
  173.  
  174.         // Run-Up in $ per contratto
  175.         RunupDollar = (MaxPriceDuringTrade - MyEntryPrice) * ContractMultiplier;
  176.  
  177.         // accumula somme per media
  178.         SumRunupPerc = SumRunupPerc + RunupPerc;
  179.         SumRunupDollar = SumRunupDollar + RunupDollar;
  180.  
  181.         NumTrades = NumTrades + 1;
  182.  
  183.         // stampa dettagli del trade
  184.         Print("Trade ", NumTrades,
  185.               " | Entry Price: ", MyEntryPrice:0:2,
  186.               " | Entry Date: ", TradeEntryDate,
  187.               " | Entry Time: ", TradeEntryTime,
  188.               " | Exit Price: ", TradeExitPrice:0:2,
  189.               " | Exit Date: ", TradeExitDate,
  190.               " | Exit Time: ", TradeExitTime,
  191.               " | Max Price: ", MaxPriceDuringTrade:0:2,
  192.               " | Max Date: ", MaxPriceDate,
  193.               " | Max Time: ", MaxPriceTime,
  194.               " | Run-up %: ", RunupPerc:5:2,
  195.               " | Run-up $: ", RunupDollar:0:2);
  196.     end;
  197.  
  198.     // reset variabili run-up per prossimo trade
  199.     MyEntryPrice = 0;
  200.     MaxPriceDuringTrade = 0;
  201.     MaxPriceDate = 0;
  202.     MaxPriceTime = 0;
  203.     TradeEntryDate = 0;
  204.     TradeEntryTime = 0;
  205.     TradeExitDate = 0;
  206.     TradeExitTime = 0;
  207.     TradeExitPrice = 0;
  208. end;
  209.  
  210. // ===============================
  211. // STAMPA MEDIA FINALE
  212. // ===============================
  213. if LastBarOnChart then
  214. begin
  215.     if NumTrades > 0 then
  216.         Print("Media Run-up % = ", (SumRunupPerc / NumTrades):5:2,
  217.               " | Media Run-up $ = ", (SumRunupDollar / NumTrades):0:2)
  218.     else
  219.         Print("Nessun trade eseguito.");
  220. end;      }
  221.  
  222.  
  223. // ==========================================================================================================================================================================================//                            
  224. //                                                                                          ESEMPIO STRATEGIA SOLO SHORT                                   
  225. // ==========================================================================================================================================================================================//
  226.  
  227. // Apertura posizione short il 1° giorno del mese
  228. if DayOfMonth(Date) = 1 and MarketPosition = 0 then
  229.     sellshort ("ShortStart") next bar at market;
  230.  
  231. // Chiusura short il 7 del mese
  232. if MarketPosition = -1 and DayOfMonth(Date) = 7 then
  233.     buytocover ("ShortExit") next bar at market;
  234.  
  235. // ==========================================================================================================================================================================================//                            
  236. //                                                                                          SOLO SHORT                                 
  237. // ==========================================================================================================================================================================================//
  238. // ==========================================================================================================================================================================================//                                                                                                              
  239. // BLOCCO DRAWNDOWN INTEGRATO SOLO SHORT "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
  240. // ==========================================================================================================================================================================================//
  241.  
  242. // Moltiplicatore contratto @S (1 punto = 50$)
  243. {Vars: ContractMultiplier(50);                                          // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
  244.  
  245. // Variabili drawdown Short
  246. Vars: MyEntryPriceS(0), MaxPriceDuringTrade(0), MaxPriceDate(0), MaxPriceTime(0),
  247.       TradeEntryDateS(0), TradeEntryTimeS(0), TradeExitDateS(0), TradeExitTimeS(0), TradeExitPriceS(0),
  248.       DrawdownPercS(0), DrawdownDollarS(0), SumDrawdownPercS(0), SumDrawdownDollarS(0), NumTradesS(0);
  249.  
  250. // ===============================
  251. // REGISTRAZIONE PREZZO D'ENTRATA E MASSIMO DURANTE IL TRADE SHORT
  252. // ===============================
  253. if MarketPosition = -1 and MyEntryPriceS = 0 then begin
  254.     MyEntryPriceS = EntryPrice(0);
  255.     MaxPriceDuringTrade = MyEntryPriceS;
  256.     MaxPriceDate = Date;
  257.     MaxPriceTime = Time;
  258.  
  259.     TradeEntryDateS = Date;
  260.     TradeEntryTimeS = Time;
  261. end;
  262.  
  263. // Aggiorna massimo intratrade (short)
  264. if MarketPosition = -1 then begin
  265.     if High > MaxPriceDuringTrade then begin
  266.         MaxPriceDuringTrade = High;
  267.         MaxPriceDate = Date;
  268.         MaxPriceTime = Time;
  269.     end;
  270. end;
  271.  
  272. // ===============================
  273. // CALCOLO DRAWDOWN ALLA CHIUSURA DEL TRADE O FINE BAR SHORT
  274. // ===============================
  275. if (MarketPosition(1) = -1 and MarketPosition = 0) or
  276.    (LastBarOnChart and MarketPosition = -1) then
  277. begin
  278.     if MarketPosition = 0 then
  279.         TradeExitPriceS = ExitPrice(1)
  280.     else
  281.         TradeExitPriceS = Close;
  282.  
  283.     TradeExitDateS = Date;
  284.     TradeExitTimeS = Time;
  285.  
  286.     if MyEntryPriceS > 0 then begin
  287.         // Drawdown % Short
  288.         DrawdownPercS = ((MaxPriceDuringTrade - MyEntryPriceS) / MyEntryPriceS) * 100;
  289.  
  290.         // Drawdown in $ per contratto Short
  291.         DrawdownDollarS = (MaxPriceDuringTrade - MyEntryPriceS) * ContractMultiplier;
  292.  
  293.         // accumula somme per media
  294.         SumDrawdownPercS = SumDrawdownPercS + DrawdownPercS;
  295.         SumDrawdownDollarS = SumDrawdownDollarS + DrawdownDollarS;
  296.  
  297.         NumTradesS = NumTradesS + 1;
  298.  
  299.         // stampa dettagli trade Short
  300.         Print("Trade ", NumTradesS,
  301.               " | Entry Price: ", MyEntryPriceS:0:2,
  302.               " | Entry Date: ", TradeEntryDateS,
  303.               " | Entry Time: ", TradeEntryTimeS,
  304.               " | Exit Price: ", TradeExitPriceS:0:2,
  305.               " | Exit Date: ", TradeExitDateS,
  306.               " | Exit Time: ", TradeExitTimeS,
  307.               " | Max Price: ", MaxPriceDuringTrade:0:2,
  308.               " | Max Date: ", MaxPriceDate,
  309.               " | Max Time: ", MaxPriceTime,
  310.               " | Drawdown %: ", DrawdownPercS:5:2,
  311.               " | Drawdown $: ", DrawdownDollarS:0:2);
  312.     end;
  313.  
  314.     // reset variabili per prossimo trade Short
  315.     MyEntryPriceS = 0;
  316.     MaxPriceDuringTrade = 0;
  317.     MaxPriceDate = 0;
  318.     MaxPriceTime = 0;
  319.     TradeEntryDateS = 0;
  320.     TradeEntryTimeS = 0;
  321.     TradeExitDateS = 0;
  322.     TradeExitTimeS = 0;
  323.     TradeExitPriceS = 0;
  324. end;
  325.  
  326. // ===============================
  327. // STAMPA MEDIA FINALE SHORT
  328. // ===============================
  329. if LastBarOnChart then
  330. begin
  331.     if NumTradesS > 0 then
  332.         Print("Media Drawdown % = ", (SumDrawdownPercS / NumTradesS):5:2,
  333.               " | Media Drawdown $ = ", (SumDrawdownDollarS / NumTradesS):0:2)
  334.     else
  335.         Print("Nessun trade eseguito.");
  336. end;      }
  337.  
  338.  
  339. // ==========================================================================================================================================================================================//                            
  340. //                                                                                          SOLO SHORT                                 
  341. // ==========================================================================================================================================================================================//
  342. // BLOCCO RUN-UP INTEGRATO SOLO SHORT "DISATTIVA TK E STOP LOSS PRIMA DI ATTIVARLO E IMPOSTA VALORE PUNTO FUTURES IN: Vars: ContractMultiplier(50)";
  343. // ==========================================================================================================================================================================================//
  344.  
  345. // Moltiplicatore contratto @S (1 punto = 50$)
  346. {Vars: ContractMultiplier(50);                                          // ATTENZIONE METTI QUI IL VALORE DEL PUNTO DELLO STRUMENTO !!! //
  347.  
  348. // Variabili run-up Short
  349. Vars: MyEntryPriceS(0), MinPriceDuringTrade(0), MinPriceDate(0), MinPriceTime(0),
  350.       TradeEntryDateS(0), TradeEntryTimeS(0), TradeExitDateS(0), TradeExitTimeS(0), TradeExitPriceS(0),
  351.       RunupPercS(0), RunupDollarS(0), SumRunupPercS(0), SumRunupDollarS(0), NumTradesS(0);
  352.  
  353. // ===============================
  354. // REGISTRAZIONE PREZZO D'ENTRATA E MINIMO DURANTE IL TRADE SHORT
  355. // ===============================
  356. if MarketPosition = -1 and MyEntryPriceS = 0 then begin
  357.     MyEntryPriceS = EntryPrice(0);
  358.     MinPriceDuringTrade = MyEntryPriceS;
  359.     MinPriceDate = Date;
  360.     MinPriceTime = Time;
  361.  
  362.     TradeEntryDateS = Date;
  363.     TradeEntryTimeS = Time;
  364. end;
  365.  
  366. // Aggiorna minimo intratrade (short)
  367. if MarketPosition = -1 then begin
  368.     if Low < MinPriceDuringTrade then begin
  369.         MinPriceDuringTrade = Low;
  370.         MinPriceDate = Date;
  371.         MinPriceTime = Time;
  372.     end;
  373. end;
  374.  
  375. // ===============================
  376. // CALCOLO RUN-UP ALLA CHIUSURA DEL TRADE O FINE BAR SHORT
  377. // ===============================
  378. if (MarketPosition(1) = -1 and MarketPosition = 0) or  
  379.    (LastBarOnChart and MarketPosition = -1) then
  380. begin
  381.     if MarketPosition = 0 then
  382.         TradeExitPriceS = ExitPrice(1)
  383.     else
  384.         TradeExitPriceS = Close;
  385.  
  386.     TradeExitDateS = Date;
  387.     TradeExitTimeS = Time;
  388.  
  389.     if MyEntryPriceS > 0 then begin
  390.         // Run-up % Short
  391.         RunupPercS = ((MyEntryPriceS - MinPriceDuringTrade) / MyEntryPriceS) * 100;
  392.  
  393.         // Run-up in $ per contratto Short
  394.         RunupDollarS = (MyEntryPriceS - MinPriceDuringTrade) * ContractMultiplier;
  395.  
  396.         // accumula somme per media
  397.         SumRunupPercS = SumRunupPercS + RunupPercS;
  398.         SumRunupDollarS = SumRunupDollarS + RunupDollarS;
  399.  
  400.         NumTradesS = NumTradesS + 1;
  401.  
  402.         // stampa dettagli trade Short
  403.         Print("Trade ", NumTradesS,
  404.               " | Entry Price: ", MyEntryPriceS:0:2,
  405.               " | Entry Date: ", TradeEntryDateS,
  406.               " | Entry Time: ", TradeEntryTimeS,
  407.               " | Exit Price: ", TradeExitPriceS:0:2,
  408.               " | Exit Date: ", TradeExitDateS,
  409.               " | Exit Time: ", TradeExitTimeS,
  410.               " | Min Price: ", MinPriceDuringTrade:0:2,
  411.               " | Min Date: ", MinPriceDate,
  412.               " | Min Time: ", MinPriceTime,
  413.               " | Run-up %: ", RunupPercS:5:2,
  414.               " | Run-up $: ", RunupDollarS:0:2);
  415.     end;
  416.  
  417.     // reset variabili per prossimo trade Short
  418.     MyEntryPriceS = 0;
  419.     MinPriceDuringTrade = 0;
  420.     MinPriceDate = 0;
  421.     MinPriceTime = 0;
  422.     TradeEntryDateS = 0;
  423.     TradeEntryTimeS = 0;
  424.     TradeExitDateS = 0;
  425.     TradeExitTimeS = 0;
  426.     TradeExitPriceS = 0;
  427. end;
  428.  
  429. // ===============================
  430. // STAMPA MEDIA FINALE SHORT
  431. // ===============================
  432. if LastBarOnChart then
  433. begin
  434.     if NumTradesS > 0 then
  435.         Print("Media Run-up % = ", (SumRunupPercS / NumTradesS):5:2,
  436.               " | Media Run-up $ = ", (SumRunupDollarS / NumTradesS):0:2)
  437.     else
  438.         Print("Nessun trade eseguito.");
  439. end;        }
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
Advertisement
Add Comment
Please, Sign In to add comment