Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Indicatore Day_Of_Week-Day_of_Month-Month //
- // Decommenta Il Blocco che vuoi usare //
- // ======================================================================
- // INDICATORE DAY_OF_WEEK - DAY_OF_MONTH - MONTH
- // ======================================================================
- // Modalità Calendario
- // Money Management
- // Test Giorno Della Settimana
- // Test Giorno Mensile
- // Test 2 Ingressi Con Pausa
- // Test Mensile
- // ======================================================================
- // ====================================================================== INIZIO INPUTS E VARIABILI PER IL CODICE 1 AL CODICE 3 ====================================================================== //
- Input:
- Only_long(false),
- Only_short(false),
- percent_initial_equity(false),
- InitialCapital(400000),
- percent_risk(25),
- Settimanale(true), // Dom = 0 / Lun = 1 Etc...
- Mensile(false); // 1 / 30 etc...
- inputs: longEntry(1), longExit(4), shortEntry(3), shortExit(5), startPause(5), endPause(15), INIZIO_INPUT_A_BLOCCHI_4("------------INIZIO_INPUT_A_BLOCCHI------------");
- Vars:
- CurrentMonth(0),
- entryDoneLongThisMonth(false),
- entryDoneShortThisMonth(false);
- Vars:
- risk(percent_risk),
- nr_share(0);
- // Calcolo Money Management
- risk = percent_risk/100;
- nr_share = floor((InitialCapital) * risk) / close ; // Entro con il 25% del capitale iniziale
- // 1 Contratto o % Equity Iniziale
- if not percent_initial_equity then
- nr_share = 1;
- // ====================================================================== FINE INPUTS E VARIABILI PER IL CODICE 1 AL CODICE 4 ====================================================================== //
- // -------------------------------------------------------------
- // 1 Test Giorni Della Settimana Ingresso In Input Con Uscita Barra Successiva * SE MANCA GIORNO INPUT INGRESSO SALTA OPERAZIONE / ESCE SEMPRE LA BARRA DOPO *
- // -------------------------------------------------------------
- {if dayofweek(date) = longEntry and Settimanale = true and not Only_short then buy ("Long Sett") nr_share contracts next bar at market;
- if Marketposition = 1 and Settimanale = true and not Only_short then sell ("Chiusura Long Sett") from entry("Long Sett") next bar at market;
- if dayofweek(date) = shortEntry and Settimanale = true and not Only_long then sellshort ("Short Sett") nr_share contracts next bar at market;
- if Marketposition = -1 and Settimanale = true and not Only_long then sell ("Chiusura Short Sett") from entry("Short Sett") next bar at market; }
- // ======================================================================// ======================================================================// ======================================================================
- // -------------------------------------------------------------
- // 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" !!! *
- // -------------------------------------------------------------
- {if dayofweek(date) = longEntry and Settimanale = true and not Only_short then buy ("Long Sett") nr_share contracts next bar at market;
- if dayofweek(date) = longExit and Settimanale = true and not Only_short then sell ("Chiusura Long Sett") from entry("Long Sett") next bar at market;
- if dayofweek(date) = shortEntry and Settimanale = true and not Only_long then sellshort ("Short Sett") nr_share contracts next bar at market;
- if dayofweek(date) = shortExit and Settimanale = true and not Only_long then buytocover ("Chiusura Short Sett") from entry("Short Sett") next bar at market; }
- // ======================================================================// ======================================================================// ======================================================================
- // -------------------------------------------------------------
- // 3 Test Giorni Del Mese Ingresso In Input Con Uscita Giorno Dopo * SE MANCA GIORNO INPUT INGRESSO SALTA OPERAZIONE / ESCE SEMPRE LA BARRA DOPO *
- // -------------------------------------------------------------
- {if dayofmonth(date) = longEntry and Mensile = true and not Only_short then buy ("Long Mens") nr_share contracts next bar at market;
- if Marketposition = 1 and Mensile = true and not Only_short then sell ("Chiusura Long Mens") from entry("Long Mens") next bar at market;
- if dayofmonth(date) = shortEntry and Mensile = true and not Only_long then sellshort ("Short Mens") nr_share contracts next bar at market;
- if Marketposition = -1 and Mensile = true and not Only_long then Buytocover ("Chiusura Short Mens") from entry("Short Mens") next bar at market; }
- // ======================================================================// ======================================================================// ======================================================================
- // -------------------------------------------------------------
- // 4 Test Giorni Del Mese 2 Ingressi In Input con Pausa Con Con Uscita In Input (con gestione calendario mesi da 28–31 giorni)
- // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE MANCA GIORNO INPUT USCITA ESCE BARRA SUCCESSIVA /
- // 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" !!! *
- // -------------------------------------------------------------
- // Calendario:
- {Vars:
- m(0), y(0), last_day_of_month(0);
- // Calcolo mese e anno corrente
- m = Month(Date);
- y = Year(Date);
- // Gestione mesi
- if m = 1 or m = 3 or m = 5 or m = 7 or m = 8 or m = 10 or m = 12 then
- last_day_of_month = 31
- else if m = 4 or m = 6 or m = 9 or m = 11 then
- last_day_of_month = 30
- else begin
- // Febbraio → gestione anni bisestili
- if (Mod(y, 400) = 0) or ((Mod(y, 4) = 0) and (Mod(y, 100) <> 0)) then
- last_day_of_month = 29
- else
- last_day_of_month = 28;
- end;
- Inputs:
- // Long
- longEntry1(1),
- longExit1(6),
- startPauseLong(6),
- endPauseLong(10),
- longEntry2(19),
- longExit2(23),
- // Short
- shortEntry1(10),
- shortExit1(16),
- startPauseShort(16),
- endPauseShort(19),
- shortEntry2(25),
- shortExit2(28);
- Vars:
- // Flags Long
- entryDoneLongBlock1(false),
- entryDoneLongBlock2(false),
- // Flags Short
- entryDoneShortBlock1(false),
- entryDoneShortBlock2(false),
- // Reset mensile
- lastMonthProcessed(0),
- lastYearProcessed(0);
- // -------------------------------------------------------------
- // RESET VARIABILI MENSILI - Robusto per intraday e daily
- // -------------------------------------------------------------
- if (Month(Date) <> lastMonthProcessed) or (Year(Date) <> lastYearProcessed) then begin
- // Long
- entryDoneLongBlock1 = false;
- entryDoneLongBlock2 = false;
- // Short
- entryDoneShortBlock1 = false;
- entryDoneShortBlock2 = false;
- lastMonthProcessed = Month(Date);
- lastYearProcessed = Year(Date);
- end;
- // -------------------------------------------------------------
- // LONG MENSILE (DOPPIO BLOCCO CON PAUSA)
- // -------------------------------------------------------------
- if not Only_short then begin
- // BLOCCO 1 - INGRESSO
- if (not entryDoneLongBlock1) and
- (DayOfMonth(Date) >= longEntry1) and
- (DayOfMonth(Date) < startPauseLong) then begin
- buy ("Long Mens 1") nr_share contracts next bar at market;
- entryDoneLongBlock1 = true;
- end;
- // BLOCCO 1 - USCITA
- if MarketPosition = 1 then begin
- if (DayOfMonth(Date) >= longExit1)
- or (longExit1 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
- sell ("Exit Long Mens 1") from entry("Long Mens 1") next bar at market;
- end;
- // BLOCCO 2 - INGRESSO
- if (not entryDoneLongBlock2) and
- (DayOfMonth(Date) >= longEntry2) and
- (DayOfMonth(Date) >= endPauseLong) then begin
- buy ("Long Mens 2") nr_share contracts next bar at market;
- entryDoneLongBlock2 = true;
- end;
- // BLOCCO 2 - USCITA
- if MarketPosition = 1 then begin
- if (DayOfMonth(Date) >= longExit2)
- or (longExit2 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
- sell ("Exit Long Mens 2") from entry("Long Mens 2") next bar at market;
- end;
- end;
- // -------------------------------------------------------------
- // SHORT MENSILE (DOPPIO BLOCCO CON PAUSA)
- // -------------------------------------------------------------
- if not Only_long then begin
- // BLOCCO 1 - INGRESSO
- if (not entryDoneShortBlock1) and
- (DayOfMonth(Date) >= shortEntry1) and
- (DayOfMonth(Date) < startPauseShort) then begin
- sellshort ("Short Mens 1") nr_share contracts next bar at market;
- entryDoneShortBlock1 = true;
- end;
- // BLOCCO 1 - USCITA
- if MarketPosition = -1 then begin
- if (DayOfMonth(Date) >= shortExit1)
- or (shortExit1 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
- buytocover ("Exit Short Mens 1") from entry("Short Mens 1") next bar at market;
- end;
- // BLOCCO 2 - INGRESSO
- if (not entryDoneShortBlock2) and
- (DayOfMonth(Date) >= shortEntry2) and
- (DayOfMonth(Date) >= endPauseShort) then begin
- sellshort ("Short Mens 2") nr_share contracts next bar at market;
- entryDoneShortBlock2 = true;
- end;
- // BLOCCO 2 - USCITA
- if MarketPosition = -1 then begin
- if (DayOfMonth(Date) >= shortExit2)
- or (shortExit2 > last_day_of_month and DayOfMonth(Date) = last_day_of_month) then
- buytocover ("Exit Short Mens 2") from entry("Short Mens 2") next bar at market;
- end;
- end; }
- // ======================================================================// ======================================================================// ======================================================================
- // -------------------------------------------------------------
- // 5 Test Mensile Ingresso In Input Con Uscita Cambio Mese Successivo
- // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE INPUT ENTRATA GIORNI FINE MESE 29/30/31 ENTRA APPENA TROVA INPUT / USCITA CAMBIO MESE
- // -----------------------------------------------------------
- // ======================= INPUT ===============================
- {Inputs:
- Start_Day(5); // giorno del mese per ingresso
- Start_Month(2), // mese da cui iniziare il test (1=Gen, 2=Feb,...)
- // ======================= VARIABILI ==========================
- Vars:
- entryMonth(0), // memorizza il mese in cui siamo entrati (per uscita)
- entryDoneThisMonth(false); // flag per evitare più ingressi nello stesso mese
- // ---------------------- RESET FLAG MENSILE ------------------
- if Month(Date) <> entryMonth then
- entryDoneThisMonth = false; // un solo trade per mese per direzione
- // ------------------- ENTRATA LONG -------------------
- if (Month(Date) = Start_Month) and (not Only_short) and (not entryDoneThisMonth) and (MarketPosition = 0) and (DayOfMonth(Date) >= Start_Day) then begin
- buy ("Long Mese") nr_share contracts next bar at market;
- entryDoneThisMonth = true;
- entryMonth = Month(Date); // memorizza il mese di ingresso
- end;
- // ------------------- USCITA LONG -------------------
- if (MarketPosition = 1) and (Month(Date) <> entryMonth) then begin
- sell ("Exit Long Mese") from entry("Long Mese") next bar at market;
- end;
- // ------------------- ENTRATA SHORT -------------------
- if (Month(Date) = Start_Month) and (not Only_long) and (not entryDoneThisMonth) and (MarketPosition = 0) and (DayOfMonth(Date) >= Start_Day) then begin
- sellshort ("Short Mese") nr_share contracts next bar at market;
- entryDoneThisMonth = true;
- entryMonth = Month(Date); // memorizza il mese di ingresso
- end;
- // ------------------- USCITA SHORT -------------------
- if (MarketPosition = -1) and (Month(Date) <> entryMonth) then begin
- buytocover ("Exit Short Mese") from entry("Short Mese") next bar at market;
- end; }
- // ======================================================================// ======================================================================// ======================================================================
- // -------------------------------------------------------------
- // 6 Test Mensile Ingresso In Input Con Uscita In Input
- // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE MANCA GIORNO INPUT USCITA ESCE BARRA SUCCESSIVA /
- // 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
- // -----------------------------------------------------------
- // ======================= INPUT ===============================
- {Inputs:
- Start_Day(1), // giorno del mese per ingresso
- Start_Month(1), // mese da cui iniziare il test (1=Gennaio,...)
- Exit_Day(31), // giorno del mese per uscita
- Exit_Month(12); // mese di uscita (1=Gennaio,...)
- // ======================= VARIABILI ==========================
- Vars:
- entryDone(false), // flag per evitare più ingressi
- entryYear(0), // anno di ingresso per gestire rollover
- entryMonth(0); // mese di ingresso
- // ---------------------- RESET FLAG ANNUALE ------------------
- if Year(Date) <> entryYear then
- entryDone = false;
- // ------------------- ENTRATA LONG -------------------
- if (Month(Date) = Start_Month) and (DayOfMonth(Date) >= Start_Day) and
- (not entryDone) and (not Only_short) and (MarketPosition = 0) then
- begin
- buy ("Long Mese") nr_share contracts next bar at market;
- entryDone = true;
- entryMonth = Month(Date);
- entryYear = Year(Date);
- end;
- // ------------------- USCITA LONG -------------------
- Vars: exitDateOK(false);
- // Controllo se siamo arrivati al giorno/mese di uscita o oltre
- exitDateOK = (Year(Date) > entryYear) or
- (Year(Date) = entryYear and Month(Date) > Exit_Month) or
- (Year(Date) = entryYear and Month(Date) = Exit_Month and DayOfMonth(Date) >= Exit_Day);
- if MarketPosition = 1 and exitDateOK then
- sell ("Exit Long Mese") from entry("Long Mese") next bar at market;
- // ------------------- ENTRATA SHORT -------------------
- if (Month(Date) = Start_Month) and (DayOfMonth(Date) >= Start_Day) and
- (not entryDone) and (not Only_long) and (MarketPosition = 0) then
- begin
- sellshort ("Short Mese") nr_share contracts next bar at market;
- entryDone = true;
- entryMonth = Month(Date);
- entryYear = Year(Date);
- end;
- // ------------------- USCITA SHORT -------------------
- if MarketPosition = -1 and exitDateOK then
- buytocover ("Exit Short Mese") from entry("Short Mese") next bar at market; }
- // ======================================================================// ======================================================================// ======================================================================
- // -------------------------------------------------------------
- // 7 Test Mensile Doppio Blocco Ingressi In Input Con Uscita In Input Cambio Mese Successivo
- // * SE MANCA GIORNO INPUT INGRESSO BARRA SUCCESSIVA / SE INPUT ENTRATA GIORNI FINE MESE 29/30/31 ENTRA APPENA TROVA INPUT / USCITA CAMBIO MESE
- // -----------------------------------------------------------
- {// ======================= INPUT ===============================
- Inputs:
- // ----- BLOCCO 1 -----
- Start_Day1(1), // giorno ingresso blocco 1
- Start_Month1(1), // mese ingresso blocco 1 (es: 1=Gennaio)
- Exit_Month1(12), // uscita al cambio mese dopo questo (es: 12=Dicembre → esce 1 Gennaio)
- // ----- BLOCCO 2 -----
- Start_Day2(1), // giorno ingresso blocco 2
- Start_Month2(5), // mese ingresso blocco 2
- Exit_Month2(11); // uscita al cambio mese dopo questo (es: 11=Novembre → esce 1 Dicembre)
- // ======================= VARIABILI ==========================
- Vars:
- // LONG
- entryMonthLong(0),
- entryDoneLongBlock1(false),
- entryDoneLongBlock2(false),
- // SHORT
- entryMonthShort(0),
- entryDoneShortBlock1(false),
- entryDoneShortBlock2(false),
- // mesi di uscita calcolati
- exitMonthNext1(0),
- exitMonthNext2(0);
- // ------------------- CALCOLO MESE SUCCESSIVO PER USCITA -------------------
- if Exit_Month1 = 12 then
- exitMonthNext1 = 1
- else
- exitMonthNext1 = Exit_Month1 + 1;
- if Exit_Month2 = 12 then
- exitMonthNext2 = 1
- else
- exitMonthNext2 = Exit_Month2 + 1;
- // ====================== BLOCCO 1 - LONG ======================
- // ---- INGRESSO LONG BLOCCO 1 ----
- if (Month(Date) = Start_Month1) and
- (DayOfMonth(Date) >= Start_Day1) and
- (not entryDoneLongBlock1) and
- (not Only_short) and
- (MarketPosition = 0) then
- begin
- buy ("Long Mese 1") nr_share contracts next bar at market;
- entryDoneLongBlock1 = true;
- entryMonthLong = Month(Date);
- end;
- // ---- USCITA LONG BLOCCO 1 ----
- if (MarketPosition = 1) and (entryDoneLongBlock1) and (Month(Date) = exitMonthNext1) then
- begin
- sell ("Exit Long Mese 1") from entry("Long Mese 1") next bar at market;
- entryDoneLongBlock1 = false; // reset flag per ingresso futuro
- end;
- // ====================== BLOCCO 1 - SHORT ======================
- // ---- INGRESSO SHORT BLOCCO 1 ----
- if (Month(Date) = Start_Month1) and
- (DayOfMonth(Date) >= Start_Day1) and
- (not entryDoneShortBlock1) and
- (not Only_long) and
- (MarketPosition = 0) then
- begin
- sellshort ("Short Mese 1") nr_share contracts next bar at market;
- entryDoneShortBlock1 = true;
- entryMonthShort = Month(Date);
- end;
- // ---- USCITA SHORT BLOCCO 1 ----
- if (MarketPosition = -1) and (entryDoneShortBlock1) and (Month(Date) = exitMonthNext1) then
- begin
- buytocover ("Exit Short Mese 1") from entry("Short Mese 1") next bar at market;
- entryDoneShortBlock1 = false; // reset flag per ingresso futuro
- end;
- // ====================== BLOCCO 2 - LONG ======================
- // ---- INGRESSO LONG BLOCCO 2 ----
- if (Month(Date) = Start_Month2) and
- (DayOfMonth(Date) >= Start_Day2) and
- (not entryDoneLongBlock2) and
- (not Only_short) and
- (MarketPosition = 0) then
- begin
- buy ("Long Mese 2") nr_share contracts next bar at market;
- entryDoneLongBlock2 = true;
- entryMonthLong = Month(Date);
- end;
- // ---- USCITA LONG BLOCCO 2 ----
- if (MarketPosition = 1) and (entryDoneLongBlock2) and (Month(Date) = exitMonthNext2) then
- begin
- sell ("Exit Long Mese 2") from entry("Long Mese 2") next bar at market;
- entryDoneLongBlock2 = false; // reset flag per ingresso futuro
- end;
- // ====================== BLOCCO 2 - SHORT ======================
- // ---- INGRESSO SHORT BLOCCO 2 ----
- if (Month(Date) = Start_Month2) and
- (DayOfMonth(Date) >= Start_Day2) and
- (not entryDoneShortBlock2) and
- (not Only_long) and
- (MarketPosition = 0) then
- begin
- sellshort ("Short Mese 2") nr_share contracts next bar at market;
- entryDoneShortBlock2 = true;
- entryMonthShort = Month(Date);
- end;
- // ---- USCITA SHORT BLOCCO 2 ----
- if (MarketPosition = -1) and (entryDoneShortBlock2) and (Month(Date) = exitMonthNext2) then
- begin
- buytocover ("Exit Short Mese 2") from entry("Short Mese 2") next bar at market;
- entryDoneShortBlock2 = false; // reset flag per ingresso futuro
- end; }
Advertisement
Add Comment
Please, Sign In to add comment