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

Forums ProRealTime English forum ProBuilder support Strategy mini S&P, 5 minute Conversion of code from the Tradestation

Tagged: , ,

Viewing 5 posts - 1 through 5 (of 5 total)
  • #188582

    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

    Ok, I’ll code it asap.

     

    1 user thanked author for this post.
    #188673

    Cool! Thanks Roberto 🙂

    #188888

    There you go:

    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.

     

    #188909

    Super! Thanks Roberto 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login