2 days buy and hold SP500

2 days buy and hold SP500

I found the baseline of this long only code online and did a few small changes to it.

It works as follow:

Entry rules:

  1. 2 periods moving average 1 day ago is greater than moving average of today.
  2. 2 periods moving average 10  days ago is greater than 11 days ago.
  3. Close above 7 periods moving average

Exit rule:

When the first entry rule is no longer true; exit.

 

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. Nicolas • 09/20/2017 #

    Thank you Victor, I added a full ‘buy and hold’ chart comparison as an attached file.

  2. victormork • 09/20/2017 #

    Thanks for the comparsion. This code would need some additional money management to take advantage of the steady equity curve in order to make sense. The selection of number of days to use for entry signal can also be optimised for a better return.

  3. Gertrade • 09/20/2017 #

    Hi victor, below “Buy Sell and Hold” code optimized with money management on DAX 4h. Thank’s

    DEFPARAM CumulateOrders = False
    DEFPARAM PreloadBars = 200

    // Money Management
    Equity = 500+(StrategyProfit*3)
    Risk = 0.1
    n = Max(1,Equity*Risk/51/PipValue)

    // ————
    Losses = positionperf(38)>0
    Wins = positionperf(38)ma1[0]
    b1 = b1 and ma1[10]>ma1[11]
    b1 = b1 and close > ma2

    b3 = ma1[1]<ma1[0]
    b3 = b3 and ma1[10]<ma1[11]
    b3 = b3 and close < ma2

    // Entry
    if b1 then
    buy positionsize contracts at market
    endif

    if b3 then
    sellshort positionsize contracts at market
    endif

    // Exit
    e1 = ma1[1]ma1[0]

    if e1 and longonmarket then
    sell at market
    endif

    if e3 and shortonmarket then
    exitshort at market
    endif

    // Stoploss and Profit
    set stop %loss sl
    set target %profit tp

    • victormork • 09/20/2017 #

      thanks! works alright but I think something when wrong in the last part of the code you attached (from “b3” and down)? There is no command for entry.

  4. Gertrade • 09/20/2017 #

    thanks victor! below the original code modified with no errors.
    //————————————————————————-
    // Code principal : buy sell and hold DAX 4h
    //————————————————————————-
    DEFPARAM CumulateOrders = False
    DEFPARAM PreloadBars = 200

    // Money Management
    Equity = 500+(StrategyProfit*3)
    Risk = 0.1
    n = Max(1,Equity*Risk/51/PipValue)

    // ————
    Losses = positionperf(38)>0
    Wins = positionperf(38)ma1[0]
    b1 = b1 and ma1[10]>ma1[11]
    b1 = b1 and close > ma2

    b3 = ma1[1]<ma1[0]
    b3 = b3 and ma1[10]<ma1[11]
    b3 = b3 and close < ma2

    // Entry
    if b1 then
    buy positionsize contracts at market
    endif

    if b3 then
    sellshort positionsize contracts at market
    endif

    // Exit
    e1 = ma1[1]ma1[0]

    if e1 and longonmarket then
    sell at market
    endif

    if e3 and shortonmarket then
    exitshort at market
    endif

    // Stoploss and Profit
    set stop %loss sl
    set target %profit tp

  5. victormork • 09/20/2017 #

    Hi! it’s still incorrect. There’s something wrong when you copy codes to this comment section. I’ve had this problem here too. If you don’t mind could you pls put the code in a new forum topic?

  6. Gertrade • 09/20/2017 #

    Hi! replace the code at the line 43 by the code below. Thank’s
    b3 = ma1[1]<ma1[0]
    b3 = b3 and ma1[10]<ma1[11]
    b3 = b3 and close < ma2

    // Entry
    if b1 then
    buy positionsize contracts at market
    endif

    if b3 then
    sellshort positionsize contracts at market
    endif

    // Exit
    e1 = ma1[1]ma1[0]

  7. victormork • 09/20/2017 #

    @Nicolas do you think you can solve the issue with copy paste code into this comment field? Thanks

  8. Gertrade • 09/20/2017 #

    I’m sorry but it impossible to post the original true code. May be, Nicolas can solve this problem.

    • Nicolas • 09/20/2017 #

      I’m aware of this comment engine issue. Would you mind send me the code as I could try to fix the problem, probably due to the codes’characters.. Please use the contact form: https://www.prorealcode.com/contact/
      Thanks a lot for your help!

  9. Gertrade • 09/20/2017 #

    I don’t send the original code by the contact form:https://www.prorealcode.com/contact/. The contact form don’t run when i push on the button “send”.

    • Nicolas • 09/20/2017 #

      Send me the code with email: nicolas[at]prorealcode.com

  10. stockdemon • 09/20/2017 #

    The problem is that the markup is assuming you’re writing. markup 🙂

    Try the code tags, might do the trick, e.g.

    b3 = ma1[1]<ma1[0]

    • stockdemon • 09/20/2017 #

      Well that didn’t work. Next attempt:
      b3 = ma1[1]<ma1[0]

      https://www.freeformatter.com/html-escape.html#ad-output (Try this site)

    • Nicolas • 09/20/2017 #

      Sorry for the problem. It should be fixed now. Post code and refresh the page, then codes should no longer been truncated.

  11. jens_kittner • 09/20/2017 #

    Since 2018 this strategy leads to bankruptcy)))))))

  12. Jan Wind • 09/20/2017 #

    You do not HAVE to run it

  13. Brisvegas • 09/20/2017 #

    As an exersize in writing code its fine but as a tool to make money not so much . If you happy with less than treasury bond returns this is for you .

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
phoentzs
12 months ago
banjoo78 Which is the timezone's setting of USA SP 500? I've differents results and I don't know why....
pdrh I have runit in the UTC+2 TZ and got matching results
BaderBader Hey @banjoo78, maybe its because of your License for US Indices? Because I have the sa...
KAMJKAZE thanks, really interesting!
2c95 thanks, why do U prefer average than lowest ? to close under average does'nt mean another...
Ludwig Bonjour Merci pour le code, je souhaite intégrer un break even et mette en place un réinves...
superfalcio hello, this strategy is pretty interesting, anyway on index after diferent suggestion and im...
Fralex Hello everyone I optimized the original “LongOnly-DAX-4H-TMA-Channel” algorithm over a pe...
odin i use it on daily Chart only. i use it on stock market for long only startegies. i´m no fan ...
noisette Hi Odin, Thank you for the code. I made sone test with M1 timeframe and results have to be ...
Onega Sorry, a quick question I cannot see on forum please ?...Using ProScreener, how can we get t...
osupero https://www.screencast.com/t/2fCW8fkGsOeZ....solo posiciones largas por ahora
osupero https://www.screencast.com/t/MIaSZ2PRg
ALZ Hi JohnSher, Nice but not the same result Do you have the last itf of it ? Good result i...
dertopen HI Wwhy you said avoiding bear market? Don't you think that we can use this code for short...
maurizio dove si trova lo screener?
macdopa Thanks...
Eric If you have a high percentage winners and the trades are closed with take profit the spread ...
Casenova I Agree with you JaunJ, and Yes Eric, what you say makes sense too. Optimizing the Stop Loss...
ET Thanks for the system Casenova. In determining the high of the past 4 bars, is there a reaso...
simoneb ciao Gabri, potresti il modo più efficace per selezionare il paniere di 20-30 titoli su cui ...
gabri Simoneb, puoi creare uno screener che cerchi i titoli con un modified sharpe index inferiore...
gabri Dimenticavo, i titoli che performano meglio sono quelli che crossano la linea dello zero (o ...
JanWd Hi Francesco, nice algorithme, works with me on other markets as well !
Francesco78 thank you Janwd. Do you mind sharing where it works? happy new year!
Aaron Bennett Nice analysis, with the proposed tweak I'm seeing great performance since 2008/QE on the CAC...
EchnatonX Hallo Im Demomodus bei IG habe ich das Problem, dass oft keine Orders ausgeführt werden kön...
Jan EchnatonX, nice late answer of me: Make the stop loss a percentage of the close, like 100/...
guleny Hello I made some optimization to make it better. But there are 5 transacttion which incr...
Doctrading AH ok, I think the ca3 is the same : ca3 = pB[1] < 0.2 and pB < 0.2 Best regards,
chromosome21 Hello everybody, First, thank you so much for all your advices, I'm a begginer in trading a...
bertrandpinoy bonjour j ai un probleme avec ce code modifié, apparement PRT ne veut pas...avez vous une so...
Miguel1980 Hi gabri, I was not asking you to run any backtest but a PRT screener on any market to find...
gabri Miguel, copy. I just came back from vacation, I will pass you some data soon.
gabri Miguel, I will give you some stocks. I would buy (I probably will) Serneke group AB. I will...
Iber0 Asi quedaria con el spread de IG [IMG]http://i65.tinypic.com/2418ism.jpg[/IMG]
avatar
bjoern Seems to work nice on BUND - M15 with SL 70 and TP 120
hvluthy@sunrise.ch I tried to backtest this code but don't get any restults. Can any body help me?
CKW  Thanks Doctrading for sharing Is this Daily Time frame?  
Doctrading Hello, Yes, it is daily timeframe.
air Good job. 

Top