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
- This topic has 4 replies, 2 voices, and was last updated 2 years ago by jjn09010.
Tagged: sp, sp500, tradestation
-
-
02/20/2022 at 11:01 PM #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;02/21/2022 at 3:59 PM #18861902/22/2022 at 5:39 PM #18867302/26/2022 at 11:57 AM #188888There you go:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// 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 = 50ONCE CanTrade = 1//CanTrade = myTR <= myATRIF CanTrade = 0 AND OnMarket THENEXITSHORT at MarketSELL at MarketENDIF//Rsi5 = Rsi[5](close)IF OpenTime = 083000 THENOpenP = openENDIF// - LONG conditionsL1 = OpenTime = 083500L2 = low > openPL3a = Rsi5 < 50L3b = 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 conditionsS1 = L1S2 = high < openPS3a = Rsi5 > 50S3b = 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// EntryIF Lcond THENBUY 1 Contract at MarketELSIF Scond THENSellShort 1 Contract at MarketENDIFSET STOP pLOSS stopl//IF time >= 110000 AND PositionPerf > 0 THENEXITSHORT at MarketSELL at Market //comment out this line not to exit LONG tradesENDIFYour 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.
02/26/2022 at 3:13 PM #188909 -
AuthorPosts
Find exclusive trading pro-tools on