Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ============================================================
- // *** STUDY AZIONARIO NASDAQ MULTI TICKER TREND LONG 1440 MIN *** //
- // ============================================================
- // ============================================================
- // TIPO STRATEGIA: TREND
- // STRUMENTO: AZIONARIO NASDAQ MULTI TICKER
- // TICKER: TRADESTATION 100 TICKER NASDAQ CSV IN CARTELLA
- // TIMEFRAME: 1440 MIN
- // DATI: TRADESTATION DAL 01/01/2006 AL 01/04/2026
- // SESSIONI: EXCHANGE TIME
- // LUN-LUN 09:30 - 16:00 SESSION END YES
- // MAR-MAR 09:30 - 16:00 SESSION END YES
- // MER-MER 09:30 - 16:00 SESSION END YES
- // GIO-GIO 09:30 - 16:00 SESSION END YES
- // VEN-VEN 09:30 - 16:00 SESSION END YES
- // MINI PAUSA : NO
- // BARS BACK: 200
- // COMMISSIONI SVILUPPO: 0
- // COMMISSIONI DOPO SVILUPPO: 1$, 2$ TOT, 2 TICK SLIPPAGE
- // POSITION SIZE SVILUOPPO 10000 / CLOSE
- // CORRELAZIONI STRUMENTI: S&P 500 / RUSSEL 2000
- // ============================================================
- // ==================LONG======================================
- // DESCRIZIONE INGRESSO: UNA PERCENTUALE DEI TITOLI NASDAQ È SOPRA NUOVI 52W HIGH / CLOSE > SMA / SUPERTREND / PATTERN INCLUSIONE SETTIMANALE / PATTERN ESCLUSIONE SETTIMANALE
- // DESCRIZIONE USCITA: CLOSE CROSS UNDER LEADLINE2 E CONVERSIONELINE > LEADLINE / NO SUPERTREND / TRAILING STOP PERCENTUALE
- // ESCLUSIONI: MESI/GIORNI/ORE NESSUNA
- // ============================================================
- // ============================== ============================== ============================== ==============================
- // ============================================================================
- // MARKET REGIME HLIDX - INDICATOR VERSION
- // ============================================================================
- Inputs:
- Len(10),
- UseEMA(1),
- OffsetPct(50);
- Vars:
- Highs(0),
- Lows(0),
- Ratio(0),
- HLIDX(0),
- BreadthOK(false);
- // =========================
- // CALCOLO SOLO SE DATA2 DISPONIBILE
- // =========================
- If BarNumber of Data2 >= Len then begin
- Highs = High of Data2;
- Lows = Low of Data2;
- // Ratio
- If (Highs + Lows) > 0 then
- Ratio = Highs / (Highs + Lows)
- else
- Ratio = 0;
- // Smooth
- If UseEMA = 1 then
- HLIDX = XAverage(Ratio, Len) * 100
- else
- HLIDX = Average(Ratio, Len) * 100;
- // Regime boolean (stesso della strategy)
- If HLIDX > OffsetPct then
- BreadthOK = true
- else
- BreadthOK = false;
- end
- else begin
- HLIDX = 0;
- BreadthOK = false;
- end;
- // ============================================================================
- // PLOT MARKET REGIME HLIDX - INDICATOR VERSION
- // ============================================================================
- // linea indice
- Plot1(HLIDX, "HLIDX");
- // linea soglia regime
- Plot2(OffsetPct, "Threshold");
- // colore regime ON/OFF identico alla strategy
- If BreadthOK then
- SetPlotColor(1, Green)
- else
- SetPlotColor(1, Red);
- // ============================== ============================== ============================== ==============================
- // ============================================================================
- // SIMPLE MOVING AVERAGE – INDICATOR VERSION
- // ============================================================================
- Inputs:
- LongLen(200);
- Vars:
- LongMA(0);
- LongMA = Average(Close, LongLen);
- // ============================================================================
- // PLOT SIMPLE MOVING AVERAGE
- // ============================================================================
- Plot3(LongMA, "LongMA");
- SetPlotColor(3, Yellow);
- // ============================== ============================== ============================== ==============================
- // ============================================================================
- // ICHIMOKU – INDICATOR VERSION
- // ============================================================================
- // =========================
- // INPUTS
- // =========================
- Inputs:
- ConversionPeriods(9), // Periodi per la linea di conversione (Tenkan)
- BasePeriods(26), // Periodi per la linea base (Kijun)
- TenkanLen(5), // Periodi per calcolo slope Tenkan
- LeadLine2LowPeriods(26), // Periodi low per Leading Span 2 (più veloce)
- SpanBPeriods(52); // Periodi high-low per Span B
- // =========================
- // VARS
- // =========================
- Vars:
- ConversionLine(0), // Linea di conversione (Tenkan)
- BaseLine(0), // Linea base (Kijun)
- LeadLine1(0), // Leading Span 1
- LeadLine2(0), // Leading Span 2
- SpanA(0), // Span A
- Kijun(0), // Kijun temporanea
- Tenkan(0), // Tenkan temporanea
- Slope(0); // Slope Tenkan
- // =========================
- // CALCOLI DONCHIAN LINES
- // =========================
- ConversionLine = (Lowest(Low, ConversionPeriods) + Highest(High, ConversionPeriods)) / 2;
- BaseLine = (Lowest(Low, BasePeriods) + Highest(High, BasePeriods)) / 2;
- // =========================
- // CALCOLI LEADING SPANS
- // =========================
- LeadLine1 = (ConversionLine + BaseLine) / 2;
- LeadLine2 = (Lowest(Low, LeadLine2LowPeriods) + Highest(High, SpanBPeriods)) / 2;
- // =========================
- // TENKAN & SLOPE
- // =========================
- Tenkan = (Highest(High,9) + Lowest(Low,9)) / 2;
- Slope = Tenkan - Tenkan[TenkanLen];
- // =========================
- // SPAN A
- // =========================
- SpanA = (Tenkan + Kijun) / 2;
- // ============================================================================
- // PLOT ICHIMOKU
- // ============================================================================
- Plot4(ConversionLine, "Conversion"); // Linea di conversione (Tenkan)
- SetPlotColor(4, Cyan);
- //Plot5(BaseLine, "Base"); // Linea base (Kijun)
- //SetPlotColor(5, Magenta);
- //Plot6(LeadLine1, "Lead1"); // Leading Span 1
- //SetPlotColor(6, Green);
- Plot7(LeadLine2, "LeadLine2"); // Leading Span 2
- SetPlotColor(7, Magenta);
- // ============================== ============================== ============================== ==============================
- // ============================================================================
- // SUPERTREND – INDICATOR VERSION
- // ============================================================================
- // =========================
- // INPUTS
- // =========================
- Inputs:
- atrPeriod(10), // Periodi ATR
- factor(3); // Moltiplicatore ATR (anche 2.1 va bene)
- // =========================
- // VARS
- // =========================
- Vars:
- atr(0), // ATR corrente
- upperBand(0), // Banda superiore base
- lowerBand(0), // Banda inferiore base
- finalUpper(0), // Upper band trailing
- finalLower(0), // Lower band trailing
- supertrend(0), // Valore SuperTrend
- direction(0); // Direzione trend: -1 = uptrend, +1 = downtrend
- // =========================
- // CALCOLO ATR
- // =========================
- atr = AvgTrueRange(atrPeriod);
- // =========================
- // CALCOLO BANDE BASE
- // =========================
- upperBand = (High + Low) / 2 + factor * atr;
- lowerBand = (High + Low) / 2 - factor * atr;
- // =========================
- // INIZIALIZZAZIONE
- // =========================
- if CurrentBar = 1 then begin
- finalUpper = upperBand;
- finalLower = lowerBand;
- direction = 1; // downtrend iniziale
- end
- else begin
- // --- Upper band trailing ---
- if upperBand < finalUpper[1] or Close[1] > finalUpper[1] then
- finalUpper = upperBand
- else
- finalUpper = finalUpper[1];
- // --- Lower band trailing ---
- if lowerBand > finalLower[1] or Close[1] < finalLower[1] then
- finalLower = lowerBand
- else
- finalLower = finalLower[1];
- // --- Direzione ---
- if supertrend[1] = finalUpper[1] then begin
- if Close > finalUpper then
- direction = -1 // uptrend
- else
- direction = 1; // downtrend
- end
- else begin
- if Close < finalLower then
- direction = 1 // downtrend
- else
- direction = -1; // uptrend
- end;
- end;
- // =========================
- // VALORE SUPERTREND
- // =========================
- if direction = -1 then
- supertrend = finalLower
- else
- supertrend = finalUpper;
- // ============================================================================
- // PLOT SUPERTREND
- // ============================================================================
- // Plot8 = SuperTrend sul grafico principale (overlay)
- Plot8(supertrend, "SuperTrend");
- // Colori: verde = uptrend, rosso = downtrend
- if direction = -1 then
- SetPlotColor(8, Green)
- else
- SetPlotColor(8, Red);
- // ============================== ============================== ============================== ==============================
- // ============================================================================
- // PTNBASESA LY WEEKLY 23
- // ============================================================================
- var: PtnBaseSA23(false), minimo_uno_weekly(0), minimo_cinque_weekly(0);
- // --- valori settimanali ---
- minimo_uno_weekly = loww(1); // low della settimana scorsa
- minimo_cinque_weekly = loww(5); // low delle ultime 5 settimane
- // --- confronto booleano ---
- PtnBaseSA23 = (minimo_uno_weekly < minimo_cinque_weekly);
- // ============================================================================
- // PLOT PTNBASESA LY WEEKLY 23
- // ============================================================================
- // --- plot booleano (1 = true, 0 = false) ---
- if PtnBaseSA23 then
- Plot9(1, "Ptn Inclusione")
- else
- Plot9(0);
- SetPlotColor(9, RGB(255,165,0)); // Orange
- // ============================== ============================== ============================== ==============================
- // ============================================================================
- // PTNBASESA LN WEEKLY 21
- // ============================================================================
- var: PtnBaseSA21(false), massimo_uno_weekly(0), massimo_cinque_weekly(0);
- // --- valori settimanali ---
- massimo_uno_weekly = highw(1); // high della settimana scorsa
- massimo_cinque_weekly = highw(5); // high delle ultime 5 settimane
- // --- confronto booleano invertito: 1 quando NOT PtnBaseSA21 ---
- PtnBaseSA21 = (massimo_uno_weekly > massimo_cinque_weekly);
- // ============================================================================
- // PLOT PTNBASESA LN WEEKLY 21
- // ============================================================================
- // --- plot booleano (1 = true, 0 = false) ---
- if not PtnBaseSA21 then
- Plot10(1, "Ptn Esclusione")
- else
- Plot10(0);
- SetPlotColor(10, RGB(255,165,0)); // Orange
Advertisement