ProRealCode - Trading & Coding with ProRealTime™
Hi all,
Newbie here with creating PRT strategies and would really welcome feedback on my first effort.
I am developing a strategy for 5 minute candles on DAX.
The concept is such:
Code below and screenshots of results attached. Results use a risk of 1% with compounding.
Would really appreciate a critical review to determine if this is worth pursuing?
Many thanks
Chip
//Defining variables
ma21 = average [21] (close)
Shortentryprice = low - 2 //Entries taken when low of prior candle is surpassed
Longentryprice = high + 2 //Entries taken when high of prior candle is surpassed
myrsi = RSI [14] (close)
lowestrsi = lowest [20] (myrsi) //Sets to lowest RSI reading for past 20 candles
highestrsi = highest [20] (myrsi) //Sets to highest RSI reading for past 20 candles
Mylongsetup= 1 //This variable is used to determine if a long trade is entered; if set to 0 an entry will not occur
Myshortsetup = 1 //As for above for short setups
//Setting stops and targets
stoplongpoints = longentryprice - low
stopshortpoints = high - shortentryprice
targetlongpoints = stoplongpoints*2 //RR for long trades can be set here
targetshortpoints = stopshortpoints*2 //RR for short trades can be set here
//Detecting RSI extreme
If lowestRSI > 20 then //Cancels long entry by setting mylongsetup to 0 if lowest RSI reading for past 20 candles > 20. I.e. there has been no extreme
mylongsetup = 0
endif
If highestrsi < 80 then //As above but for an extreme of above 80 on RSI
myshortsetup = 0
endif
//Detecting close beyond 21
If close < ma21 then //Cancels long entry if close beyond 21 hasn't occured.
mylongsetup = 0
endif
If close < ma21 then //As above for short
mylongsetup = 0
endif
//Don't take at end of the week
If currentdayofweek = 5 AND currenttime = 215500 then
mylongsetup = 0
myshortsetup = 0
endif
// Money Management
Capital = 10000
Risk = 0.01
If mylongsetup = 1 then
stoploss = stoplongpoints
endif
If myshortsetup = 1 then
stoploss = stopshortpoints
endif
//Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
//Entry conditions
IF NOT LongOnMarket AND mylongsetup = 1 THEN
BUY positionsize lot AT longentryprice stop
set stop ploss stoplongpoints
set target pprofit targetlongpoints
endif
IF NOT shortOnMarket AND myshortsetup = 1 THEN
sellshort positionsize lot AT Shortentryprice stop
set stop ploss stopshortpoints
set target pprofit targetshortpoints
endif
Hey looks good esp for a first attempt and doesn’t blow the Account on OOS Test (over the 1st 100k bars provided by Francesco).
Looks like it has a bias towards a rising market, but even so it holds up (no big losses) in that downtrend end June 19 to late Aug 19. Might just need re-optimising as / when the market turns down?
I’m going to try it on my Platform
Thank You for sharing
Mmm … attached is what I get Lot size = 1 … and I didn’t get same as you anyway even with Lot Size same as you had it?
I can’t think why my results are different than yours? I’ve only had 2 stubby bottles of beer! 🙂
It’s always best to get a System running as best you can with Lot Size = 1 as compounding can hides problems
Hi @DR Chips
My initial thought is that the numbers of contracts traded are scary and looking at IG.com if you had the stomach for 100+ contracts you system would not have the margin based on the starting capital
Based on my own RSI systems I would suggest trading the EU session only as the spreads are closer along with more volume
I am currently having a play with your code but I would suggest looking at the code here: https://www.prorealcode.com/prorealtime-trading-strategies/grinder-eurusd-5-min-intraday-trading-strategy/ it is similar to yours but adds in a trend filter and is a solid basis across multiple time frames and products
Systems are always worth pursuing as producing them is always a learning experience and any system should be run on a demo account so that you can have an indication as to how it will perform in real life as opposed to a back test and have a feel for it before risking any actual cash
//UK CodeFIN 1 candle delay
DEFPARAM FLATBEFORE = 080000
DEFPARAM FLATAFTER = 163000
//Defining variables
ma21 = average [21] (close)
Shortentryprice = low - 2 //Entries taken when low of prior candle is surpassed
Longentryprice = high + 2 //Entries taken when high of prior candle is surpassed
myrsi = RSI [14] (close)
lowestrsi = lowest [20] (myrsi) //Sets to lowest RSI reading for past 20 candles
highestrsi = highest [20] (myrsi) //Sets to highest RSI reading for past 20 candles
Mylongsetup= 1 //This variable is used to determine if a long trade is entered; if set to 0 an entry will not occur
Myshortsetup = 1 //As for above for short setups
//Setting stops and targets
stoplongpoints = 20
stopshortpoints = 10
targetlongpoints = 80
targetshortpoints = 20
//Detecting RSI extreme
If lowestRSI > 20 then //Cancels long entry by setting mylongsetup to 0 if lowest RSI reading for past 20 candles > 20. I.e. there has been no extreme
mylongsetup = 0
endif
If highestrsi < 80 then //As above but for an extreme of above 80 on RSI
myshortsetup = 0
endif
//Detecting close beyond 21
If close < ma21 then //Cancels long entry if close beyond 21 hasn't occured.
mylongsetup = 0
endif
If close [1] < ma21 then //As above for short
myshortsetup = 0
endif
//Don't take at end of the week
If currentdayofweek = 5 AND currenttime = 215500 then
mylongsetup = 0
myshortsetup = 0
endif
// Money Management
//Capital = 10000
//Risk = 0.01
//
//If mylongsetup = 1 then
//stoploss = stoplongpoints
//endif
//
//If myshortsetup = 1 then
//stoploss = stopshortpoints
//endif
//Calculate contracts
//equity = Capital + StrategyProfit
//maxrisk = round(equity*Risk)
//PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
//Entry conditions
IF NOT LongOnMarket AND mylongsetup = 1 THEN
BUY 1 lot AT longentryprice stop
set stop ploss stoplongpoints
set target pprofit targetlongpoints
endif
IF NOT shortOnMarket AND myshortsetup = 1 THEN
sellshort 1 lot AT Shortentryprice stop
set stop ploss stopshortpoints
set target pprofit targetshortpoints
endif
Hi @Dr Chips
In your original code line 38 appears to have mylongsetup repeated rather than myshortsetup
The code above is a bit over optimised but it’s nearly midnight so please forgive me
Looking at your results I have changed the system to only trade in the EU session (Lines 1+2) and worked on the stops and take profits (lines 18-21), the attachments compare the original code to the code inserted above
Besides the EU session change one thing I noticed but haven’t got into yet is the timings of the trades, if you look at the opening and closing times of the trades it appears that trade 1 will open and close either with profit or loss then the system waits 5-10 minutes and then trade 2 is placed and so on. This happens with codes that have a prevailing condition in this system the RSI property and can cause several consecutive losses
I also added a delay on line 40 of the above code to short positions
One of the things that I need to do is to put together a video of taking some code and working on it and fully testing it, if it is okay with you then I could do that for this code?
Morning all,
Really appreciate your comments and responses here.
Grahal – I wouldn’t know either why your results are different I’m afraid… as I said, I’m very much a newbie! So even without the beers I’m still struggling to get my head around things!!
Robo Futures Trader – thanks very much for your input on things. I’m going to take some time later to properly read through what you have done here (and do a fair amount of googling to explore further) but yes do please feel free to use as an example for a video – that would be really helpful, thank you!
Many thanks all
Chip
Just had a quick look re your point about the duplication on line 38 @Robo Futures Trade
Yup, this is an error! Have changed this and reposting my (now correct) original code and results below for reference.
//Defining variables
ma21 = average [21] (close)
Shortentryprice = low - 2 //Entries taken when low of prior candle is surpassed
Longentryprice = high + 2 //Entries taken when high of prior candle is surpassed
myrsi = RSI [14] (close)
lowestrsi = lowest [20] (myrsi) //Sets to lowest RSI reading for past 20 candles
highestrsi = highest [20] (myrsi) //Sets to highest RSI reading for past 20 candles
Mylongsetup= 1 //This variable is used to determine if a long trade is entered; if set to 0 an entry will not occur
Myshortsetup = 1 //As for above for short setups
//Setting stops and targets
stoplongpoints = longentryprice - low
stopshortpoints = high - shortentryprice
targetlongpoints = stoplongpoints*2 //RR for long trades can be set here
targetshortpoints = stopshortpoints*2 //RR for short trades can be set here
//Detecting RSI extreme
If lowestRSI > 20 then //Cancels long entry by setting mylongsetup to 0 if lowest RSI reading for past 20 candles > 20. I.e. there has been no extreme
mylongsetup = 0
endif
If highestrsi < 80 then //As above but for an extreme of above 80 on RSI
myshortsetup = 0
endif
//Detecting close beyond 21
If close < ma21 then //Cancels long entry if close beyond 21 hasn't occured.
mylongsetup = 0
endif
If close > ma21 then //As above for short
myshortsetup = 0
endif
//Don't take at end of the week
If currentdayofweek = 5 AND currenttime = 215500 then
mylongsetup = 0
myshortsetup = 0
endif
// Money Management
Capital = 10000
Risk = 0.01
If mylongsetup = 1 then
stoploss = stoplongpoints
endif
If myshortsetup = 1 then
stoploss = stopshortpoints
endif
//Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
//Entry conditions
IF NOT LongOnMarket AND mylongsetup = 1 THEN
BUY positionsize lot AT longentryprice stop
set stop ploss stoplongpoints
set target pprofit targetlongpoints
endif
IF NOT shortOnMarket AND myshortsetup = 1 THEN
sellshort positionsize lot AT Shortentryprice stop
set stop ploss stopshortpoints
set target pprofit targetshortpoints
endif
Why are you not showing Lot size under your equity curves?
Position size is needed else it is only half a story.
It be sooo much better if you delete the RSI Chart and add back in the positions Chart.
An average gain of £22.45 does not mean much unless we know how many open positions we need to lose sleep over!? 🙂
Like this?
Yeah that’s it thank you.
We can now see how much stress there would be to make £10K ish profit (£7.6k to date) over 18 months.
It seems like a simple strategy but in reality there are fourteen possible variables that can be optimised that cover the following areas:
As it is on a five minute time frame that leaves us with a not very big data sample and a big possibility of curve fitting due to so many variables. I would try optimising each variable independently to see how quickly the strategy falls apart with different values for each of them and then when you spot which variables have the biggest effect then test combinations of them.
hello Dr Chips, hope you are in a good shape, how does the strategy work now? do you have any improvement for eur / usd use? cordially
hello Dr Chips, hope you are in a good shape, how does the strategy work now? do you have any improvement for eur / usd use? cordially
The code from the first postig doesn´t work on my desk. The result from my backtest.
Dax 5 minute RSI extreme Strategy Feedback Please
This topic contains 14 replies,
has 7 voices, and was last updated by VinzentVega
5 years, 6 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 01/25/2020 |
| Status: | Active |
| Attachments: | 17 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.