Advertisement
Maurizio-Ciullo

Bot Swing Trend Trailing Equity Control Drawdown

Dec 20th, 2023
1,068
1
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.                                                                  // Bot Swing Trend Trailing Equity Control Drawdown //
  3.                                                                  
  4. // **************************************************************************************************************************
  5. //                                                          2 Metodi EQC:
  6. // 1) Start sopra equityControlPercent "relative rawdown percent", stop sotto equityControlPercent "relative rawdown percent"
  7. // 2) Start sopra equityControlPercent "relative rawdown percent" ma con una nuova rottura dell'equity , stop sotto equityControlPercent "relative rawdown percent"
  8. // **************************************************************************************************************************                                                                                                                            
  9.                                                                  
  10. // **************************************************************************************************************************
  11. //                                                                      Inizio Equity Control
  12. // **************************************************************************************************************************                                                                
  13.      
  14. Input: Start_EQC_Inputs("--------------"),  
  15.        EQC_Method_Inp(0),
  16.        equityControlPercent(7),    
  17.        Start_Strategy_Inputs("--------------");
  18.  
  19. Var:   EQC_Method(false),
  20.        EquityBroken(0),
  21.        balance2(0),
  22.        highestRelativeEquity2(0),
  23.        relativeDrawdownMonetary2(0),
  24.        lowestRelativeEquity2(0),
  25.        relativeDrawdownPercent2(0);
  26.      
  27. balance2 = (close Of Data2);
  28.  
  29. // Highest Relative Equity
  30. highestRelativeEquity2 = MaxList(balance2, highestRelativeEquity2);
  31.  
  32. // LowestRelativeEquity E RelativeDrawdownMonetary E RelativeDrawdownPercent
  33. if balance2 <= highestRelativeEquity2 then
  34.     lowestRelativeEquity2 = minlist(highestRelativeEquity2, balance2);
  35.     relativeDrawdownMonetary2 = (highestRelativeEquity2 - balance2);
  36.     relativeDrawdownPercent2 = (relativeDrawdownMonetary2 / highestRelativeEquity2) * 100;
  37.  
  38.  
  39. // When we have a new Equity High and Relative Drawdown is Less then equityControlPercent the value is set to 0 else 1. "Start Straidng Broke Equity Allowed"  
  40. If relativeDrawdownPercent2 > equityControlPercent then
  41.     EquityBroken = EquityBroken +1
  42. else if
  43.     relativeDrawdownPercent2 = 0 then
  44.     EquityBroken = 0;
  45.    
  46. // **************************************************************************************************************************
  47. // Entrata Senza Equity Control EQC_Method = 0
  48. // **************************************************************************************************************************  
  49. if EQC_Method_Inp = 0 then begin
  50.     EQC_Method = true;
  51. end
  52. // **************************************************************************************************************************
  53. // Equity Control. Stoppa l'operatività ad una percentuale input derivanta dal massimo drawdown relativo della strategia originale caricata in data2 "Balance Con Initial Capital di tutte le candele"  EQC_Method = 1
  54. // **************************************************************************************************************************      
  55. else if EQC_Method_Inp = 1 then begin
  56.     EQC_Method = relativeDrawdownPercent2 >= 0 and relativeDrawdownPercent2 <= equityControlPercent;
  57. end
  58. // **************************************************************************************************************************
  59. // Equity Control. Stoppa l'operatività ad una percentuale input derivanta dal massimo drawdown relativo della strategia originale caricata in data2 "Balance Con Initial Capital di tutte le candele" EQC_Method = 2
  60. // La strategia Riparte quando rompiamo un nuovo massimo dell'equity e non abbiamo raggiunto l'input del massimo drawdown ammesso ES: Stop >= 7% Max DD; Restart New Highest Equity High and < 7% Max DD;
  61. // **************************************************************************************************************************  
  62. else if
  63.     EQC_Method_Inp = 2 then Begin
  64.     EQC_Method =  EquityBroken = 0;
  65. end;
  66.    
  67.    
  68.    
  69. // **************************************************************************************************************************
  70. //                                                                           Inizio Strategia
  71. // **************************************************************************************************************************  
  72.    
  73. //Il trading system completo - Swing-Trend-Trailing (Strategia Trend Following Con Swing Di Posizione) - parte 1
  74. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
  75. // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= NO) (Stop Loss Limit Long/Short= -10%) (Stop Loss Market Long/Short= SI) (Trailing Stop=SI) (Stop Emergenza= NO)
  76. // (Rischio Operazione 2% Perdita Media)
  77. // (In Sample Dal=17/08/2017 Al 17/10/2020) (Out Of Sample Dal=18/10/2020 Al 15/03/2021)
  78.  
  79. // GLI IMPUT POTREBBERO ESSERE DIVERSI E VANNO PRESI DAL CODICE DI PINESCRIPT, INSERIRE ANCHE LE VARIABILI SHORT CHE POTREBBERO AVERE INPUT DIVERSI
  80.  
  81. // Auentare il Max Bars Back Su Tradestation Altrimenti Non Funziona Il Conteggio Barssinceentry 500 E Cliccare Su Enable Strategy Altrimenti Non Parte
  82.  
  83. input:
  84.   InitialCapital(100000),
  85.   percent_risk(25),
  86.   lunghezza_ema(90),
  87.   perc_apertura_minima(2),
  88.   perc_apertura_massima(4),
  89.   perc_chiusura_minima(0),
  90.   input_trailing_stop_trigger(12),
  91.   input_trailing_stop_close(6),
  92.   input_stop_loss_percent(10),  // Unico Long E Short
  93.   //skipday(saturday),
  94.   //skipmonth1(10),
  95.   //skipmonth2(9),
  96.   solo_long(false),
  97.   solo_short(false);
  98.    
  99.  
  100. Vars:
  101.    media_ema(0),
  102.    apertura_minima(0),
  103.    apertura_massima(0),
  104.    chiusura_minima(0),
  105.    stop_loss(0),
  106.    media_ema_1(0),
  107.    trailing_stop_trigger(0),
  108.    trailing_stop_close(0),
  109.    trailing_stop_trigger_long(0),
  110.    trailing_stop_close_long(0),
  111.    trailing_stop_trigger_short(0),
  112.    trailing_stop_close_short(0),
  113.    trailing_long(false),
  114.    trailing_short(false),
  115.    highesthigh(0),
  116.    lowestlow(0),
  117.    ATR(0),
  118.    risk(0),
  119.    nr_share(0);
  120.    
  121.  
  122. // Calcololo degli indicatori
  123.       media_ema = XAverage(Close, lunghezza_ema);
  124.       media_ema_1 = XAverage(Close[1], lunghezza_ema);
  125.  
  126. // calcolo dei filtri in percentuale
  127.   apertura_minima   = (media_ema / 100) * perc_apertura_minima;
  128.   apertura_massima  = (media_ema / 100) * perc_apertura_massima;
  129.   chiusura_minima   = (media_ema / 100) * perc_chiusura_minima;
  130.  
  131.   // Calcolo Trailing Stop Long E Short
  132.   trailing_stop_trigger_long = Entryprice + (entryprice * input_trailing_stop_trigger)/100;
  133.   trailing_stop_close_long = entryprice + (entryprice * input_trailing_stop_close)/100;
  134.   trailing_stop_trigger_short = Entryprice - (entryprice * input_trailing_stop_trigger)/100;
  135.   trailing_stop_close_short = entryprice - (entryprice * input_trailing_stop_close)/100;
  136.  
  137.   // Originale
  138.   {trailing_long = high >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[1] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long)  or (MarketPosition =1 and high[2] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[3] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long)
  139.      or (MarketPosition =1 and high[4] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[5] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[6] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[7] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long)
  140.      or (MarketPosition =1 and high[8] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[9] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[10] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[11] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long)
  141.      or (MarketPosition =1 and high[12] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[13] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[14] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long) or (MarketPosition =1 and high[15] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long)
  142.      or (MarketPosition =1 and high[16] >= trailing_stop_trigger_long and Close < trailing_stop_close_long and close[1] > trailing_stop_close_long);
  143.  
  144.   // Originale
  145.   trailing_short = low <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[1] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short)  or (MarketPosition =-1 and low[2] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[3] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short)
  146.      or (MarketPosition =-1 and low[4] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[5] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[6] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[7] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short)
  147.      or (MarketPosition =-1 and low[8] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[9] <=trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[10] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[11] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short)
  148.      or (MarketPosition =-1 and low[12] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[13] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[14] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short) or (MarketPosition =-1 and low[15] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short)
  149.      or (MarketPosition =-1 and low[16] <= trailing_stop_trigger_short and  Close > trailing_stop_close_short and close[1] < trailing_stop_close_short);}
  150.  
  151.  {trailing_long = high >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[1] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long)  or (MarketPosition =1 and high[2] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[3] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long)
  152.      or (MarketPosition =1 and high[4] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[5] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[6] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[7] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long)
  153.      or (MarketPosition =1 and high[8] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[9] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[10] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[11] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long)
  154.      or (MarketPosition =1 and high[12] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[13] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[14] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long) or (MarketPosition =1 and high[15] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long)
  155.      or (MarketPosition =1 and high[16] >= trailing_stop_trigger_long and Close cross under trailing_stop_close_long);
  156.  
  157.   trailing_short = low <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[1] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short)  or (MarketPosition =-1 and low[2] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[3] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short)
  158.      or (MarketPosition =-1 and low[4] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[5] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[6] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[7] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short)
  159.      or (MarketPosition =-1 and low[8] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[9] <=trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[10] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[11] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short)
  160.      or (MarketPosition =-1 and low[12] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[13] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[14] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short) or (MarketPosition =-1 and low[15] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short)
  161.      or (MarketPosition =-1 and low[16] <= trailing_stop_trigger_short and  Close cross over trailing_stop_close_short)}
  162.  
  163.   highesthigh = highest(high, Barssinceentry);
  164.   trailing_long = (highesthigh >= trailing_stop_trigger_long and close <= trailing_stop_close_long);
  165.  
  166.   lowestlow = lowest(low, Barssinceentry); 
  167.   trailing_short = (lowestlow <= trailing_stop_trigger_short and close >= trailing_stop_close_short);
  168.  
  169.  
  170. // Money menagment
  171.   risk = percent_risk/100;
  172.   nr_share = floor((InitialCapital + NetProfit) * risk) / close ;
  173.   stop_loss=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent);
  174.  
  175. // **************************************************************************************************************************
  176. // // Entrata/Uscita Long
  177. // **************************************************************************************************************************  
  178. // Entrata Long
  179.                                                                                          { and (close[1] < ema1 + apertura_minima or low[1] < ema1 + apertura_minima Tradingview}
  180.     //if close > (media_ema+apertura_minima) and close < (media_ema + apertura_massima) and close[2] < (media_ema+apertura_minima) and open > close  and not solo_short {and Dayofweek(date) <> skipday and month(date) <> skipmonth1 and Dayofmonth(date) > 5} then
  181.       if close > (media_ema + apertura_minima)  and close < (media_ema + apertura_massima) and ((close[1] < (media_ema_1 + apertura_minima)) or (low[1] < (media_ema_1 + apertura_minima))) and close > open  and not solo_short {and Dayofweek(date) <> skipday and month(date) <> skipmonth1 and Dayofmonth(date) > 5} and EQC_Method then//and relativeDrawdownPercent2 >= 0 and relativeDrawdownPercent2 <= equityControlPercent then
  182.       Buy("Long") nr_share contracts Next Bar at market;
  183.              
  184. // Uscita Long    
  185.     if close < media_ema - chiusura_minima then
  186.        Sell("Chiusura Long") from entry("Long") Next Bar at market;
  187.      
  188.  // Uscita Trailing Long  
  189.     If (MarketPosition =1 and trailing_long) then
  190.      Sell("Trailing Long") from entry("Long") Next Bar at market;
  191.  
  192. // **************************************************************************************************************************
  193. // Entrata/Uscita Short
  194. // **************************************************************************************************************************      
  195. // Entrata Short
  196.                                                                                            {and (close[1] > ema1 - apertura_minima or low[1] > ema1 - apertura_minima)}
  197.       if  close < (media_ema - apertura_minima) and close > (media_ema - apertura_massima) and ((close[1] > (media_ema_1 - apertura_minima)) or (high[1] > (media_ema_1 - apertura_minima))) and close < open and not solo_long {and Dayofweek(date) <> skipday and month(date) <> skipmonth1 and Dayofmonth > 5}  and EQC_Method then //and relativeDrawdownPercent2 >= 0 and relativeDrawdownPercent2 <= equityControlPercent then
  198.       Sellshort("Short") nr_share Contracts Next Bar at market;
  199.                  
  200. // Uscita Short  
  201.     if close > (media_ema + chiusura_minima) then
  202.         Buytocover("Chiusura Short") from entry("Short") Next Bar at market;
  203.    
  204.   // Uscita Trailing Short        
  205.      If (MarketPosition =-1 and trailing_short) then    
  206.         Buytocover("Trailing Short") from entry("Short") Next Bar at market;
  207.      
  208. Setstopposition;
  209. SetStopLoss(stop_loss);
  210.  
  211. // **************************************************************************************************************************
  212.                                                                 // Fine Strategia
  213. // **************************************************************************************************************************
  214.  
  215.  
  216. // **************************************************************************************************************************
  217. // Calcolo dell relative drawdown della strategia attuale che stà girando Data1 "Strategy"
  218. // **************************************************************************************************************************  
  219. inputs: Start_EQC_Input("--------------");
  220.  
  221.  Vars:
  222.     mp(0),
  223.     formattedDate(""),
  224.     formattedTime(""),
  225.     dateTimeString("");
  226.    
  227.  Vars:
  228.     balance(0),
  229.     highestRelativeEquity(0),
  230.     relativeDrawdownMonetary(0),
  231.     lowestRelativeEquity(0),
  232.     relativeDrawdownPercent(0);
  233.  
  234. // Balance
  235. balance = (InitialCapital + NetProfit);
  236. mp = marketposition;
  237.  
  238. // Highest Relative Equity
  239. highestRelativeEquity = MaxList(balance, highestRelativeEquity);
  240.  
  241.  
  242. // LowestRelativeEquity E RelativeDrawdownMonetary E RelativeDrawdownPercent
  243. if balance <= highestRelativeEquity then
  244.     lowestRelativeEquity = minlist(highestRelativeEquity, balance);
  245.     relativeDrawdownMonetary = (highestRelativeEquity - balance);
  246.     relativeDrawdownPercent = (relativeDrawdownMonetary / highestRelativeEquity) * 100;
  247.  
  248. // **************************************************************************************************************************
  249. // Export Equity Con Initial Capital Incluso Di Tutte Le Candele Eccetto BarsBack Della Strategia On Csv //
  250. // **************************************************************************************************************************                                                  
  251. // Sul file .csv carico: Date/Time/Open/High/Low /Equity/Volume Per una questione di caricamento su tradestation... . Apro il grafico, clicco su una candela 2 volte e nelle impostazioni style clicco su line on close
  252. // per avere una linea con solo i valori dell'equity profitti/perdite cumulative con l'initial capital.
  253.  
  254. //if mp[0] <> mp[1] and mp[0] <> 0 then begin { Solo per scaricare i dati ad ogni inizio nuova operazione, se commentato scarico tutte le candele.}
  255. // Quando carico Data2 il numero delle candele deve coincidere con il Data1, altrimenti tradestation non riesce a caricarli, per questo motivo scarico il balance di ongi candela.
  256. Inputs: printFileEquityWithInitCapitAllCandles(false),
  257.         printLogStrategy(false),
  258.         printLogEquity(false);
  259.  
  260. If printFileEquityWithInitCapitAllCandles = True {and mp[0] <> mp[1] and mp[0] <> 0 then begin} Then Begin
  261.     // Formatta la data nel formato "MM-dd-yyyy"
  262.     formattedDate = FormatDate("yyyy-MM-dd", ElDateToDateTime(Date));
  263.    
  264.     // Formatta l'ora nel formato "00:00:00"
  265.     formattedTime = BarDateTime.Format("%H:%M:%S");
  266.      
  267.     // Combina data e ora nel formato richiesto
  268.     dateTimeString = formattedDate + "," + formattedTime;
  269.  
  270. // Stampa nel file CSV il balance della strategia originale tutte le candele eccetto barbacks
  271.     Print(File("C:\Users\Utente\Desktop\Equity Control\Tradestation\Swing Trend Trailing\Exports\Export_Equity.csv"), dateTimeString, ",", open, ",", high, ",", low, ",", NumToStr(balance, 2) , Volume, ",");    
  272. End;
  273.  
  274. // Print Log Strategy Data1 Tutte Le Candele
  275. if printLogStrategy = true Then
  276. Begin
  277.     Once Clearprintlog; // Clear the print log when the strategy first applyed or refreshed
  278.     print(Formatdate("dd/MM/yy", ElDateToDateTime( Date )), ", ", BarDateTime.Format( "%H%M.%S" ), ", ", " HighestRelativeEQData1= " ,highestRelativeEquity, ", ", " LowestRelativeEQData1= " ,lowestRelativeEquity, ", ", " RelativeDrawdownMonetaryData1= ", relativeDrawdownMonetary, ", ", " RelativeDrawdownPercentData1= ", relativeDrawdownPercent , " %", ", ", " BarNumData1= ", BarNumber);
  279. End;
  280.  
  281. // Print Log Equity Data2 Tutte Le Candele
  282. if printLogEquity = true Then
  283. Begin
  284.     Once Clearprintlog; // Clear the print log when the strategy first applyed or refreshed
  285.     print(Formatdate("dd/MM/yy", ElDateToDateTime( Date )), ", ", BarDateTime.Format( "%H%M.%S" ), ", ", " HighestRelativeEQData2= " ,highestRelativeEquity2, ", ", " LowestRelativeEQData2= " ,lowestRelativeEquity2, ", ", " RelativeDrawdownMonetaryData2= ", relativeDrawdownMonetary2, ", ", " RelativeDrawdownPercentData2= ", relativeDrawdownPercent2 , " %", ", ", " BarNumData2= ", BarNumber);
  286. End;
  287.  
  288. // **************************************************************************************************************************
  289. // Plotshape E Print Della Strategia Che Stà Girando Data1 "Strategy" //  Mostra solo se il DrawDown Supera o meno il valore di input. Non ha nulla a che fare con gli ingressi.                                            
  290. // **************************************************************************************************************************
  291. Input: plotshapeStrategy(false);
  292.        
  293. // Plot su strategy 1mo plot Start Della Strategia Che Stà Girando Data1 "Strategy"
  294. If plotshapeStrategy = true and relativeDrawdownPercent < equityControlPercent {and mp <> 0} Then            
  295. Begin
  296.     Value1 = Text_new(D, T, L, "*");
  297.     Text_setcolor(Value1, Green);
  298.     Text_setstyle(Value1, 2, 0);
  299. End;
  300.  
  301. // Plot su strategy 2ndo plot End Solo Dei Trade Conclusi Della Strategia Che Stà Girando Data1 "Strategy"
  302. If plotshapeStrategy = true and (relativeDrawdownPercent > equityControlPercent) {and (mp = 0) or (mp <> 0))} Then
  303. Begin
  304.     Value2 = Text_new(D, T, L, "*");
  305.     Text_setcolor(Value2, Red);
  306.     Text_setstyle(Value2, 2, 0);
  307. End;
  308.  
  309. // **************************************************************************************************************************
  310. // Plotshape E Print Start End Dell'Equity Di Data2 "Equity" // Questo ha a che fare con gli ingressi
  311. // **************************************************************************************************************************
  312. Input: plotshapeEquity(false),
  313.        printStartEndEquity(false);
  314.        
  315. // Plot su strategy 1mo plot Start Solo Del'equity Data2 "Equity"
  316. If plotshapeEquity = true and EQC_Method {and mp <> 0} Then
  317. Begin
  318.     Value3 = Text_new(D, T, L, "*");
  319.     Text_setcolor(Value3, Green);
  320.     Text_setstyle(Value3, 2, 0);
  321. End;
  322.  
  323. // Plot su strategy 2ndo plot End Solo Del'equity Data2 "Equity"
  324. If plotshapeEquity = true and (relativeDrawdownPercent2 > equityControlPercent) {and (mp = 0) or (mp <> 0))} Then
  325. Begin
  326.     Value4 = Text_new(D, T, L, "*");
  327.     Text_setcolor(Value4, Red);
  328.     Text_setstyle(Value4, 2, 0);
  329. End;
  330.  
  331.  
  332. // Print delle date Start Dell'equity Data2 "Equity"
  333. If printStartEndEquity = true then
  334. Begin
  335.     Once Clearprintlog; // Clear the print log when the strategy first applyed or refreshed
  336.     if EQC_Method and close of data2 <> close[1] of data2 Then {and close of data2 <> close[1] of data2 "Riduce I Log Non Necessari"}
  337.     print(Formatdate("dd/MM/yy", ElDateToDateTime( Date )), ", ", BarDateTime.Format( "%H%M.%S" ),  " Start Equity Data2", ", ", " DD=", relativeDrawdownPercent2, " %");
  338. // Print delle date End Dell'equity Data2 "Equity"
  339.     if (relativeDrawdownPercent2 > equityControlPercent) and close of data2 <> close[1] of data2 Then {and close of data2 <> close[1] of data2 "Riduce I Log Non Necessari"}
  340.     print(Formatdate("dd/MM/yy", ElDateToDateTime( Date )), ", ", BarDateTime.Format( "%H%M.%S" ),  " End Equity Data2", ", ", " DD=", relativeDrawdownPercent2, " %");
  341. End;
  342.  
  343. // **************************************************************************************************************************
  344. // Export Equity With No Initial Capital On Csv Solo Dei Trade Conclusi //
  345. // **************************************************************************************************************************                                                  
  346. // Sul file .csv carico: Date/Time/Open/High/Low /Equity/Volume Per una questione di caricamento su tradestation... . Apro il grafico, clicco su una candela 2 volte e nelle impostazioni style clicco su line on close
  347. // per avere una linea con solo i valori dell'equity profitti/perdite cumulative.
  348.                                                                                
  349. {Vars:
  350.     mp(0),
  351.     formattedDate(""),
  352.     formattedTime(""),
  353.     dateTimeString("");
  354.  
  355. mp = marketposition;
  356.  
  357. if mp[0] <> mp[1] and mp[0] <> 0 then begin
  358.     // Formatta la data nel formato "MM-dd-yyyy"
  359.     formattedDate = FormatDate("dd-MM-yyyy", ElDateToDateTime(Date));
  360.    
  361.     // Formatta l'ora nel formato "00:00:00"
  362.     formattedTime = BarDateTime.Format("%H:%M:%S");
  363.    
  364.     // Combina data e ora nel formato richiesto
  365.     dateTimeString = formattedDate + "," + formattedTime;
  366.    
  367.     // Stampa nel file CSV
  368.     Print(File("C:\Users\Utente\Desktop\Equity Control\Tradestation\Swing Trend Trailing\Exports\Export_Equity.csv"), dateTimeString, ",", open, ",", high, ",", low, ",", NumToStr(NetProfit, 2) , Volume, ",");
  369. end;}
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement