top of page
Search

Jasper: A Long-based NQ Futures Strategy [Free Code]

The Jasper system is a NQ futures strategy that is designed to execute long positions based on specific technical indicators and conditions tailored for each trading day of the week. By incorporating indicators like the Exponential Moving Average (EMA), Average Directional Movement Index (ADX), and Relative Strength Index (RSI), as well as utilizing stop loss and take profit levels, the strategy aims to identify optimal entry and exit points to maximize potential profits while minimizing risks.


Strategy Performance

Key Metrics


The following performance data assumes trading a single NQ contract and factors in a commission/fee of $2.60 and $10 of slippage per trade. From January 2018 to November 2024, the strategy has generated a net profit of $363K, with a maximum drawdown of $17K. The win rate stands at 57%, and the profit factor is 1.54.


Jasper Equity Curve: 2018 - 2024


Jasper Annual Performance: 2018 - 2024


Jasper Winners: 2018 - 2024


Jasper Losers: 2018 - 2024


Key Features


  • Day-Specific Logic: Customized trading parameters for each weekday (Monday to Friday) to adapt to the unique market conditions typically observed on different days

  • Technical Indicators: Utilizes EMA, ADX, and RSI to determine optimal entries

  • Risk Management: Implements dynamic stop-loss and take-profit levels based on entry prices to protect capital and lock in gains

  • Time-Based Filters: Trades are only executed within predefined time windows for each day, aligning with peak market activity periods


Technical Breakdown


Inputs and Variables


The strategy begins by defining inputs for each weekday, including:

  • Trading Hours: Start and end times for entering trades, and a day exit time to close positions.

  • Indicator Parameters: Specific lengths and thresholds for EMA, ADX, and RSI.

  • Trade Management: Take-profit and stop-loss multipliers, and an entry candle threshold to assess bullish momentum.

    .

Variables are declared to store dynamic values such as the current EMA, ADX, RSI readings, entry price, and calculated stop-loss and take-profit levels.


Day-Specific Logic


For each weekday, the strategy follows a similar structure with parameters customized for that day:

  1. Indicator Calculations: Computes EMA, ADX, and RSI values based on the day's specified lengths.

  2. Entry Conditions:

    • Market Position: Ensures no current open positions (MarketPosition = 0).

    • Time Filter: Checks if the current time is within the designated trading hours.

    • Price Conditions:

      • EMA Filter: Current close price is above the EMA, indicating an uptrend.

      • Entry Candle Threshold: The ratio of close to open price exceeds the specified threshold, suggesting bullish momentum.

      • ADX Threshold: ADX value surpasses the set threshold, indicating strong trend strength.

      • RSI Threshold: RSI value is below the defined threshold, avoiding overbought conditions.

  3. Trade Execution: Places a market order to buy on the next bar and sets the entry price along with stop-loss and take-profit levels.

  4. Exit Conditions:

    • Stop-Loss Exit: Triggers if the price falls to or below the calculated stop-loss level.

    • Take-Profit Exit: Activates when the price reaches or exceeds the take-profit level.

    • Day Exit: Closes the position if the current time reaches the day exit time.


Risk Management


The strategy emphasizes risk management through:

  • Dynamic Stop-Loss: Calculated by multiplying the entry price with the day's stop-loss multiplier.

  • Dynamic Take-Profit: Determined by multiplying the entry price with the day's take-profit multiplier.

  • Time-Based Exits: Ensures all positions are closed by the end of the trading day to avoid overnight risk.


Practical Application


To run a backtest on the Jasper NQ strategy, please follow these steps:


  1. Launch TradeStation Desktop App:

    • Open your TradeStation desktop application.

  2. Add the Jasper Strategy to EasyLanguage:

    • Navigate to the EasyLanguage editor.

    • Create a new strategy file and paste the Jasper NQ strategy code provided.

    • Save the strategy with a recognizable name, such as "Jasper NQ Strategy".

  3. Set Up the Chart:

    • Open a new chart within TradeStation.

    • Enter the symbol @NQ to select the E-mini Nasdaq-100 futures contract.

  4. Configure Chart Settings:

    • Timeframe:

      • Set the chart to use 30-minute bars.

    • Time Zone:

      • Ensure the time zone is set to "Exchange" to align with the exchange's trading hours.

    • Date Range:

      • Set the FirstDate to January 1, 2018 (01/01/2018) to begin the backtest from this date.

  5. Apply the Jasper Strategy to the Chart:

    • Right-click on the chart and select Studies - Add Strategy.

    • Choose the "Jasper NQ Strategy" from your list of strategies.

    • This will run a backtest for Jasper

  6. View Backtest results:

    • Go to Data - Strategy Performance Report

    • Navigate to different performance tabs to see backtest details


