Strategy mini S&P, 5 minute Conversion of code from the Tradestation

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #188582 quote
    jjn09010
    Participant
    New

    Strategy Rules – Plain English
    1. Set up your chart with the mini S&P, 5 minute chart, starting at 8:30 AM Exchange time, and ending at 3:15 PM.
    2. Record the open of the first bar of the day, and refer to it as “openp”
    3. At the close of the second bar of the day (at 8:40 AM) go long if:
    A. The low of bar 2 is greater than openp
    B. The 5 bar RSI indicator is below 50 OR both the close if greater than previous bar close AND the close if greater than close 2 bars ago AND the daily close is less than the daily close 2 bars ago
    4. At the close of the second bar of the day (at 8:40 AM) go short if:
    A. The high of bar 2 is less than openp
    B. The 5 bar RSI indicator is above 50 OR both the close if less than previous bar close AND the close if less than close 2 bars ago AND the daily close is greater than the daily close 2 bars ago
    5. If you are in a short trade, and the time is after than 11:00 AM and the position is profitable, exit at the open of the next bar.
    6. Have a stop loss at “stopl” points from entry. As of 2021, the value of stopl is 50 points. This parameter has to be updated every year, using walkforward analysis.
    7. If neither rule 5 nor rule 6 is hit, stay in the trade until either is hit, or the trade reverses via rules 3 or 4.
    8. To add the volatility filter:
    A. Use the variable CANTRADE to allow trading (or not). When CANTRADE=True, then trading can occur.
    B. If the true range of the daily bar is greater than the average true range of the last 5 daily bars, then:
    1. No new trades can be entered
    2. Any existing trades should be closed out
    C. If the true range condition is not met, then trading should proceed as usual.

     

    Strategy Rules – Tradestation Format
    Here is the strategy, in Tradestation Easy Language format:
    Use @ES.D or @MES.D 5 minute bars, with Exchange time for the chart.
    //based on Art Collins webinar
    //modifications by Kevin J. Davey
    //
    //
    // http://www.kjtradingsystems.com
    // kdavey@kjtradingsystems.com
    //
    //Development completed June 30, 2019
    //
    //ATR “Can Trade” Switch added March 2020
    // See video for details: https://youtu.be/BzyijasW7gI
    //
    //
    //non symmetrical exit (OK for stock indices)
    {Chart Info:
    Symbol#1 @MES.D, @ES.D
    Bar Length 5 min
    Symbol#1 @ES.D
    Bar Length Daily
    Start Date 1/1/2012
    End Date present
    Session regular
    Strategy Name:
    Strategy – Properties For All:
    General Tab
    Commission (per Share/Contract) .64 MES, 2.5 ES
    Position Slippage (per Share/Contract) 1.25 MES, 12.5 ES
    Back Testing Resolution check/not checked not checked, 1 min bars
    Details if checked
    Max Number of bars study will reference 50
    Position limits checked/not checked not checked
    Details if checked
    Backtesting Tab
    “Fill Entire Order when trade price exceeds limit price” must be chosen
    Walkforward Optimization:
    Total Iterations: 7
    IN Period (trading days): 504
    Out Period (trading days): 252
    Fitness Function: net profit
    Anchored/Unanchored: unanchored
    Parameters, Ranges:
    Stopl=20-50, step 5
    Additional/Extra Info:
    }
    input:CanSwitch(1); //=0 with no ATR on/off switch, =1 with ATR on/off switch
    variables:
    stopL ( 0 );
    if date >= 1140107 and date < 1150107 then
    begin
    stopL = 40 ;
    end ;
    if date >= 1150107 and date < 1160107 then
    begin
    stopL = 40 ;
    end ;
    if date >= 1160107 and date < 1170106 then
    begin
    stopL = 35 ;
    end ;
    if date >= 1170106 and date < 1180108 then
    begin
    stopL = 35 ;
    end ;
    if date >= 1180108 and date < 1190109 then
    begin
    stopL = 40 ;
    end ;
    if date >= 1190109 and date < 1200109 then
    begin
    stopL = 40 ;
    end ;
    if date >= 1200109 and date < 1210109 then
    begin
    stopL = 50 ;
    end ;
    if date >= 1210109 and date < 1220109 then //dates in latest walkforward off, but results same
    begin
    stopL = 50 ;
    end ;
    var: openp(2),CANTRADE(TRUE);
    CANTRADE=TRUE;
    If CanSwitch=1 and TrueRange of data2>AvgTrueRange(5) of data2 then CANTRADE=FALSE;
    if date >= 1140107 and CANTRADE=True THEN begin
    If time=835 then openp=open;
    If time=840 then begin
    If low>openp and (RSI(close,5)<50 or (c>c[1] and c>c[2])) and close of data2 < Close[2] of data2 then begin
    buy next bar at market;
    end;
    If high<openp and (RSI(close,5)>50 or (c<c[1] and c<c[2]) ) and close of data2 > Close[2] of data2 then begin
    sellshort next bar at market;
    end;
    end;
    If time>=1100 and openpositionprofit>0 then begin
    Buytocover next bar at market;
    end;
    setstoploss(stopl*BigPointValue);
    If stopl=50 then setstoploss(stopl*BigPointValue*50); //very high stop loss
    end;
    If CANTRADE=False then begin
    Sell next bar at market;
    Buytocover next bar at market;
    End;

    #188619 quote
    robertogozzi
    Moderator
    Master

    Ok, I’ll code it asap.

    jjn09010 thanked this post
    #188673 quote
    jjn09010
    Participant
    New

    Cool! Thanks Roberto 🙂

    #188888 quote
    robertogozzi
    Moderator
    Master

    There you go:

    // https://www.prorealcode.com/topic/conversion-of-code-from-the-tradestation/
    //
    Timeframe(Daily,Default)
    myTR  = TR(close)
    myATR = AverageTrueRange[5](close)
    //
    Timeframe(5 Minute,UpdateOnClose)
    ONCE stopl    = 50
    ONCE CanTrade = 1
    //
    CanTrade    = myTR <= myATR
    IF CanTrade = 0 AND OnMarket THEN
       EXITSHORT at Market
       SELL      at Market
    ENDIF
    //
    Rsi5 = Rsi[5](close)
    IF OpenTime = 083000 THEN
       OpenP = open
    ENDIF
    // - LONG  conditions
    L1    = OpenTime = 083500
    L2    = low  > openP
    L3a   = Rsi5 < 50
    L3b   = close > close[1]
    L3c   = close > close[2]
    L3d   = Dclose(0) < Dclose(0)[2]
    L3    = L3a OR (L3b AND L3c AND L3d)
    Lcond = L1 AND L2 AND L3 AND Not LongOnMarket  AND CanTrade
    // - SHORT conditions
    S1    = L1
    S2    = high < openP
    S3a   = Rsi5 > 50
    S3b   = close < close[1]
    S3c   = close < close[2]
    S3d   = Dclose(0) > Dclose(0)[2]
    S3    = S3a OR (S3b AND S3c AND S3d)
    Scond = S1 AND S2 AND S3 AND Not ShortOnMarket  AND CanTrade
    // Entry
    IF Lcond THEN
       BUY 1 Contract at Market
    ELSIF Scond THEN
       SellShort 1 Contract at Market
    ENDIF
    SET STOP  pLOSS stopl
    //
    IF time >= 110000 AND PositionPerf > 0  THEN
       EXITSHORT at Market
       SELL      at Market      //comment out this line not to exit LONG trades
    ENDIF

    Your rule 5 states “If you are in a short trade, and the time is after than 11:00 AM and the position is profitable, exit at the open of the next bar“. You did not mention Long trades, but I added both. If you don’t want that rule applied to Long trades, simply remove or comment out line 49.

    Il-Mio-Sistema-SP-500.itf
    #188909 quote
    jjn09010
    Participant
    New

    Super! Thanks Roberto 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Strategy mini S&P, 5 minute Conversion of code from the Tradestation


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
jjn09010 @jjn09010 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by jjn09010
3 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/20/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...