Hi,
Was hoping someone could provide me with some code for a very simple strategy. I cant quite get the code to do what i want it to. below are the parameters;
Trading on the major FX pairs (usd/jpy, eur/usd, gbp/usd etc)
Daily bars
If previous days bar was an up bar (open < close) then I want to sell on the previous days low
If previous days bar was a down bar (open > close) then i want to buy on the previous days high
stop will be 10 points
limit/target will be 40
If the limit or stop hasnt been hit during the trading day I want to exit on the close of that same day.
Only want to trade from monday to friday, wary that there is a sunday bar on the FX due to it opening on sunday for a lot of the world (Im in Australia, opens 7am Monday)
Ideally would like the backtesting to ignore the sunday bar
Thanks for the help with this.
Please find below a rough code that should work for your query. I didn’t test it, please make your own and give feedbacks, thank you.
bull = dclose(0)>dopen(0)
bear = dclose(0)<dopen(0)
if day<>day[1]=0 then
alreadytraded=0
endif
if dayofweek>0 then
if not onmarket and bull and alreadytraded=0 then
sellshort 1 contract at dlow(0)
alreadytraded=1
endif
if not onmarket and bear and alreadytraded=0 then
buy 1 contract at dhigh(0)
alreadytraded=1
endif
endif
set stop ploss 10
set target pprofit 40
I played around with above and got attached results on DAX 100,000 bars @ 5 Min (cos I like 5 mins TF 🙂
Had to change code at Line 5, 10 and 15 to get it going … rightly or wrongly?
bull = dclose(0)>dopen(0)
bear = dclose(0)<dopen(0)
if day<>day[1] then
alreadytraded=0
endif
if dayofweek>0 then
if not onmarket and bull and alreadytraded=0 then
sellshort 1 contract at dlow(0)stop
alreadytraded=1
endif
if not onmarket and bear and alreadytraded=0 then
buy 1 contract at dhigh(0)limit
alreadytraded=1
endif
endif
set stop ploss 100
set target pprofit 80
GraHal
Well done Grahal, I should have tested my code!
I think the order at line 15 should also be a stop one, we are buying higher, looking for a breakout.
Yeah I tried a stop at Line 15, attached are the results.
I tried all combinations, with one eye on tv watching a film it’s easier (for me) to try stuff than work out if we’re trading higher or lower 🙂
The backtest should be made on a daily timeframe, because the pending orders only last one bar in my code. I’m on my smartphone, can’t do it myself!
Nice one Nicolas! Shut phone and brain off, sit in sun, get whiskey … you’re on holiday??
WF Results for 1000 Daily bars,
Daily Code:
//https://www.prorealcode.com/topic/help-with-basic-strategy/
//GH DCloseDOpen DAX 1D
bull = dclose(0)>dopen(0)
bear = dclose(0)<dopen(0)
if day<>day[1] then
alreadytraded=0
endif
if dayofweek>0 then
if not onmarket and bull and alreadytraded=0 then
sellshort 1 contract at dlow(0)stop
alreadytraded=1
endif
if not onmarket and bear and alreadytraded=0 then
buy 1 contract at dhigh(0)stop
alreadytraded=1
endif
endif
set stop ploss 160
set target pprofit 780
GraHal
Attached overall result for above code in tick-tick mode with no WF.
Any ideas to increase % of winning trades?
I can’t BT more than 1000 x Daily due to that annoying error message … one or more candles are not available … etc.
GraHal