Hi guys.
My first contribution to the strategy site. It’s based on several codes from the site, but mainly the TDI and TMS from both Nicolas and Reiner. I changed the strategy a bit so it fits the Oil- Brent Crude. It seems like that every strategy that I test need to be “adjusted” to the particular instrument. Does anyone do the same, or do you strictly keep the rule? Anyway the code has no zero bar profit nor does it have SL or TP coded, in fact it has only 15 trades over 3 month. It sure could be more “perfect” as there are some entries that could be more profitable. Unfortunately I can only backtest it 3 month. Apparently IG only hold 3 month of data for Crude Oil. It’s tested with a 3 point spread. Anyway here it is, please comment 🙂
Cheers
Kasper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
//TDI OIL 2H elsborgtrading // based on Trend Surfer DAX-Reiner/Nicolas-TMS //http://www.prorealcode.com/prorealtime-trading-strategies/trend-surfer-dax/ //http://www.prorealcode.com/topic/trading-made-simple-tms-system/ //http://www.forexmt4.com/_MT4_Systems/Traders%20Dynamics/TDI_1.pdf // code-Parameter DEFPARAM CumulateOrders = true //DEFPARAM FlatAfter = 230000 //DEFPARAM Flatbefore = 030000 //MONEY MGT// Equity = (Strategyprofit+20000) Risk = round(Equity/100000) Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0 streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0 if losses then PositionSize = max(abs(round(max(3+risk-2,risk-2))),2) elsif not losses then PositionSize = max(abs(round(max(3+risk,risk))),2) endif if streak then PositionSize = max(abs(round(max(5+risk,risk))),2) endif //TDI indicator //parameters : lengthrsi=13 lengthrsipl=2 lengthtradesl=7 //overbought and oversold values of the TDI indicator upperzone = 68 lowerzone = 32 //heiken ashi xClose = (Open+High+Low+Close)/4 if(barindex>2) then xOpen = (xOpen[1] + xClose[1])/2 xHigh = Max(xOpen, xClose) xLow = Min(xOpen, xClose) endif //indicators r = rsi[lengthrsi](close) mab = average[lengthrsipl](r) mbb = average[lengthtradesl](r) yellowMA = average[5](TypicalPrice) yellowMAshifted = yellowMA[2] //trade conditions longCondition = mab crosses over mbb AND mab<50 AND xHigh>yellowMAshifted shortCondition = mab crosses under mbb AND mab>50 AND xLow<yellowMAshifted Longsell=mab crosses under mbb AND mab<upperzone and mab>50 AND xlow>yellowMAshifted Shortexit= mab crosses over mbb AND mab>lowerzone and mab<50 AND xhigh>yellowMAshifted //*************************** // open position // long IF Not LONGONMARKET AND longcondition THEN BUY PositionSize CONTRACT AT MARKET ENDIF // short IF Not SHORTONMARKET AND shortCondition THEN SELLSHORT PositionSize CONTRACT AT MARKET ENDIF // close position //Longsell IF LONGONMARKET and Longsell THEN SELL AT MARKET ENDIF //Shortexit IF SHORTONMARKET and Shortexit THEN EXITSHORT AT MARKET ENDIF |
Share this
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 :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Thank you Kasper for your contribution to the Library. I know this kind of strategy code can help a lot of people around here. You have put together a lot of other people pieces of work in one strategy to make yours and that’s fine. I can say that the objective of the website has been completed 🙂 Sharing our coding knowledge to help each other to better and quickly achieve the hard learning curves to build effective codes, even if they are not perfect. I can see code from Grizzly too and from Adolfo.
About the strategy, I tested it on PRT-CFD history (which is longer than the IG one), and I find it good too since mid-2015 (no history before that). Understand that the profit curve is not straight, but not deal with massive drawdown at all. Hope to see more from you soon 🙂
Hi! Thanks for sharing. I´m able to backtest the code a year. Here´s the result:
http://picgur.org/images/2016/08/07/Skarmavbild2016-08-07kl.17.37.03.png
thanks for the test. Still not bad, but room for improvement 🙂
Dear Mr. Brymas ,could you test the optimazed strategy of Elsbortrading below for 1 year ?Thanks All
Great work. I see you’ve used some of my code too 🙂
Yes Grizzly. That part is awesome 😀
Hi Casper,
I see you’ve been busy. Wondering if it would be better to remove on “shortexit” mab<50 and on “Longsell” mab>50. On recent history this reduces profits but only minimally but avoids seeing large erosion on the latest trade.
John
hi john. Yes quite busy. Regards the numbers I just found a way to optimise the them. I did not had the time yet
The reason i added those limmit is to catch the false breakout of a trade. It will save many orders that othervise would have a huge drawback
Hello guys. Using the optimization technique I was able to produce a more profitable code. still without the huge drawback. also it eliminated the one loss I had. I also added an extra streak to the Money Management code. 4 in a row- since we were doing so well. I’d still like if someone could be kind and test it back further as I still only have data since may 2016
//-------------------------------------------------------------------------
//TDI OIL Brent Crude (1£ Contracts) 2H ElsborgTrading V3
//
// based on Trend Surfer DAX-Reiner/Nicholas-TMS
//http://www.prorealcode.com/prorealtime-trading-strategies/trend-surfer-dax/
//http://www.prorealcode.com/topic/trading-made-simple-tms-system/
//http://www.forexmt4.com/_MT4_Systems/Traders%20Dynamics/TDI_1.pdf
//-------------------------------------------------------------------------
// code-Parameter
DEFPARAM CumulateOrders = true
//DEFPARAM FlatAfter = 230000
//DEFPARAM Flatbefore = 030000
//MONEY MGT//
Equity = (Strategyprofit+20000)
Risk = round(Equity/100000)
Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0
streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0
Streak2= positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0 and positionperf(4)>0
if losses then
PositionSize = max(abs(round(max(3+risk-2,risk-2))),2)
elsif not losses then
PositionSize = max(abs(round(max(3+risk,risk))),2)
endif
if streak then
PositionSize = max(abs(round(max(5+risk,risk))),2)
endif
if streak2 then
PositionSize = max(abs(round(max(7+risk,risk))),2)
endif
//TDI indicator
//parameters :
lengthrsi=13
lengthrsipl=2
lengthtradesl=7
//overbought and oversold values of the TDI indicator
upperzone = 65
lowerzone = 7
//upperzone = upz
//lowerzone = loz
//heiken ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen = (xOpen[1] + xClose[1])/2
xHigh = Max(xOpen, xClose)
xLow = Min(xOpen, xClose)
endif
//indicators
r = rsi[lengthrsi](close)
mab = average[lengthrsipl](r)
mbb = average[lengthtradesl](r)
yellowMA = average[5](TypicalPrice)
yellowMAshifted = yellowMA[2]
//trade conditions
longCondition = mab crosses over mbb AND mab<50 AND xHigh>yellowMAshifted
shortCondition = mab crosses under mbb AND mab>51 AND xLow<yellowMAshifted
//Longsell=mab crosses under mbb AND mab<upperzone and mab>56 AND xlow>yellowMAshifted
//Shortexit= mab crosses over mbb AND mab>lowerzone and mab<56 AND xhigh>yellowMAshifted
Longsell=mab crosses under mbb AND mab<upperzone and mab>55 AND xlow>yellowMAshifted
Shortexit= mab crosses over mbb AND mab>lowerzone and mab<58 AND xhigh>yellowMAshifted
//Longsell2=mab crosses under lowerzone
//Shortexit2=mab crosses over upperzone
//***************************
// open position
// long
IF Not LONGONMARKET AND longcondition THEN
BUY PositionSize CONTRACT AT MARKET
ENDIF
// short
IF Not SHORTONMARKET AND shortCondition THEN
SELLSHORT PositionSize CONTRACT AT MARKET
ENDIF
// close position
IF LONGONMARKET and Longsell then//or longsell2 THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET and Shortexit then//or shortexit2 THEN
EXITSHORT AT MARKET
ENDIF
// stop and profit
//SET STOP pLOSS sl
//SET TARGET pPROFIT tp
Ho notato che sembra dia buoni risultati su GBP/USD (la prima versione del codice)
Chi può postare un backtest più lungo ?
Grazie.
Miguel
Can i suggest, that this piece of code:
Risk = round(Equity/100000)be changed to
MaxPositionA = 50
Risk = min(round(Ratio*Equity/100000)*1,MaxPositionA)
Otherwise, risk -> infinity haha
Very nice Grizzly. I properly would have done some beginners programming like this, but yours has more “pronage” 🙂 My code is only running on Live demo for at least 3 month before considering investing real money in it. Mainly due to the small backtesting range- but if It would make it to real investment, I thing I also would start with only 1 contract
If PositionSize>=50 then
PositionSize=50
endif
to begin with
Grizzly, what should Ratio be?
I am also interested in your forward testing, as backtesting results are useless.
I agree, but since we don’t have any SL or TP at all, or any Profit on zero candle, I think it safe to say that this backtest is more useful. However 3 month is somewhat not enough.