SP500 Optimizer 5min Strategy

SP500 Optimizer 5min Strategy

Good Day

I have been a silent member of this community for quite some time but suppose as time would allow I would try to become more active. I have been developing PRT strategies for almost 2 years now and have quite a few running live and profitable on various indexes and FX Pairs. I still need to get to a point where I can freely share my strategies but still find that slightly difficult (especially knowing some people sell your IP for profit). Anyhow this is just one of the many rabbit hole strategies I have developed in an effort to outperform a given index.

I actually wrote this today when the idea came to me to write a small time frame strategy that attempts to enter the market and take profit as soon as possible with the ability to stop and reverse direction quickly if the position becomes unprofitable. I am sure the general idea can be adapted to other timeframes and markets.

 

Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. juanj • 05/11/2017 #

    As mentioned, this is a conceptual strategy to beat a buy and hold approach. Practically the costs of staying in the market for such extended periods can potentially outweigh the benefits if the market tends to range longer than what it actually trends. I will in the near future post some of my other strategies that spend much less time in the market and are much more practical to trade.

    • bertrandpinoy • 05/11/2017 #

      bonjour je test le robot sp500 Optimizer stategy. Je ne vois pas le SL dans le code??? merci

  2. juanj • 05/11/2017 #

    Here is the version adapted for the DAX. Which it also wildly outperforms.
    ///Spread set to 0.9 points for SP500
    ///Spread set to 3 points for DAX

    possize = 1
    pointsp = 90 //20 for SP500 //points where profit is to be locked in
    pointsb = 84 //36 for SP500 //points where stop is to be taken

    fast = average[12,4](close) //11,4 for SP500
    medium = average[14,4](close) //13,4 for SP500

    If countofposition = 0 then
    If fast > medium then
    BUY possize CONTRACT AT open + averagetruerange[3](close)*2 stop
    EndIf
    EndIf

    If longonmarket and close >= positionprice + pointsp then
    If close < close[1] then
    SELL AT MARKET
    EndIf
    ElsIf longonmarket and close <= positionprice - pointsb then
    SELLSHORT possize*2 CONTRACT AT MARKET
    EndIf

    If shortonmarket and close <= positionprice - pointsp then
    If close > close[1] then
    EXITSHORT AT MARKET
    EndIf
    ElsIf shortonmarket and close >= positionprice + pointsb then
    BUY possize*2 CONTRACT AT MARKET
    EndIf

    SET TARGET pPROFIT 100 //50 for SP500
     

  3. Oskar Bergvall • 05/11/2017 #

     Looks very interesting! Will try it on both sp500 and dax on one of my demoaccounts 🙂

  4. klaus • 05/11/2017 #

    I just backtested on my German IG account. Looks good almost 70% profit from Jan2016
    Unfortunately i was not able to insert a screen shot. Does somebody know how?
    ciao Klaus

  5. juanj • 05/11/2017 #

    I tested the strategy on FX today and seems to work very nicely.
    Here the example of EUR/USD with spread set to 0.8:
    ///Spread set to 0.9 points for SP500
    ///Spread set to 3 points for DAX
    ///Spread set to 0.8 for EUR/USD

    possize = 1
    pointsp = 0.0029//90 for DOW //20 for SP500 //points where profit is to be locked in
    pointsb = 0.0042//84 for DOW //36 for SP500 //points where stop is to be taken

    fast = average[10,4](close) //12,4 for DOW //11,4 for SP500
    medium = average[13,4](close) //14,4 for DOW //13,4 for SP500

    If countofposition = 0 then
    If fast > medium then
    BUY possize CONTRACT AT open + averagetruerange[3](close)*2 stop
    EndIf
    EndIf

    If longonmarket and close >= positionprice + pointsp then
    If close < close[1] then
    SELL AT MARKET
    EndIf
    ElsIf longonmarket and close <= positionprice - pointsb then
    SELLSHORT possize*2 CONTRACT AT MARKET
    EndIf

    If shortonmarket and close <= positionprice - pointsp then
    If close > close[1] then
    EXITSHORT AT MARKET
    EndIf
    ElsIf shortonmarket and close >= positionprice + pointsb then
    BUY possize*2 CONTRACT AT MARKET
    EndIf

    SET TARGET $PROFIT 130//105 for DOW //50 for SP500

     

  6. Francesco78 • 05/11/2017 #

    Thank you Juanj! It looks very nice, I am running live the one on Dax already and it is already making money 🙂
    One question on the EUR/USD. 
    I have changed the size from 1 to 2 by setting possize = 2 but it change the shape of the equity curve..
    What am I missing?
    Best
    Francesco 

  7. juanj • 05/11/2017 #

    Hi Francesco, I am glad you find the strategy useful. However you are rather brave to run the strategy live,usually running a strategy in a demo account for at least a month is strongly advised. However, if you understand the risk involved (as any good trader hopefully does) I wish you all the best.
    With regards to changing the possize parameter on the EUR/USD, since this increases the position exposure you would have to make the following modifications to incorporate possize since you are not dealing here with points as with the indexes but pips and dollars;
    pointsp = 0.0029*possize
    pointsb = 0.0042*possize
    SET TARGET $PROFIT 130*possize

  8. Francesco78 • 05/11/2017 #

    Thank you!

  9. Francesco78 • 05/11/2017 #

    Thank you! I think the pointsp and the pointsb are already in pips though so no need to change those. 
     

  10. juanj • 05/11/2017 #

    That is correct, was just about to edit my post to ignore the first part (pointsp and pointsb) as it is already in pips as you mention.

  11. zilliq • 05/11/2017 #

    Walk forward, walk forward Guys 😉

  12. criscolci • 05/11/2017 #

    Thanks for sharing your ideas.

  13. juanj • 05/11/2017 #

    As with all strategies that uses variables (back tested or forward tested) it is always a good idea to keep your variables optimized to current market conditions. I recommend running variable optimization on a monthly basis and carefully watch the MA on your equity curve for changing conditions requiring optimization. No amount of back or forward testing is sufficient to produce that ‘golden’ set of variables for future market conditions.

  14. juanj • 05/11/2017 #

    Version adapted for FTSE spread set to 3;
    ///Spread set to 0.9 points for SP500
    ///Spread set to 3 points for DAX
    ///Spread set to 0.8 for EUR/USD
    ///Spread set to 3 points for FTSE

    possize = 1

    pointsp = 55//0.0029 for EUR/USD //90 for DOW //20 for SP500 //points where profit is to be locked in
    pointsb = 45//0.0042 for EUR/USD //84 for DOW //36 for SP500 //points where stop is to be taken

    fast = average[11,4](close) //10,4 for EUR/USD //12,4 for DOW //11,4 for SP500
    medium = average[13,4](close) //13,4 for EUR/USD //14,4 for DOW //13,4 for SP500

    If countofposition = 0 then
    If fast > medium then
    BUY possize CONTRACT AT open + averagetruerange[3](close)*2 stop
    EndIf
    EndIf

    If longonmarket and close >= positionprice + pointsp then
    If close < close[1] then
    SELL AT MARKET
    EndIf
    ElsIf longonmarket and close <= positionprice - pointsb then
    SELLSHORT possize*2 CONTRACT AT MARKET
    EndIf

    If shortonmarket and close <= positionprice - pointsp then
    If close > close[1] then
    EXITSHORT AT MARKET
    EndIf
    ElsIf shortonmarket and close >= positionprice + pointsb then
    BUY possize*2 CONTRACT AT MARKET
    EndIf

    SET TARGET pPROFIT 55//130*possize for EUR/USD //105 for DOW //50 for SP500

     

  15. juanj • 05/11/2017 #

    I realize in the comments of my code I made reference to the parameters of the DOW when in reality I meant DAX.

  16. reb • 05/11/2017 #

     Very interesting strat juanj
     only one  remark, I find time on the market a bit high and then risky
    Reb

    • juanj • 05/11/2017 #

      Thanks Reb, I am aware. Interestingly enough though the time in market is much less in more volatile markets such as forex. See the EUR/USD example for instance. 

  17. zilliq • 05/11/2017 #

    Walk forward Guys, Walk forward as I said ! An optimization means nothing without “confirmation” by WF
    An optimization is quite easy, pass a WF is more complicated
    DAX Spread 3 points, 15000 unit
    Finish in gain
    2/5 >50 % WFE
    Ratio 45 %
    Not perfect but not bad

  18. zilliq • 05/11/2017 #

    Walk forward Guys, Walk forward as I said ! An optimization means nothing without “confirmation” by WF
    An optimization is quite easy, pass a WF is more complicated
    DAX Spread 3 points, 15000 unit
    Finish in gain
    2/5 >50 % WFE
    Ratio 45 %
    Not perfect but not bad

  19. zilliq • 05/11/2017 #

    I tried with 3 variables and now 6. Results in some hours …

  20. zilliq • 05/11/2017 #

    And of course thanks for your job Juan 😉

  21. zilliq • 05/11/2017 #

    WF with 6 variables stopped..Game Over..Be careful Guys …

  22. zilliq • 05/11/2017 #

    I will try with 6 variables on US500 …

  23. zilliq • 05/11/2017 #

    Game over on sp500 too …

  24. zilliq • 05/11/2017 #

    I tried with less variables and on mini 500 (as juan)
    Same results sadly…

  25. juanj • 05/11/2017 #

    Hi Zilliq, thank you for taking the time in doing some walk forward testing. You mentioned you used 6 valuables, but there is only 5 that requires optimization. Also what variable ranges did you use? As a side note, it is worth noting that frequent variable optimisation can keep a time optimised strategy surprisingly profitable. Just keep an eye on the equity curve. 

  26. Ketefster • 05/11/2017 #

    Juan, would love to see anything on the South African cash Top4o, if possible please.

  27. Dymjohn • 05/11/2017 #

    Hi juanj
    Interesting system but for someone not sure on the coding what does the  ,4 represent in the formula: 
    I tried graphing the average but couldn’t see what it represented?
    best regards
    dymjohn
    fast = average[11,4](close)

  28. juanj • 05/11/2017 #

    The value after the comma refers to the Moving Average type;
    0 = Simple,1 = Exponential,2 = Weighted,3 = Wilder’s Smoothed,4 = Triangular,5 = End Point, and6 = Time Series.

  29. Dymjohn • 05/11/2017 #

    Thanks for this, juanj, I didn’t know you could write the average method this way. I would have written it as TriangularAverage[11](close).
    Should you worry about “walk Forward” how is this calculated unless you test it for months before using?
    Regards
    dymjohn
    best r

  30. juanj • 05/11/2017 #

    @Ketefster I actually have quite a couple of SA Top40 strategies that I am personally running live. Send me an email on jd3gjacobs@gmail.co.za for more information.

  31. juanj • 05/11/2017 #

    @Dymjohn The above strategy is largely conceptual and hence not optimized using walk forward testing. I do however use walk forward tests extensively on development of my core strategies to establish a good set of optimized variables to start off with. However that said walk forward tests will never guarantee future performance, although a tight range of variables will show that you are on the right track. There is no such thing as a magic set of variables. It is necessary to regularly optimize variables to ensure your strategy is suited to current market conditions.

  32. Dymjohn • 05/11/2017 #

    Thanks for your comments, juanj, probably explains why I tend to optimize a strategy and then find I lose money when I trade it. The trouble is one can optimise today and market conditions change tomorrow I get the point about a tight range of variables though
    Thanks again
    Dymjohn 

  33. Benjamin • 05/11/2017 #

     Hi Juanj, thanks for sharing this, are you using the same sp500-optimizer-5min-strategy.itf for the German 30?
    Cheers

  34. juanj • 05/11/2017 #

    Hi @Benjamin, unfortunately as I have mentioned before I cannot say that I use this strategy. It was purely conceptual in design. I did post a version of the above adapted for the DAX. See earlier comments. However I cannot advise using this strategy without at least running it live for  a month or so. Even then re-optimization would be necessary to ensure performance related to then ‘current’ market conditions.

  35. Francesco78 • 05/11/2017 #

    Hi I created an optimized version that differentiate between long and short and that allows the first trade to be short
     

    • juanj • 05/11/2017 #

      Cool can you post it somewhere? Maybe create a topic on the forum?

  36. Francesco78 • 05/11/2017 #

    I tried to post it here but something doesnt seem to work..
    ///Spread set to 0.9 points for SP500///Spread set to 3 points for DAX//DEFPARAM flatafter = 230000//defparam flatbefore= 080000possize = 1pointspl = 110//20 for SP500 //points where profit is to be locked inpointsbl = 85//36 for SP500 //points where stop is to be taken
    pointsps = 90 //20 for SP500 //points where profit is to be locked inpointsbs = 105 //36a = 2.1b=2pf = 100periodfast = 3periodmedium = 15fast = average[periodfast,4](close) //11,4 for SP500medium = average[periodmedium,4](close) //13,4 for SP500
    If countofposition = 0 thenIf fast > medium thenBUY possize CONTRACT AT open + averagetruerange[3](close)*a stopEndIfEndIf
    If countofposition = 0 thenIf fast < medium thensellshort possize CONTRACT AT open – averagetruerange[3](close)*b stopEndIfEndIf
    If longonmarket and close >= positionprice + pointspl thenIf close < close[1] thenSELL AT MARKETEndIfElsIf longonmarket and close <= positionprice – pointsbl thenSELLSHORT possize*2 CONTRACT AT MARKETEndIf
    If shortonmarket and close <= positionprice – pointsps thenIf close > close[1] thenEXITSHORT AT MARKETEndIfElsIf shortonmarket and close >= positionprice + pointsbs thenBUY possize*2 CONTRACT AT MARKETEndIf
    SET TARGET pPROFIT pf //50 for SP500

    • juanj • 05/11/2017 #

      I like your modification. Have yo tried it on some of the other indexes or currencies?
      However looking at the DAX for YTD there is some concerns:
      Top = Original CodeMiddle = Buy and HoldBottom = Your Code

  37. Francesco78 • 05/11/2017 #

    thats weird, I get a completely different result..

  38. Francesco78 • 05/11/2017 #

    I cant attach the picture here, shall we exchange email?

  39. Pollux • 05/11/2017 #

    Hi Juan.
    Thanks for sharing. I like the concept. 
    I’m curious to find out what broker you use? IG? if so, you get about 3 months more data than me on the 5min timeframe.
    Have you tried this on the SA40?

  40. hvluthy@sunrise.ch • 05/11/2017 #

    Hi,
    Please forgive my question… I’m an absolute beginner.
    I’m trying to trade the US 500 1€ on a 25 contract base. So, changed “1” on line 3 into 25. I presume other numbers must be changed. Would you be good enough telling which ones, please.

  41. fatcat • 05/11/2017 #

    Sorry, but my Broker can only accept a buy-order depending on the averagetruerange-limit if there is a minimum distance from actual price level. Therefore the strategy is being hold quickly. No trading possible.

  42. nonetheless • 05/11/2017 #

    Hi juanj , thanks for posting this. I’m with IG and have been trying to run it on US 500 but orders keep getting rejected. Any idea why that might be?

  43. phoentzs • 05/11/2017 #

    Hello Juanj, I really like this concept. I especially like the possibility of a reversal when the market is going against you. I have created several versions with different inputs (RSI2, close>close(1) etc.) and with the possibility to go short or long as the first trade if the trend demands it. I also changed the diagnosis of the trend. It performs very well in so many markets. Of course, it’s often on the market for a very long time. Is that a good thing or a bad thing?
    Do you use this concept? Do you maybe have a few tips for me?

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
Nacho Buenos días Raul, tengo puesto este sistema desde hace unos días en una cuenta demo en la ve...
Dominik Hola Raul ... it looks wonderful :-) Why does it not work if I use less than 100,000 € capi...
Bobbi Hola y gracias por compartir! Descubrí que en 5 minutos teníamos algo muy bueno! Pero no ...
pascal3431 Salut Doc , Je ne vois pas ce qui fait office de stop dans ce code .. un retour dans le nua...
Doctrading Bonjour, Il s'agit juste d'une stratégie où on est toujours en position : soit à l'achat / ...
pascal3431 Bonjour, après quelques essais sur EUR/USD au M15 en rajoutant(car sinon on est en perte) u...
jonjon Hi Raul. Just a thought, is there a way to limit the maximum number or orders that can be ac...
Petrus Hi jonjon. If you want to exit at the 4th bar only if the trade is losing money, you have to...
emadimarco Hi, I would like to do a test by doing it by day, but I'm not able to change the start and e...
Doctrading Interesting concept, good work !  
verdi55 Thank you. This is mainly to show the concept, but I would not trade with this system as it ...
Kris75 Hi Verdi, I like very much the point and figure tool and would like to work with your tradi...
verdi55
8 years ago
Marcel Hi, I tested this strategy on Spot Gold with a brick size of 20 on the weekly timeframe with...
Nicolas Because the renko chart construction begin at the first price of the loaded history. So you ...
JOKAMAURICE I am learning to code. I try to understand these lines newbricksup = (round(((close - upbr...
danhei Hi I am tryong to figure out how trist strategy works. I am new to pro real time. Can some...
Plop61 Hello,Thank you for sharing this beautiful strategy.Is it possible to indicate the code for ...
NoName Thank you very much for this fascinating trading system. It is still proving to be extremely...
ALE
8 years ago
pollon Ciao Ale,  anche a me da questo errore  "QQE_QUDAX1HBUY"  "QQE_QUDAX1HSELL"  "UNIV_QUDAX...
reb Hi Ale do you trade these QU strategies?  Are the results same as backtests Thnaks in adv...
avatar
crazytrader Hi anyone that has run this lately?
DonDollar Ni Nicolas, thanks for the comment. I started with a 3000$ Position and 1 Pip Spread. I fo...
DonDollar Stupid me, it is indeed 1 POINT Spread....  
HarryPro Hello Clemens, I tested your Friday XAU and found it broke down when going well into the pas...
ellejoe Hi Ale, can you please share your live results and updated version with us? Was this strateg...
ALE Hello ellejoe,since 1th november 2016,I can confirm probacktest results, I cant run it in li...
David Thompson I'm new to PRT, and yet I know I need to take away the 'human emotion' from my trading - so ...
DANY I did it on demo account; it's too dangerous for mea and I can not resist psychologically  ....
demoz How can a demo account be dangerous? Did you have it run live (on a demo account for exampl...
DANY Yes, I mean that I tried on a demo account for 2 months and it had work fine, like the BackT...
Dimi.A Awesome mate.
mora87 Hi David and Nicola, I'd like to share idea with you guys which is related to David's Idea. ...
Nicolas Please ask for custom coding in forums instead.
ALE Hi Pat This code was nothing more than an experiment
pat95162 Hi Ale Do you have same results as me ? The strategy works very well in 2017 and now in 2-...
Nicolas Built on the history means that it suits the history. Always develop ideas in In-Sample peri...
ALE
9 years ago
ALE no, only with TF 15m
enzo_52 Grazie tante, Thanks so much 
JanWd Hallo Ale, First of all, thank you for this strategy. Could you explain what the BLUSTER ...
ALE
9 years ago
ALE @Nicola Nicolas thanks for your kind attention, the same indicator used with different set c...
miguel33 In piena sintonia . 
Ernesto1 Grazie Ale per aver condiviso con noi il tuo indicatore  P.A.B. aspettiamo il tuo script s...
Matriciel
9 years ago
chaostrader82 Dear Matriciel , can you add in the following ? stoploss=30pips , take profit= 4pips <===...
chaostrader82 Theres some bugs still with this program , can somebody help to improve on the following? I...
Matriciel Hi Chaostrader82,You know, I'm starting in automatic strategy coding so I'm not going to be ...
Cosmic1
9 years ago
Cosmic1 Lets discuss here: https://www.prorealcode.com/topic/cac-breakout-ported-to-other-markets/
rejo007 hello, anybody use thi strategy for a long time? thanks
abacus23 Hi, I have been trading this strategy and it seems to work quite well recently. Is there a...
Elsborgtrading No that is wrong :) 1st runs always- then only run 2nd if 1st is on market with positions(ar...
Elsborgtrading It can only be fully automated if IG change minimum SLto 7 at night on DAX multi timefra...
Elsborgtrading A small example. the strategy would have opened 3 position on Dec 4th 2016 and keept it for ...
Cosmic1
9 years ago
Cosmic1 @JadeDB What times are you putting in?
sincitytrader I tried this one out recently,  and wasn't profitable for me.
Cosmic1 Yes, not great lately. I stopped this live at the end of last year. Will wait to see when th...
Mansoor What does COI stand for?
MikeGC Hi Mansoor, COI is the abbreviation for the Coppock indicator.
nonetheless Anyone interested in this strategy please see forum topic: https://www.prorealcode.com/topic...
Stenozar Buongiorno, qualcuno sta utilizzando in reale questa strategia? con quali risultati? Grazie!
reb Hi Stenozar Sorry in the library, could you use english pls ? I don't use this strategy  l...
Stenozar Thanks Reb; do you suggest any other strategy on Brent? thanks

Top