Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ============================================================
- // *** BOT FUTURES @S SOIA BREAKOUT LONG E SHORT 15 MIN *** //
- // ============================================================
- // ============================================================
- // TIPO STRATEGIA: BREAKOUT SESSIONE PRECEDENTE
- // STRUMENTO: FUTURES
- // TICKER: TRADESTATION @S
- // TIMEFRAME: 15 MIN
- // DATI: TRADESTATION DAL 04/01/2010 AL 27/10/2025
- // SESSIONI: EXCHANGE TIME
- // DOM-LUN 19:00 - 13:20 SESSION END YES
- // LUN-MAR 19:00 - 13:20 SESSION END YES
- // MAR-MER 19:00 - 13:20 SESSION END YES
- // MER-GIO 19:00 - 13:20 SESSION END YES
- // GIO-VEN 19:00 - 13:20 SESSION END YES
- // MINI PAUSA : 07:54 08:30
- // BARS BACK: 50
- // COMMISSIONI SVILUPPO: 0
- // COMMISSIONI DOPO SVILUPPO: 3$, 6 $ TOT, 1 TICK SLIPPAGE
- // POSITION SIZE SVILUOPPO 1 CONTRATTO
- // CORRELAZIONI STRUMENTI: Corn (@C) / Wheat (@W)
- // ============================================================
- // ==================LONG======================================
- // DESCRIZIONE INGRESSO: INGRESSO BREAKOUT MASSIMO SESSIONE PRECEDENTE / INGRESSO FASCE ORARIE / VERIFICA PATTERN DI PREZZO
- // DESCRIZIONE USCITA: NUMERO CANDELE DA ENTRY / STOP LOSS MONETARIO / TAKE PROFIT MONETARIO / TRAILING STOP MONETARIO
- // ESCLUSIONI: MESE SETTEMBRE
- // ============================================================
- // ==================SHORT======================================
- // DESCRIZIONE INGRESSO: INGRESSO BREAKOUT MINIMO SESSIONE PRECEDENTE / INGRESSO FASCE ORARIE / VERIFICA PATTERN DI PREZZO
- // DESCRIZIONE USCITA: NUMERO CANDELE DA ENTRY MINIMO CON ORARIO PREDEFINITO / STOP LOSS MONETARIO / TAKE PROFIT MONETARIO / TRAILING STOP MONETARIO
- // ESCLUSIONI: MESE NESSUNO / SKIP MONTH VALUTABILE: https://www.barchart.com/futures/quotes/ZSF26/seasonality-chart
- // ============================================================
- // ============================================================
- // *** Inizio Parte 1 Study Funzione In-Sample Out-Sample QTA *** //
- // ============================================================
- {---------------- HEADER INIZIO: DA ELIMINARE ----------------}
- Inputs: isSampleOutOfSampleActive(0), displayMode(1);
- if isSampleOutOfSampleActive = 0 or (
- ((displayMode = 1 or displayMode = 3) and isSampleOutOfSampleActive = 1 and ((Date >= 1100103 and Date <= 1152954) or (Date >= 1175607 and Date <= 1228458) or marketposition <> 0)) or
- ((displayMode = 2 or displayMode = 3) and isSampleOutOfSampleActive = 1 and ((Date > 1152955 and Date <= 1175606) or (Date > 1228459 and Date <= 1251110) or marketposition <> 0))) then begin
- {---------------- HEADER FINE: DA ELIMINARE ----------------}
- // *** Fine Parte 1 Study Funzione In-Sample Out-Sample QTA *** //
- // ============================================================
- // LONG
- // ============================================================
- // ============================================================
- // INPUTS LONG
- // ============================================================
- Inputs:
- OnlyLong(false),
- OnlyShort(false),
- StopLossLong(1240),
- TakeProfitLong(2800), // 1085 valutabile ma forse troppo piccolo
- EntryTimeLong(1100),
- EndEntryTimeLong(2030), // Ora fine finestra ingresso anche 1330 va bene
- //ExitTimeLong(200),
- ExitAfterBarsLong(250), // 250 (sono 3 sessioni) e considerando la fascia oraria di ingresso esco circa delle ore 200 o a qualche barra più in là.
- ExcludeMonth1Long(9), // Anche 5 va bene
- BreakEvenPriceLong(2000), // Non rilavantissimo, aiuta in qualche posizione senza dare fastidio
- ProfitBufferLong(800), // Non rilavantissimo, aiuta in qualche posizione senza dare fastidio
- InizioInputShort("------------InizioInputShort------------"),
- //MyPtnLY(14) // Il PtnBaseSA(MyPtnLY) è inserito come: CloseSession(0,1) > CloseSession(0,2)
- // ============================================================
- // INPUTS SHORT
- // ============================================================ ,
- StopLossShort(1050), // RANGE DA (950/1200) DA VALUTARE CON TUTTE LE OTTIMIZZAZIONI !!!
- TakeProfitShort(2125), // 2000 VA ANCHE BENE
- EntryTimeShort(200), // ora inizio finestra ingresso 200/300/400
- EndEntryTimeShort(600), // ora fine finestra ingresso 200/300/400 ATTENZIONE 200 300 STABILE MA SOLO 1 ORA POTREI OVERFITTARE, TROPPO POCO, ALTRIMENTI MI DEVO ALLUNGARE FINO A MX 600 !!! VALUTARE !!!
- ExitTimeShort(1200), // ora uscita 1100/1200
- ExitAfterBarsShort(92), // quante barre dopo l’ingresso esci
- MyPtnSY(41), MyPtnSN(20), // Il PTN 20 Toglie solo pochi trades ma è molto stabile "Opzionale Scelta Personale"
- //ExcludeMonth1Short(10), // Anche se va bene, ci sono 5 mesi che vanno molto bene per il Long allora non metto questo filtro, altra cosa short diventerebbe con troppi pochi trades !!!.
- BreakEvenPriceShort(1800), // Non rilavantissimo, aiuta in qualche posizione senza dare fastidio
- ProfitBufferShort(800); // Non rilavantissimo, aiuta in qualche posizione senza dare fastidio
- //MyPtnSN(20) // Il PtnBaseSA(MyPtnSN) è inserito come: not (HighSession(0,0) > HighSession(0,1))
- // ============================================================
- // VARS LONG
- // ============================================================
- Vars:
- IntraBarPersist InEntryWindow(false),
- IntraBarPersist MaxPriceDuringTradeLong(0), // Massimo prezzo intratrade
- IntraBarPersist BarCounterLong(0),
- BufferPointsLong(0), // Uscita se il prezzo ritraccia
- // ============================================================
- // VARS SHORT
- // ============================================================
- IntraBarPersist InEntryWindowShort(false),
- IntraBarPersist MinPriceDuringTradeShort(0), // Minimo prezzo intratrade
- IntraBarPersist BarCounterShort(0),
- BufferPointsShort(0); // Uscita se il prezzo ritraccia
- // ============================================================
- // LOGICA UNIVERSALE PER FINESTRA ORARIA LONG
- // ============================================================
- // Se la finestra NON attraversa la mezzanotte → usa AND
- If EntryTimeLong < EndEntryTimeLong then
- InEntryWindow = (Time >= EntryTimeLong) and (Time <= EndEntryTimeLong)
- else
- // Se attraversa la mezzanotte (es. 2200→1000) → usa OR
- InEntryWindow = (Time >= EntryTimeLong) or (Time <= EndEntryTimeLong);
- // ============================================================
- // ENTRY LONG
- // ============================================================
- If InEntryWindow and MarketPosition = 0 and month(date) <> ExcludeMonth1Long and not OnlyShort then begin
- If CloseSession(0,1) > CloseSession(0,2) then {PtnBaseSA(MyPtnLY) 14 }
- Buy ("BreakPrevHigh") next bar at HighSession(1,1) stop;
- end;
- // ============================================================
- // USCITA LONG DOPO N BARRE
- // ============================================================
- If MarketPosition = 1 then begin
- BarCounterLong = BarCounterLong + 1;
- If BarCounterLong >= ExitAfterBarsLong {and time >= ExitTimeLong} then begin
- Sell ("ExitAfterBarsLong") next bar at market;
- BarCounterLong = 0;
- end;
- end else
- BarCounterLong = 0;
- // ============================================================
- // STOP LOSS / TAKE PROFIT LONG
- // ============================================================
- If MarketPosition = 1 then begin
- SetStopLoss(StopLossLong);
- SetProfitTarget(TakeProfitLong);
- end;
- // ============================================================
- // BREAKEVEN + BUFFER LONG //
- // ============================================================
- // Conversione $ -> punti (1 punto @S = $50)
- BufferPointsLong = ProfitBufferLong / 50;
- // ============================
- // EXIT BREAKEVEN LONG TRADE
- // ============================
- If MarketPosition = 1 Then Begin
- // Inizio trade: registra massimo intratrade
- If MaxPriceDuringTradeLong = 0 Then
- MaxPriceDuringTradeLong = EntryPrice;
- // Aggiorna massimo intratrade
- If High > MaxPriceDuringTradeLong Then
- MaxPriceDuringTradeLong = High;
- // Attiva breakeven + buffer se profitto raggiunto
- If (MaxPriceDuringTradeLong - EntryPrice) * 50 >= BreakEvenPriceLong Then
- Sell ("BEPlusStopLong") next bar at EntryPrice + BufferPointsLong stop;
- End;
- // ============================
- // RESET variabili alla chiusura del trade per trailing
- // ============================
- If MarketPosition = 0 Then Begin
- MaxPriceDuringTradeLong = 0;
- End;
- // ============================================================
- // SHORT
- // ============================================================
- // ============================================================
- // LOGICA UNIVERSALE PER FINESTRA ORARIA SHORT
- // ============================================================
- // Se la finestra NON attraversa la mezzanotte (es. 02:00 → 06:00) → usa AND
- If EntryTimeShort < EndEntryTimeShort then
- InEntryWindowShort = (Time >= EntryTimeShort) and (Time <= EndEntryTimeShort)
- // Se la finestra attraversa la mezzanotte (es. 22:00 → 03:00) → usa OR
- else
- InEntryWindowShort = (Time >= EntryTimeShort) or (Time <= EndEntryTimeShort);
- // ============================================================
- // TEST ENTRATA SHORT ORARIO CON BREAKOUT
- // ============================================================
- If InEntryWindowShort and MarketPosition = 0 {and month(date) <> ExcludeMonth1Short} and not OnlyLong then begin
- If not (HighSession(0,0) > HighSession(0,1)) then {PtnBaseSA(MyPtnSN) 20}
- SellShort("BreakPrevLow") next bar at LowSession(1,1) stop;
- end;
- // ============================================================
- // USCITA DOPO N BARRE
- // ============================================================
- If MarketPosition = -1 then begin
- BarCounterShort = BarCounterShort + 1;
- If BarCounterShort >= ExitAfterBarsShort and time >= ExitTimeShort then begin // * ATTENZIONE A DIFFERENZA DEL LONG ABBIAMO USCITA BARRE > DI INPUT CON ORARIO FORZATO A INPUT 1200 * //
- Buytocover ("ExitAfterBarsShort") next bar at market;
- BarCounterShort = 0;
- end;
- end else
- BarCounterShort = 0;
- // ============================================================
- // STOP LOSS SHORT / TAKE PROFIT SHORT
- // ============================================================
- If MarketPosition = -1 then begin // Condizione Tk e Sl Solo Per Long, ATTENZIONE GLI ORDINI ENTRANO DOPO LA PRIMA BARRA !!!
- SetStopLoss(StopLossShort);
- SetProfitTarget(TakeProfitShort);
- end;
- // ============================================================
- // BREAKEVEN + BUFFER SHORT
- // ============================================================
- // Conversione $ -> punti (1 punto @S = $50)
- BufferPointsShort = ProfitBufferShort / 50;
- // ============================
- // EXIT BREAKEVEN SHORT TRADE
- // ============================
- If MarketPosition = -1 Then Begin
- // Inizio trade: registra minimo intratrade
- If MinPriceDuringTradeShort = 0 Then
- MinPriceDuringTradeShort = EntryPrice;
- // Aggiorna minimo intratrade
- If Low < MinPriceDuringTradeShort Then
- MinPriceDuringTradeShort = Low;
- // Attiva breakeven + buffer se profitto raggiunto
- If (EntryPrice - MinPriceDuringTradeShort) * 50 >= BreakEvenPriceShort Then
- BuyToCover ("BEPlusStopShort") next bar at EntryPrice - BufferPointsShort stop;
- End;
- // ============================
- // RESET variabili alla chiusura del trade
- // ============================
- If MarketPosition = 0 Then Begin
- MinPriceDuringTradeShort = 0;
- End;
- // ============================================================
- // Inizio Parte 2 Study Funzione In-Sample Out-Sample QTA *** //
- // ============================================================
- {---------------- FOOTER INIZIO: DA ELIMINARE ----------------}
- end;
- {---------------- FOOTER FINE: DA ELIMINARE ----------------}
- // ============================================================
- // *** Fine Parte 2 Study Funzione In-Sample Out-Sample QTA *** //
- // ============================================================
Advertisement
Add Comment
Please, Sign In to add comment