Maurizio-Ciullo

Indicatore Day_Of_Week-Day_of_Month-Month

Dec 12th, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                                                                 // Indicatore Day_Of_Week-Day_of_Month-Month //
  2.                                                                                    // Decommenta Il Blocco che vuoi usare //
  3.  
  4. // ======================================================================
  5. // INDICATORE DAY_OF_WEEK - DAY_OF_MONTH - MONTH
  6. // ======================================================================
  7. // Modalità Calendario
  8. // Money Management
  9. // Test Giorno Della Settimana
  10. // Test Giorno Mensile
  11. // Test 2 Ingressi Con Pausa
  12. // Test Mensile
  13. // ======================================================================
  14.  
  15. // ====================================================================== INIZIO INPUTS E VARIABILI PER IL CODICE 1 AL CODICE 3 ====================================================================== //
  16.  
  17. Input:
  18.     Only_long(false),
  19.     Only_short(false),
  20.     percent_initial_equity(false),
  21.     InitialCapital(400000),
  22.     percent_risk(25),
  23.     Settimanale(true),       // Dom = 0 / Lun = 1 Etc...
  24.     Mensile(false);          // 1 / 30 etc...
  25.  
  26.  
  27. inputs: longEntry(1), longExit(4), shortEntry(3), shortExit(5), startPause(5), endPause(15), INIZIO_INPUT_A_BLOCCHI_4("------------INIZIO_INPUT_A_BLOCCHI------------");
  28.  
  29.    
  30. Vars:
  31. CurrentMonth(0),
  32. entryDoneLongThisMonth(false),
  33. entryDoneShortThisMonth(false);
  34.  
  35. Vars:
  36. risk(percent_risk),
  37. nr_share(0);
  38.  
  39. // Calcolo Money Management
  40. risk = percent_risk/100;
  41. nr_share = floor((InitialCapital) * risk) / close ;  // Entro con il 25% del capitale iniziale
  42.  
  43. // 1 Contratto o % Equity Iniziale
  44. if not percent_initial_equity then
  45.     nr_share = 1;
  46.  
  47. // ====================================================================== FINE INPUTS E VARIABILI PER IL CODICE 1 AL CODICE 4 ====================================================================== //
  48.  
  49. // -------------------------------------------------------------
  50. // 1 Test Giorni Della Settimana Ingresso In Input Con Uscita Barra Successiva    * SE MANCA GIORNO INPUT INGRESSO SALTA OPERAZIONE / ESCE SEMPRE LA BARRA DOPO *
  51. // -------------------------------------------------------------
  52.  
  53. {if dayofweek(date) = longEntry and Settimanale = true and not Only_short then buy ("Long Sett") nr_share contracts next bar at market;
  54. if Marketposition = 1 and Settimanale = true and not Only_short then sell ("Chiusura Long Sett") from entry("Long Sett") next bar at market;  
  55. if dayofweek(date) = shortEntry and Settimanale = true and not Only_long then sellshort ("Short Sett") nr_share contracts next bar at market;
  56. if Marketposition = -1 and Settimanale = true and not Only_long then sell ("Chiusura Short Sett") from entry("Short Sett") next bar at market;   }
  57.  
  58. // ======================================================================// ======================================================================// ======================================================================
  59.  
  60. // -------------------------------------------------------------
  61. // 2 Test Giorni Della Settimana Ingresso In Input Con Uscita In Input          * SE MANCA GIORNO INPUT INGRESSO SALTA OPERAZIONE / SE MANCA GIORNO INPUT USCITA ESCE APPENA TROVA INPUT / " !!! MENO AFFIDABILE" !!! *
  62. // -------------------------------------------------------------
  63.  
  64. {if dayofweek(date) = longEntry and Settimanale = true and not Only_short then buy ("Long Sett") nr_share contracts next bar at market;
  65. if dayofweek(date) = longExit and Settimanale = true and not Only_short then sell ("Chiusura Long Sett") from entry("Long Sett") next bar at market;
  66. if dayofweek(date) = shortEntry and Settimanale = true and not Only_long then sellshort ("Short Sett") nr_share contracts next bar at market;
  67. if dayofweek(date) = shortExit and Settimanale = true and not Only_long then buytocover ("Chiusura Short Sett") from entry("Short Sett") next bar at market;  }
  68.  
  69. // ======================================================================// ======================================================================// ======================================================================
  70.  
  71. // -------------------------------------------------------------
  72. // 3 Test Giorni Del Mese Ingresso In Input Con Uscita Giorno Dopo             * SE MANCA GIORNO INPUT INGRESSO SALTA OPERAZIONE / ESCE SEMPRE LA BARRA DOPO *
  73. // -------------------------------------------------------------
  74.  
  75. {if dayofmonth(date) = longEntry and Mensile = true and not Only_short then buy ("Long Mens") nr_share contracts next bar at market;
  76. if Marketposition = 1 and Mensile = true and not Only_short then sell ("Chiusura Long Mens") from entry("Long Mens") next bar at market;
  77. if dayofmonth(date) = shortEntry and Mensile = true and not Only_long then sellshort ("Short Mens") nr_share contracts next bar at market;
  78. if Marketposition = -1 and Mensile = true and not Only_long then Buytocover ("Chiusura Short Mens") from entry("Short Mens") next bar at market;     }
  79.  
  80. // ======================================================================// ======================================================================// ======================================================================
  81.  
  82. // -------------------------------------------------------------
  83. // 4 Test Giorni Del Mese 2 Ingressi In Input con Pausa Con Con Uscita In Input (con gestione calendario mesi da 28–31 giorni)
  84. // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE MANCA GIORNO INPUT USCITA ESCE BARRA SUCCESSIVA /
  85. // SE INPUT ENTRATA GIORNI FINE MESE 29/30/31 ENTRA APPENA TROVA INPUT / SE INPUT USCITA GIORNI FINE MESE 29/30/31 ESCE APPENA TROVA INPUT / " !!! MENO AFFIDABILE" !!! *
  86. // -------------------------------------------------------------
  87.  
  88. // Calendario:
  89. {Vars:
  90.     m(0), y(0), last_day_of_month(0);
  91.  
  92. // Calcolo mese e anno corrente
  93. m = Month(Date);
  94. y = Year(Date);
  95.  
  96. // Gestione mesi
  97. if m = 1 or m = 3 or m = 5 or m = 7 or m = 8 or m = 10 or m = 12 then
  98.     last_day_of_month = 31
  99. else if m = 4 or m = 6 or m = 9 or m = 11 then
  100.     last_day_of_month = 30
  101. else begin
  102.     // Febbraio → gestione anni bisestili
  103.     if (Mod(y, 400) = 0) or ((Mod(y, 4) = 0) and (Mod(y, 100) <> 0)) then
  104.         last_day_of_month = 29
  105.     else
  106.         last_day_of_month = 28;
  107. end;
  108.  
  109. Inputs:
  110.     // Long
  111.     longEntry1(1),
  112.     longExit1(6),
  113.     startPauseLong(6),
  114.     endPauseLong(10),
  115.     longEntry2(19),
  116.     longExit2(23),
  117.  
  118.     // Short
  119.     shortEntry1(10),
  120.     shortExit1(16),
  121.     startPauseShort(16),
  122.     endPauseShort(19),
  123.     shortEntry2(25),
  124.     shortExit2(28);
  125.  
  126. Vars:
  127.     // Flags Long
  128.     entryDoneLongBlock1(false),
  129.     entryDoneLongBlock2(false),
  130.     // Flags Short
  131.     entryDoneShortBlock1(false),
  132.     entryDoneShortBlock2(false),
  133.     // Reset mensile
  134.     lastMonthProcessed(0),
  135.     lastYearProcessed(0);
  136.  
  137. // -------------------------------------------------------------
  138. // RESET VARIABILI MENSILI - Robusto per intraday e daily
  139. // -------------------------------------------------------------
  140. if (Month(Date) <> lastMonthProcessed) or (Year(Date) <> lastYearProcessed) then begin
  141.     // Long
  142.     entryDoneLongBlock1  = false;
  143.     entryDoneLongBlock2  = false;
  144.     // Short
  145.     entryDoneShortBlock1 = false;
  146.     entryDoneShortBlock2 = false;
  147.  
  148.     lastMonthProcessed = Month(Date);
  149.     lastYearProcessed  = Year(Date);
  150. end;
  151.  
  152. // -------------------------------------------------------------
  153. // LONG MENSILE (DOPPIO BLOCCO CON PAUSA)
  154. // -------------------------------------------------------------
  155. if not Only_short then begin
  156.  
  157.     // BLOCCO 1 - INGRESSO
  158.     if (not entryDoneLongBlock1) and
  159.        (DayOfMonth(Date) >= longEntry1) and
  160.        (DayOfMonth(Date) < startPauseLong) then begin
  161.         buy ("Long Mens 1") nr_share contracts next bar at market;
  162.         entryDoneLongBlock1 = true;
  163.     end;
  164.  
  165.     // BLOCCO 1 - USCITA
  166.     if MarketPosition = 1 then begin
  167.         if (DayOfMonth(Date) >= longExit1)
  168.            or (longExit1 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
  169.             sell ("Exit Long Mens 1") from entry("Long Mens 1") next bar at market;
  170.     end;
  171.  
  172.     // BLOCCO 2 - INGRESSO
  173.     if (not entryDoneLongBlock2) and
  174.        (DayOfMonth(Date) >= longEntry2) and
  175.        (DayOfMonth(Date) >= endPauseLong) then begin
  176.         buy ("Long Mens 2") nr_share contracts next bar at market;
  177.         entryDoneLongBlock2 = true;
  178.     end;
  179.  
  180.     // BLOCCO 2 - USCITA
  181.     if MarketPosition = 1 then begin
  182.         if (DayOfMonth(Date) >= longExit2)
  183.            or (longExit2 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
  184.             sell ("Exit Long Mens 2") from entry("Long Mens 2") next bar at market;
  185.     end;
  186.  
  187. end;
  188.  
  189. // -------------------------------------------------------------
  190. // SHORT MENSILE (DOPPIO BLOCCO CON PAUSA)
  191. // -------------------------------------------------------------
  192. if not Only_long then begin
  193.  
  194.     // BLOCCO 1 - INGRESSO
  195.     if (not entryDoneShortBlock1) and
  196.        (DayOfMonth(Date) >= shortEntry1) and
  197.        (DayOfMonth(Date) < startPauseShort) then begin
  198.         sellshort ("Short Mens 1") nr_share contracts next bar at market;
  199.         entryDoneShortBlock1 = true;
  200.     end;
  201.  
  202.     // BLOCCO 1 - USCITA
  203.     if MarketPosition = -1 then begin
  204.         if (DayOfMonth(Date) >= shortExit1)
  205.            or (shortExit1 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
  206.             buytocover ("Exit Short Mens 1") from entry("Short Mens 1") next bar at market;
  207.     end;
  208.  
  209.     // BLOCCO 2 - INGRESSO
  210.     if (not entryDoneShortBlock2) and
  211.        (DayOfMonth(Date) >= shortEntry2) and
  212.        (DayOfMonth(Date) >= endPauseShort) then begin
  213.         sellshort ("Short Mens 2") nr_share contracts next bar at market;
  214.         entryDoneShortBlock2 = true;
  215.     end;
  216.  
  217.     // BLOCCO 2 - USCITA
  218.     if MarketPosition = -1 then begin
  219.         if (DayOfMonth(Date) >= shortExit2)
  220.            or (shortExit2 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
  221.             buytocover ("Exit Short Mens 2") from entry("Short Mens 2") next bar at market;
  222.     end;
  223.  
  224. end;      }
  225.  
  226. // ======================================================================// ======================================================================// ======================================================================
  227.  
  228. // -------------------------------------------------------------
  229. // 5 Test Mensile Ingresso In Input Con Uscita Cambio Mese Successivo                                      
  230. // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE INPUT ENTRATA GIORNI FINE MESE 29/30/31 ENTRA APPENA TROVA INPUT / USCITA CAMBIO MESE        
  231. // -----------------------------------------------------------
  232.  
  233. // ======================= INPUT ===============================
  234. {Inputs:
  235.     Start_Day(5);    // giorno del mese per ingresso
  236.     Start_Month(2),  // mese da cui iniziare il test (1=Gen, 2=Feb,...)
  237.  
  238. // ======================= VARIABILI ==========================
  239. Vars:
  240.     entryMonth(0),              // memorizza il mese in cui siamo entrati (per uscita)
  241.     entryDoneThisMonth(false);  // flag per evitare più ingressi nello stesso mese
  242.  
  243. // ---------------------- RESET FLAG MENSILE ------------------
  244. if Month(Date) <> entryMonth then
  245.     entryDoneThisMonth = false;  // un solo trade per mese per direzione
  246.  
  247. // ------------------- ENTRATA LONG -------------------
  248. if (Month(Date) = Start_Month) and (not Only_short) and (not entryDoneThisMonth) and (MarketPosition = 0) and (DayOfMonth(Date) >= Start_Day) then begin
  249.     buy ("Long Mese") nr_share contracts next bar at market;
  250.     entryDoneThisMonth = true;
  251.     entryMonth = Month(Date);  // memorizza il mese di ingresso
  252. end;
  253.  
  254. // ------------------- USCITA LONG -------------------
  255. if (MarketPosition = 1) and (Month(Date) <> entryMonth) then begin
  256.     sell ("Exit Long Mese") from entry("Long Mese") next bar at market;
  257. end;
  258.  
  259. // ------------------- ENTRATA SHORT -------------------
  260. if (Month(Date) = Start_Month) and (not Only_long) and (not entryDoneThisMonth) and (MarketPosition = 0) and (DayOfMonth(Date) >= Start_Day) then begin
  261.     sellshort ("Short Mese") nr_share contracts next bar at market;
  262.     entryDoneThisMonth = true;
  263.     entryMonth = Month(Date);  // memorizza il mese di ingresso
  264. end;
  265.  
  266. // ------------------- USCITA SHORT -------------------
  267. if (MarketPosition = -1) and (Month(Date) <> entryMonth) then begin
  268.     buytocover ("Exit Short Mese") from entry("Short Mese") next bar at market;
  269. end;     }
  270.  
  271. // ======================================================================// ======================================================================// ======================================================================
  272.  
  273. // -------------------------------------------------------------
  274. // 6 Test Mensile Ingresso In Input Con Uscita In Input
  275. // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE MANCA GIORNO INPUT USCITA ESCE BARRA SUCCESSIVA /
  276. //   SE INPUT ENTRATA GIORNI FINE MESE 29/30/31 ENTRA APPENA TROVA INPUT / SE INPUT USCITA GIORNI FINE MESE 29/30/31 ESCE APPENA TROVA INPUT          
  277. // -----------------------------------------------------------
  278.  
  279. // ======================= INPUT ===============================
  280. {Inputs:
  281.     Start_Day(1),       // giorno del mese per ingresso
  282.     Start_Month(1),     // mese da cui iniziare il test (1=Gennaio,...)
  283.     Exit_Day(31),       // giorno del mese per uscita
  284.     Exit_Month(12);     // mese di uscita (1=Gennaio,...)
  285.  
  286. // ======================= VARIABILI ==========================
  287. Vars:
  288.     entryDone(false),    // flag per evitare più ingressi
  289.     entryYear(0),        // anno di ingresso per gestire rollover
  290.     entryMonth(0);       // mese di ingresso
  291.  
  292. // ---------------------- RESET FLAG ANNUALE ------------------
  293. if Year(Date) <> entryYear then
  294.     entryDone = false;
  295.  
  296. // ------------------- ENTRATA LONG -------------------
  297. if (Month(Date) = Start_Month) and (DayOfMonth(Date) >= Start_Day) and
  298.    (not entryDone) and (not Only_short) and (MarketPosition = 0) then
  299. begin
  300.     buy ("Long Mese") nr_share contracts next bar at market;
  301.     entryDone = true;
  302.     entryMonth = Month(Date);
  303.     entryYear  = Year(Date);
  304. end;
  305.  
  306. // ------------------- USCITA LONG -------------------
  307. Vars: exitDateOK(false);
  308.  
  309. // Controllo se siamo arrivati al giorno/mese di uscita o oltre
  310. exitDateOK = (Year(Date) > entryYear) or
  311.              (Year(Date) = entryYear and Month(Date) > Exit_Month) or
  312.              (Year(Date) = entryYear and Month(Date) = Exit_Month and DayOfMonth(Date) >= Exit_Day);
  313.  
  314. if MarketPosition = 1 and exitDateOK then
  315.     sell ("Exit Long Mese") from entry("Long Mese") next bar at market;
  316.  
  317. // ------------------- ENTRATA SHORT -------------------
  318. if (Month(Date) = Start_Month) and (DayOfMonth(Date) >= Start_Day) and
  319.    (not entryDone) and (not Only_long) and (MarketPosition = 0) then
  320. begin
  321.     sellshort ("Short Mese") nr_share contracts next bar at market;
  322.     entryDone = true;
  323.     entryMonth = Month(Date);
  324.     entryYear  = Year(Date);
  325. end;
  326.  
  327. // ------------------- USCITA SHORT -------------------
  328. if MarketPosition = -1 and exitDateOK then
  329.     buytocover ("Exit Short Mese") from entry("Short Mese") next bar at market;   }
  330.  
  331. // ======================================================================// ======================================================================// ======================================================================
  332.  
  333. // -------------------------------------------------------------
  334. // 7 Test Mensile Doppio Blocco Ingressi In Input Con Uscita In Input Cambio Mese Successivo
  335. // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE INPUT ENTRATA GIORNI FINE MESE 29/30/31 ENTRA APPENA TROVA INPUT / USCITA CAMBIO MESE            
  336. // -----------------------------------------------------------
  337.  
  338. {// ======================= INPUT ===============================
  339. Inputs:
  340.  
  341.     // ----- BLOCCO 1 -----
  342.     Start_Day1(1),       // giorno ingresso blocco 1
  343.     Start_Month1(1),     // mese ingresso blocco 1 (es: 1=Gennaio)
  344.     Exit_Month1(12),     // uscita al cambio mese dopo questo (es: 12=Dicembre → esce 1 Gennaio)
  345.  
  346.     // ----- BLOCCO 2 -----
  347.     Start_Day2(1),       // giorno ingresso blocco 2
  348.     Start_Month2(5),     // mese ingresso blocco 2
  349.     Exit_Month2(11);     // uscita al cambio mese dopo questo (es: 11=Novembre → esce 1 Dicembre)
  350.  
  351.  
  352. // ======================= VARIABILI ==========================
  353. Vars:
  354.  
  355.     // LONG
  356.     entryMonthLong(0),
  357.     entryDoneLongBlock1(false),
  358.     entryDoneLongBlock2(false),
  359.  
  360.     // SHORT
  361.     entryMonthShort(0),
  362.     entryDoneShortBlock1(false),
  363.     entryDoneShortBlock2(false),
  364.  
  365.     // mesi di uscita calcolati
  366.     exitMonthNext1(0),
  367.     exitMonthNext2(0);
  368.  
  369. // ------------------- CALCOLO MESE SUCCESSIVO PER USCITA -------------------
  370. if Exit_Month1 = 12 then
  371.     exitMonthNext1 = 1
  372. else
  373.     exitMonthNext1 = Exit_Month1 + 1;
  374.  
  375. if Exit_Month2 = 12 then
  376.     exitMonthNext2 = 1
  377. else
  378.     exitMonthNext2 = Exit_Month2 + 1;
  379.  
  380. // ====================== BLOCCO 1 - LONG ======================
  381. // ---- INGRESSO LONG BLOCCO 1 ----
  382. if (Month(Date) = Start_Month1) and
  383.    (DayOfMonth(Date) >= Start_Day1) and
  384.    (not entryDoneLongBlock1) and
  385.    (not Only_short) and
  386.    (MarketPosition = 0) then
  387. begin
  388.     buy ("Long Mese 1") nr_share contracts next bar at market;
  389.     entryDoneLongBlock1 = true;
  390.     entryMonthLong = Month(Date);
  391. end;
  392.  
  393. // ---- USCITA LONG BLOCCO 1 ----
  394. if (MarketPosition = 1) and (entryDoneLongBlock1) and (Month(Date) = exitMonthNext1) then
  395. begin
  396.     sell ("Exit Long Mese 1") from entry("Long Mese 1") next bar at market;
  397.     entryDoneLongBlock1 = false;  // reset flag per ingresso futuro
  398. end;
  399.  
  400. // ====================== BLOCCO 1 - SHORT ======================
  401. // ---- INGRESSO SHORT BLOCCO 1 ----
  402. if (Month(Date) = Start_Month1) and
  403.    (DayOfMonth(Date) >= Start_Day1) and
  404.    (not entryDoneShortBlock1) and
  405.    (not Only_long) and
  406.    (MarketPosition = 0) then
  407. begin
  408.     sellshort ("Short Mese 1") nr_share contracts next bar at market;
  409.     entryDoneShortBlock1 = true;
  410.     entryMonthShort = Month(Date);
  411. end;
  412.  
  413. // ---- USCITA SHORT BLOCCO 1 ----
  414. if (MarketPosition = -1) and (entryDoneShortBlock1) and (Month(Date) = exitMonthNext1) then
  415. begin
  416.     buytocover ("Exit Short Mese 1") from entry("Short Mese 1") next bar at market;
  417.     entryDoneShortBlock1 = false;  // reset flag per ingresso futuro
  418. end;
  419.  
  420. // ====================== BLOCCO 2 - LONG ======================
  421. // ---- INGRESSO LONG BLOCCO 2 ----
  422. if (Month(Date) = Start_Month2) and
  423.    (DayOfMonth(Date) >= Start_Day2) and
  424.    (not entryDoneLongBlock2) and
  425.    (not Only_short) and
  426.    (MarketPosition = 0) then
  427. begin
  428.     buy ("Long Mese 2") nr_share contracts next bar at market;
  429.     entryDoneLongBlock2 = true;
  430.     entryMonthLong = Month(Date);
  431. end;
  432.  
  433. // ---- USCITA LONG BLOCCO 2 ----
  434. if (MarketPosition = 1) and (entryDoneLongBlock2) and (Month(Date) = exitMonthNext2) then
  435. begin
  436.     sell ("Exit Long Mese 2") from entry("Long Mese 2") next bar at market;
  437.     entryDoneLongBlock2 = false;  // reset flag per ingresso futuro
  438. end;
  439.  
  440. // ====================== BLOCCO 2 - SHORT ======================
  441. // ---- INGRESSO SHORT BLOCCO 2 ----
  442. if (Month(Date) = Start_Month2) and
  443.    (DayOfMonth(Date) >= Start_Day2) and
  444.    (not entryDoneShortBlock2) and
  445.    (not Only_long) and
  446.    (MarketPosition = 0) then
  447. begin
  448.     sellshort ("Short Mese 2") nr_share contracts next bar at market;
  449.     entryDoneShortBlock2 = true;
  450.     entryMonthShort = Month(Date);
  451. end;
  452.  
  453. // ---- USCITA SHORT BLOCCO 2 ----
  454. if (MarketPosition = -1) and (entryDoneShortBlock2) and (Month(Date) = exitMonthNext2) then
  455. begin
  456.     buytocover ("Exit Short Mese 2") from entry("Short Mese 2") next bar at market;
  457.     entryDoneShortBlock2 = false;  // reset flag per ingresso futuro
  458. end;    }  
Advertisement
Add Comment
Please, Sign In to add comment