Francesco78

Oil 15 minutes meanreverting strategy

Category: Strategies By: Francesco78 Created: June 28, 2017, 2:28 PM
June 28, 2017, 2:28 PM
Strategies
24 Comments
Oil 15 minutes meanreverting strategy

Hello,

I found this nice and simple strategy playing with the “average fullness of last 5 candles” . I added a simple moving average oscillator, with 5 and 50 period and I considered mean reverting long/short condition by setting a threshold to the “average fullnes”

The strategy is really minimally optimized, I only optimized the threshold and the profit and stop target.

Results of  backtest and  WF are attached

Regards

Francesco

//crude oil 15 min strategy

DEFPARAM cumulateOrders = False // Cumulating positions deactivated
///parameter definition
period = 5
fastav = average[5](close)
slowav = average[50](close)
maoscillator = fastav-slowav

fullness = (Dclose(0)-Dopen(0))/abs(Dhigh(0)-Dlow(0))
avfullness = summation[period](fullness)/period

pr = 50
pl = 40
avfullnessthreshold = 0.2

cl = maoscillator > 0
cl = cl and avfullness < -avfullnessthreshold
// Conditions to enter long positions

cs = maoscillator<0
cs = cs and avfullness > avfullnessthreshold

IF cl THEN
 BUY 1 PERPOINT AT MARKET
ENDIF

if cs then
 sellshort 1 perpoint at market
endif

set target pprofit pr
set stop ploss pl

Download
Filename: oil_15min.itf
Downloads: 418
Download
Filename: oil_15min_wf.png
Downloads: 238
Francesco78
Francesco78 Master
As an architect of digital worlds, my own description remains a mystery. Think of me as an undeclared variable, existing somewhere in the code.
Author’s Profile

Comments

UkCoopDownUnder
6 years ago
#

Hi, ProOrder does not recognise, "avfullnessthreshold" any ideas, thanks

fatlung
7 years ago
#

Excuse me. I would like to the time zone applied to this strategy.

DANY
8 years ago
#

overfit

lizmerrill
9 years ago
#

Thanks for replying, so.... I assume in your backtest, the fullness calculations using dclose,dopen, etc were based on the last available prices i.e., the open, h,l, and close of daily frame from yesterday, right?

Francesco78
9 years ago
#

hi Lizmerril, yes, that is correct

lizmerrill
9 years ago
#

can you explain the flow of the code, just to clarify. RE:fullness = (Dclose(0)-Dopen(0))/abs(Dhigh(0)-Dlow(0)) avfullness = summation[period](fullness)/period. Correct me, but avfullness is based on the dailystats, e.g., dclose, dhigh, dopen,dlow. Since you are using 0 for parameter for dclose(0), and dhigh,dlow,dopen, I assume that during the 24 hour day, these values will change, is that correct, so there fullness will change, as the day proceeds, is that correct?

stockdemon
9 years ago
#

Posted solution to the zero div problem which exists in the different versions of the code.

Francesco78
9 years ago
#

how do you define trailingstep and trailingstart?

Francesco78
9 years ago
#

HI Juan, I created this forum where you can share with us your results if you dont mind. By the way your code as it is doesnt seems to work, can you pls upload the correct version in the forum at this link? https://www.prorealcode.com/topic/oil-15-minutes-meanreverting-strategy/ Many thanks!

Francesco78
9 years ago
#

Thank you Juan Salas!, will have a look now

Juan Salas
9 years ago
#

By the way, thanks again for your valuable contribution to this community.

Juan Salas
9 years ago
#

I was planning to insert pics of my backtest, but apparently I don't find the way to insert a png. file in the conversation.

Juan Salas
9 years ago
#