EasyLanguage Code


Inputs:

    // Monday Inputs

    MonStartTime(930),

    MonEndTime(2230),

    MonDayExitTime(2300),

    MonEMALength(12),

    MonADXLength(19),

    MonADXThreshold(10),

    MonTakeProfit(1.0115),

    MonStopLoss(0.9856),

    MonEntryCandle(1.0007),

    MonRSILength(30),

    MonRSIThreshold(59),

    MondayTrades(True),


    // Tuesday Inputs

    TueStartTime(800),

    TueEndTime(2000),

    TueDayExitTime(2200),

    TueEMALength(2),

    TueADXLength(15),

    TueADXThreshold(18),

    TueTakeProfit(1.0118),

    TueStopLoss(0.9926),

    TueEntryCandle(1.0012),

    TueRSILength(35),

    TueRSIThreshold(62),

    TuesdayTrades(True),


    // Wednesday Inputs

    WedStartTime(900),

    WedEndTime(1300),

    WedDayExitTime(2100),

    WedEMALength(20),

    WedADXLength(9),

    WedADXThreshold(17),

    WedTakeProfit(1.0118),

    WedStopLoss(0.9913),

    WedEntryCandle(1.001),

    WedRSILength(14),

    WedRSIThreshold(70),

    WednesdayTrades(True),


    // Thursday Inputs

    ThuStartTime(900),

    ThuEndTime(1500),

    ThuDayExitTime(2230),

    ThuEMALength(34),

    ThuADXLength(15),

    ThuADXThreshold(18),

    ThuTakeProfit(1.0079),

    ThuStopLoss(0.9937),

    ThuEntryCandle(1.0009),

    ThuRSILength(14),

    ThuRSIThreshold(70),

    ThursdayTrades(True),


    // Friday Inputs

    FriStartTime(930),

    FriEndTime(1500),

    FriDayExitTime(1530),

    FriEMALength(16),

    FriADXLength(12),

    FriADXThreshold(18),

    FriTakeProfit(1.0157),

    FriStopLoss(0.987),

    FriEntryCandle(1),

    FriRSILength(20),

    FriRSIThreshold(66),

    FridayTrades(True);


Variables:

    EMAValue(0),

    ADXValue(0),

    RSIValue(0),

    MyEntryPrice(0),

    StopLossLevel(0),

    TakeProfitLevel(0);


// Monday Logic

If DayOfWeek(Date) = 1 and MondayTrades then begin

    EMAValue = XAverage(Close, MonEMALength);

    ADXValue = ADX(MonADXLength);

    RSIValue = RSI(Close, MonRSILength);


    If MarketPosition = 0 and Time > MonStartTime and Time < MonEndTime and

       Close > EMAValue and Close / Open > MonEntryCandle and ADXValue > MonADXThreshold and RSIValue < MonRSIThreshold then

    begin

        Buy ("Mon Long Entry") next bar at market;

        MyEntryPrice = Close;

        StopLossLevel = MyEntryPrice * MonStopLoss;

        TakeProfitLevel = MyEntryPrice * MonTakeProfit;

    end;


    If MarketPosition = 1 then begin

        If Low <= StopLossLevel then

            Sell ("Mon Stop Loss Exit") next bar at market;

        If High >= TakeProfitLevel then

            Sell ("Mon Take Profit Exit") next bar at market;

        If Time >= MonDayExitTime then

            Sell ("Mon Day Exit") next bar at market;

    end;

end;


// Tuesday Logic

