Indexbond-Contrarian-orders
Forums › ProRealTime English forum › ProOrder support › Indexbond-Contrarian-orders
- This topic has 8 replies, 4 voices, and was last updated 7 years ago by Bard.
-
-
03/25/2017 at 11:14 AM #2980003/25/2017 at 12:31 PM #2980803/25/2017 at 1:37 PM #2981104/17/2017 at 8:08 AM #32266
HI all,
I rewied a bit the strategy in order to be more conservative (and there was a bug too…..)
Could anyone test on 200 k bars (12 H) ???
here the code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546//DAX OR DAX MINI//12 hDEFPARAM cumulateorders = trueTIMEWORK = 010000TIMESTOP = 230000period=3stdev=STD[period](close)TPC = STDEV / CLOSE *100FIRSTacc = 0.5 * TPCtp = 2 * TPCNEXTacc = 20 * TPC//IF YOU WANT TO LIMIT THE NUMBER OF CONTRACT SET THE FOLLOWING PARAM TO A LOWER AMOUNTCONTRACTLIM = 2000if (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) < (stdev[1]+stdev[2]+stdev[3]+stdev[4]+stdev[5]) thenSWBUY=1elseSWBUY=0ENDIFP1 = ((CLOSE -CLOSE[1]) / CLOSE * 100) < -FIRSTaccIF TIME > TIMEWORK AND TIME < TIMESTOP THENif not onmarket thensizebuy = 1IF SWBUY=1 AND P1 THENBUY sizebuy SHARES AT MARKETendifendifif LONGONMARKET thenLASTperf = (close - TRADEPRICE)/TRADEPRICE * 100GLOBperf = (close - POSITIONPRICE)/POSITIONPRICE * 100if GLOBperf > tp thenSELl AT MARKETELSEIF COUNTOFPOSITION >= CONTRACTLIM THENSELL AT MARKETENDIFif LASTperf < -NEXTacc and SWBUY=1 thenBUY sizebuy SHARES AT MARKETENDIFENDIFENDIFENDIF1 user thanked author for this post.
04/17/2017 at 5:29 PM #3232804/17/2017 at 8:46 PM #32363Hi DEIO.
I can’t find any problems preback-testing at all. It LOOKS like it buys on downtrend but I can’t see if losing any money anyway, so I don’t exactly understand how it works. Thanks, going to test it on many indexes/bonds on my demo-account!
06/21/2017 at 12:24 AM #38695Hi Deio, Sorry for the long delay due to family matters, I’ve only just been getting back into research in the last few weeks.
I thought about this strategy a lot. I tested it on many variations adding different indicators and altering parameters or hours traded and then tested it on other indexes. At times, you can get the profit up or the drawdown down in tests by adding the Ehler’s Universal Supersmoother Oscillator as a trend filter – but it still hasn’t totally stopped the system buying into steep declines and accumulating positions, although the Damiani Indicator can sometimes help on backtests with parameters:
//—settings
Viscosity=7 //Default=7 //try 5
Sedimentation=50 //Default 50 //try 60
Thresholdlevel=1.1 //Default 1.1
lagsupressor=1 //boolean value (default=true)
MAtype=2 //MA type variable (2=Weighted average) //Default 2
//—end of settings(Nicolas kindly posted both the codes on this forum).
I don’t have reference to that particular exact Nikkei strategy mentioned in your original post but I changed the code slightly to something like this:
Index/Bond Strategy Slow Accumulation using St Dev.rtfd1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586//-----------------------------------------------------------------------------------------------//Deio//TF a 12 h//dax min 1 Eur.//-----------------------------------------------------------------------------------------------//TAKE PROFIT NEAR ZERO IN ORDER TO NOT ACCUMULATE TOO MUCH//-----------------------------------------------------------------------------------------------//IF NOT ON MARKET TRY TO ENTER AGAIN AS SOON A CORRECTION APPEARS, TRYING TO FOLLOW//THE POTENTIAL CURRENT UPTREND//-----------------------------------------------------------------------------------------------//IF I BOUGHT THE PREVIOUS BAR DON'T BUY THE FOLLOWING BAR IN ORDER TO NOT ACCUMULATE TOO MUCH//-----------------------------------------------------------------------------------------------//MAIN PARAMETER IN ORDER TO CHANGE THE RISK LEVELS ARE://acc----> % of decrease of (price)of the instrument compared to the last buy price (THE LOWER IT//IS THE MORE RISK AND CASH RETURN WILL OCCUR)//-----------------------------------------------------------------------------------------------//tp-----> % beyond which the entire position is closed (THE HIGHER IT IS AND MORE// RISK AND CASH RETURN WILL APPEAR) - below zero is safer !//-----------------------------------------------------------------------------------------------//MONEY MANAGMENT "ANTIMARTINGALA" STYLE - I SUPPOSE CLEARER RESULTS ON A LONGER PERIOD OF BACKTEST//-----------------------------------------------------------------------------------------------DEFPARAM cumulateorders = trueTIMEWORK = 080000TIMESTOP = 180000acc = 2 //orig 5if justone = 0 thencapital = 10000 * pointvaluejustone = 1endifperccap = 0.5 //0rig 0.5margin = 0.5 * close * pointvalue / 100period=5// Conditions to enter long positions // Univ Osc Bandedge =25indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"c1 = (indicator1 > -0.9)// Conditions to enter long positionsindicator1, indicator2 = CALL "Damiani Volameter"(close)c2 = (indicator1 > indicator2) //When Damiani is greenstdev=STD[period](close)//LOOK FOR A LOCAL VOLATILITY DECREASE//I WANT TO BUY AGAIN ONLY WHEN BEAR MARKET SHOWS A LOCAL PAUSEif C1 AND C2 AND (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) < (stdev[1]+stdev[2]+stdev[3]+stdev[4]+stdev[5]) thenSWBUY=1elseSWBUY=0ENDIF//default Close > Close. Use <IF TIME > TIMEWORK AND TIME < TIMESTOP THENif not onmarket thensizebuy = ROUND((capital *perccap /100)/ margin)tp = 0.25 //orig 0.25IF CLOSE > CLOSE[100] THENBUY sizebuy SHARES AT MARKETendifendifif LONGONMARKET thenperf = (close - POSITIONPRICE)/POSITIONPRICE * 100if perf > tp thenSELL AT MARKETperfc = (close - POSITIONPRICE) * POINTVALUE * COUNTOFPOSITIONcapital = capital + PERFCELSEIF LASTBARBUY = 0 THENif (((CLOSE-TRADEPRICE)/TRADEPRICE)*100) < -acc AND SWBUY=1 thensizebuy = ROUND((capital *perccap /100)/ margin)BUY sizebuy SHARES AT MARKETLASTBARBUY = 1ENDIFELSELASTBARBUY = 0ENDIFENDIFENDIFENDIFNote: I tried to add a graph of the std deviation but I am not sure it is correctly coded:
Graph showing std deviation requirement12SWBUY = (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) < (stdev[1]+stdev[2]+stdev[3]+stdev[4]+stdev[5])Graph SWBUY=1Creating code that stops the strategy from buying more positions if the equity curve is falling:
It occurred to me today that one way to stop it buying and accumulating positions in steep market declines maybe to add code that stops it doing that based on the equity curve. I have read threads on this forum that suggest that may not work, so what is needed is a “Black Swan” warning based on either a sharp momentum (proceeds price) move or very sharp increases in volatility.
Close>Close[1]
Changed to Close<Close[100]. I’ve included an Excel screen of the Period close optimisation to show that there is a stable range b/n 60 bars and 150.Testing on the Nikkei 30 mins charts there is only marginal improvement in drawdown and not a particularly stable relationship between profit and the period of the chart 1, 2 hrs chosen – i.e. longer timeframes fail.
Btw what was the bug you mentioned that you found in v.1.0?
I tested this new strategy V.2.0 above today, on the S&P 500 and Dax, but I’m not sure (due to limited testing) if it is performing better than V.1.0 that you posted 3 months ago. I haven’t quite figured it all out yet.
Nice work Deio,
Cheers
Bard06/21/2017 at 5:52 AM #3870306/23/2017 at 9:08 PM #38928Sure Reb, here’s the links for you:
https://www.prorealcode.com/prorealtime-indicators/universal-oscillator-john-ehlers/
https://www.prorealcode.com/prorealtime-indicators/damiani-volameter/It’s worth reading up on how the indicators function and there’s also a lot of John Ehler’s research papers on his cycle theory on the net too. Here’s his website:
http://www.mesasoftware.com/Cheers
Bard -
AuthorPosts