//------------------------------------------------------------------------- // Código principal : MEANREVERTING w TRAIL15' //------------------------------------------------------------------------- //crude oil 15 min strategy DEFPARAM cumulateOrders = False // Dias de la semana IF DayOfWeek = 0 OR Dayofweek = 6 THEN tradeok = 0 ELSE tradeok = 1 ENDIF // Friday 22:00 Close ALL operations. IF DayOfWeek = 5 AND time = 220000 THEN SELL AT MARKET EXITSHORT AT MARKET ENDIF Fridaynight = Dayofweek = 5 AND time>220000 //parameter definition period = 6 fastav = average[4](close) slowav = average[50](close) maoscillator = fastav-slowav fullness = (Dclose(0)-Dopen(0))/abs(Dhigh(0)-Dlow(0)) avfullness = summation[period](fullness)/period avfullnessthreshold = 0.38 enrojoalcista= (tradeprice(1)-close)>35*pipsize enrojobajista= (close-tradeprice(1))>35*pipsize cl = maoscillator>0 cl = cl and avfullness < -avfullnessthreshold cs = maoscillator avfullnessthreshold // Largos IF NOT ONMARKET AND cl AND tradeok=1 AND NOT Fridaynight THEN BUY 1 CONTRACT AT MARKET ENDIF // Cortos IF NOT ONMARKET AND cs AND tradeok=1 AND NOT Fridaynight THEN SELLSHORT 1 CONTRACT AT MARKET ENDIF // Salida Largos IF LONGONMARKET AND enrojoalcista AND (open-close)>=30*pipsize AND open>close THEN SELL AT MARKET ENDIF // Salida cortos IF SHORTONMARKET AND enrojobajista AND (close-open)>=30*pipsize AND open=trailingstart*pipsize THEN newSL = tradeprice(1)+trailingstep*pipsize ENDIF //next moves IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN newSL = newSL+trailingstep*pipsize ENDIF ENDIF //manage short positions IF SHORTONMARKET THEN //first move (breakeven) IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN newSL = tradeprice(1)-trailingstep*pipsize ENDIF //next moves IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN newSL = newSL-trailingstep*pipsize ENDIF ENDIF //stop order to exit the positions IF newSL>0 and tradeok=1 THEN SELL AT newSL STOP EXITSHORT AT newSL STOP ENDIF //************************************************************************ //set target pprofit 30 set stop ploss 90

Juan Salas
9 years ago
#

Hi Francesco, I have customised your code for Oil USA 15', applying Nicolas' super trailing code (thanks Nicolas!) and other minor alterations (Increased STOP distance, closing operations Friday night, etc). The equity curve is a little smother and is working for me in real. I know it may not reflect a big change, but it very consistence and so far it is working very well. I am also a fan of the hammer negated. It is working for me in Oil USA in 10min, 30min, and ...in 2 mins. The results are amazing. The only con, as well as with this code is that I have just tested it in 100k. I am trying to adapt the Mean Reverting to other markets, any suggestions would be greatly appreciated. (It is working well with Brent, but not as well as with the USA)

Kenneth Kvistad
9 years ago
#

Francesco, can you try to make this strategy with short and long proffit tragets just like in your hammernegated strategy?

Francesco78
9 years ago
#

Kenneth, it means that the tick value is 1 euro

Kenneth Kvistad
9 years ago
#

What does buy 1 «perpoint» means?

I also see there is some inside candlestick trades that i personaly have Never been able to be sucssessfull in.

I see you have alot of great ideas and strategies :-)

 

Yannick
9 years ago
#

Hi thanks for sharing.

Did you tried volatility take profit and stop loss based on atr rather than fixed values?

Francesco78
9 years ago
#

Alexinvestgroup, I have used spread = 1 to backtest

Francesco78
9 years ago
#

HI Victormonk, thank you, yes I noticed that. Maybe we could try to set different target for long and short to rebalance it, I tried to optimize as little as possible.

alexinvestgroup
9 years ago
#

What spread?

victormork
9 years ago
#

Nice work Francesco! Have you noticed that the long side is much better than the short?

Francesco78
9 years ago
#

Thank you Wilko!

Wilko
9 years ago
#

Nice idea of relative fullness of candle! I like it.

ProRealCode ProRealCode
Loading...