If DayOfWeek(Date) = 2 and TuesdayTrades then begin

    EMAValue = XAverage(Close, TueEMALength);

    ADXValue = ADX(TueADXLength);

    RSIValue = RSI(Close, TueRSILength);


    If MarketPosition = 0 and Time > TueStartTime and Time < TueEndTime and

       Close > EMAValue and Close / Open > TueEntryCandle and ADXValue > TueADXThreshold and RSIValue < TueRSIThreshold then

    begin

        Buy ("Tue Long Entry") next bar at market;

        MyEntryPrice = Close;

        StopLossLevel = MyEntryPrice * TueStopLoss;

        TakeProfitLevel = MyEntryPrice * TueTakeProfit;

    end;


    If MarketPosition = 1 then begin

        If Low <= StopLossLevel then

            Sell ("Tue Stop Loss Exit") next bar at market;

        If High >= TakeProfitLevel then

            Sell ("Tue Take Profit Exit") next bar at market;

        If Time >= TueDayExitTime then

            Sell ("Tue Day Exit") next bar at market;

    end;

end;


// Wednesday Logic

If DayOfWeek(Date) = 3 and WednesdayTrades then begin

    EMAValue = XAverage(Close, WedEMALength);

    ADXValue = ADX(WedADXLength);

    RSIValue = RSI(Close, WedRSILength);


    If MarketPosition = 0 and Time > WedStartTime and Time < WedEndTime and

       Close > EMAValue and Close / Open > WedEntryCandle and ADXValue > WedADXThreshold and RSIValue < WedRSIThreshold then

    begin

        Buy ("Wed Long Entry") next bar at market;

        MyEntryPrice = Close;

        StopLossLevel = MyEntryPrice * WedStopLoss;

        TakeProfitLevel = MyEntryPrice * WedTakeProfit;

    end;


    If MarketPosition = 1 then begin

        If Low <= StopLossLevel then

            Sell ("Wed Stop Loss Exit") next bar at market;

        If High >= TakeProfitLevel then

            Sell ("Wed Take Profit Exit") next bar at market;

        If Time >= WedDayExitTime then

            Sell ("Wed Day Exit") next bar at market;

    end;

end;


// Thursday Logic

If DayOfWeek(Date) = 4 and ThursdayTrades then begin

    EMAValue = XAverage(Close, ThuEMALength);

    ADXValue = ADX(ThuADXLength);

    RSIValue = RSI(Close, ThuRSILength);


    If MarketPosition = 0 and Time > ThuStartTime and Time < ThuEndTime and

       Close > EMAValue and Close / Open > ThuEntryCandle and ADXValue > ThuADXThreshold and RSIValue < ThuRSIThreshold then

    begin

        Buy ("Thu Long Entry") next bar at market;

        MyEntryPrice = Close;

        StopLossLevel = MyEntryPrice * ThuStopLoss;

        TakeProfitLevel = MyEntryPrice * ThuTakeProfit;

    end;


    If MarketPosition = 1 then begin

        If Low <= StopLossLevel then

            Sell ("Thu Stop Loss Exit") next bar at market;

        If High >= TakeProfitLevel then

            Sell ("Thu Take Profit Exit") next bar at market;

        If Time >= ThuDayExitTime then

            Sell ("Thu Day Exit") next bar at market;

    end;

end;


// Friday Logic

If DayOfWeek(Date) = 5 and FridayTrades then begin

    EMAValue = XAverage(Close, FriEMALength);

    ADXValue = ADX(FriADXLength);

    RSIValue = RSI(Close, FriRSILength);


    If MarketPosition = 0 and Time > FriStartTime and Time < FriEndTime and

       Close > EMAValue and Close / Open > FriEntryCandle and ADXValue > FriADXThreshold and RSIValue < FriRSIThreshold then

    begin

        Buy ("Fri Long Entry") next bar at market;

        MyEntryPrice = Close;

        StopLossLevel = MyEntryPrice * FriStopLoss;

        TakeProfitLevel = MyEntryPrice * FriTakeProfit;

    end;


    If MarketPosition = 1 then begin

        If Low <= StopLossLevel then

            Sell ("Fri Stop Loss Exit") next bar at market;

        If High >= TakeProfitLevel then

            Sell ("Fri Take Profit Exit") next bar at market;

        If Time >= FriDayExitTime then

            Sell ("Fri Day Exit") next bar at market;

    end;

end;


 
 
 

Recent Posts

See All
bottom of page