victormork

2 days buy and hold SP500

Category: Strategies By: victormork Created: September 20, 2017, 7:29 AM
September 20, 2017, 7:29 AM
Strategies
18 Comments
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.

DEFPARAM CumulateOrders = False
DEFPARAM PreloadBars    = 200

//Position size
positionsize = 10

//Indicators
ma1 = average [2](close)
ma2 = average [7](close)

// Entry condition
// b1 = moving average at close of one day ago is greater than the moving average of today
// b2 = moving average at close 10 days ago is greater than the moving average of the close 11 days ago

b1 = ma1[1]>ma1[0]
b1 = b1 and ma1[10]>ma1[11]
b1 = b1 and close > ma2

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

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

if e1 then
 sell at market
endif

// Stoploss
set stop ploss 100

 

Download
Filename: buy-and-hold-sp500-comparison.png
Downloads: 258
Download
Filename: 2-day-buy-and-hold.itf
Downloads: 387
Download
Filename: Skarmavbild-2017-09-19-kl.-09.05.01.png
Downloads: 159
Download
Filename: Skarmavbild-2017-09-19-kl.-09.04.44.png
Downloads: 295
victormork
victormork Veteran
Currently debugging life, so my bio is on hold. Check back after the next commit for an update.
Author’s Profile

Comments

Brisvegas
6 years ago
#

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 .

Jan Wind
7 years ago
#

You do not HAVE to run it

jens_kittner
7 years ago
#

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

stockdemon
9 years ago
#

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
9 years ago
#

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
9 years ago
#

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

Gertrade
9 years ago
#

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
9 years ago
#

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

Gertrade
9 years ago
#

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

Nicolas
9 years ago
#

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!

victormork
9 years ago
#

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

Gertrade
9 years ago
#

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]

victormork
9 years ago
#

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?

Gertrade
9 years ago
#

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

Gertrade
9 years ago
#

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
9 years ago
#

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.

victormork
9 years ago
#

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.

Nicolas
9 years ago
#

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

ProRealCode ProRealCode
Loading...