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

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: 257
Download
Filename: 2-day-buy-and-hold.itf
Downloads: 386
Download
Filename: Skarmavbild-2017-09-19-kl.-09.05.01.png
Downloads: 157
Download
Filename: Skarmavbild-2017-09-19-kl.-09.04.44.png
Downloads: 295
victormork Veteran
Developer by day, aspiring writer by night. Still compiling my bio... Error 404: presentation not found.
Author’s Profile

Comments

Logo Logo
Loading...