Wanted: small code snippet for reinvestment
Forums › ProRealTime English forum › ProOrder support › Wanted: small code snippet for reinvestment
- This topic has 68 replies, 7 voices, and was last updated 7 years ago by Nicolas.
-
-
01/11/2018 at 1:18 PM #5904301/11/2018 at 1:22 PM #59044
Out of interest – what settings are you running on that SuperTrend on the 4HR chart?
[1.9, 10], as the image says on the upper left. The ATR component looks 10 periods back, and the supertrend line is 1.9 * ATR away from the medianprice, roughly spoken.
01/11/2018 at 1:39 PM #59051[1.9, 10], as the image says on the upper left.Sorry should have seen that – I think I need new glasses!01/12/2018 at 9:16 AM #59144You should have a look at this customized Supertrend
1 user thanked author for this post.
01/12/2018 at 1:27 PM #59179You should have a look at this customized Supertrend
I have tried out most of these variants, but the standard supertrend with ATR usually gives best results in simple systems that trade long and short from supertrend cut to supertrend cut. This criterion is usually a good first selection.
In addition, manual supertrends run slowly and decelerate backtests a lot.
The only real advantage I have ever found in a customized supertrend was to leave the volatility component (ATR or STD) away entirely, and replace it by a fixed amount of points – or better a fixed fraction of current price. Sometimes, especially when you do long backtests over 10 years with DAX prices ranging from 4.000 to 13.500, this gives better results. See the following example.
supertrend without volatility1234567891011121314151617181920212223242526272829303132333435363738394041ONCE direction = 1ONCE STlongold = 0ONCE STshortold = 1000000000000indicator1 = medianpriceindicator3 = closeindicator2 = indicator3 * factorSTlong = indicator1 - indicator2STshort = indicator1 + indicator2If direction = 1 and STlong < STlongold thenSTlong = STlongoldendifIf direction = -1 and STshort > STshortold thenSTshort = STshortoldendifIf direction = 1 and indicator3 crosses under STlong thendirection = -1endifIf direction = -1 and indicator3 crosses over STshort thendirection = 1endifSTlongold = STlongSTshortold = STshortIf direction = 1 thenST = STlongelseST = STshortendifReturn ST coloured by direction as "Supertrend"The parameter “factor” in line 9 changes the distance of the supertrend line from the last highest or lowest medianprice. It sets the distance to a fraction of the current “close” value. Try 0.005 as an initial setting, but of course it depends on the time scale and on the instrument you are looking at.
This supertrend will not move closer to the price in sideward movements (like the normal supertrend), when volatility decreases, but will stay constant all the time, as long as price does not change.
This version is also quite well optimized for speed.
01/12/2018 at 1:58 PM #59181That is an interesting new look at SuperTrend. I wasn’t getting any colour with the way the code is written. Never seen ‘coloured as’ before? So I changed it slightly. You should maybe put it in the library for others to consider using.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546ONCE direction = 1ONCE STlongold = 0ONCE STshortold = 1000000000000factor = 0.005indicator1 = medianpriceindicator3 = closeindicator2 = indicator3 * factorSTlong = indicator1 - indicator2STshort = indicator1 + indicator2If direction = 1 and STlong < STlongold thenSTlong = STlongoldendifIf direction = -1 and STshort > STshortold thenSTshort = STshortoldendifIf direction = 1 and indicator3 crosses under STlong thendirection = -1endifIf direction = -1 and indicator3 crosses over STshort thendirection = 1endifSTlongold = STlongSTshortold = STshortIf direction = 1 thenST = STlongR = 0G = 128elseST = STshortR = 128G = 0endifReturn ST coloured(R,G,0) Style(Line,2) as "Supertrend"01/12/2018 at 2:11 PM #5918201/12/2018 at 2:36 PM #59186That is an interesting new look at SuperTrend. I wasn’t getting any colour with the way the code is written. Never seen ‘coloured as’ before? So I changed it slightly. You should maybe put it in the library for others to consider using.
I usually prefer not to judge the optical impression of an indicator. People always show complex and nicely coloured indicators in a chart place that fits best their intentions and appears to work in this detail. In my opinion, the usefulness of an indicator can only be judged by coding a trading system that trades the signals of this indicator. So I rarely use my own indicators in charts, only in trading codes. But thanks for your colour code addition, anyway, so I do not have to look it up.
This version of supertrend is simpler than the normal supertrend, because there is only one adaptable parameter (factor). Curve fitting is not so easy, then. It behaves more like a common trailing stop, because volatility is not used.
01/12/2018 at 2:41 PM #59187colour was only coded this way so you can set it yourself in the indicator box. By default, it is black.
Thanks – wasn’t aware that you could do it like that.
01/12/2018 at 6:23 PM #59234Ich sehe das wir uns hier auf Deutsch unterhalten können.
Damit wird es für mich einfacher, verständlich zu bleiben.
Kannst du mir einen Gefallen tun, und den folgenden Code durch einen Backtest jagen und gucken ob die Ergebnisse halbwegs gleich sind?
Ich halte das Ergebnis schlichtweg für unglaublich.
den “Call NR7” kann ich nachreichen
Nikolas meinete “overfitted” dazu …. aber ja, von mir aus.
the only one123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187// Hauptcode : H4 live cxxxx last PF flat2100//-------------------------------------------------------------------------// Start Pathfinder-System// with define saisonal position multiplier for each month 1-15 / 16-31 (>0 - long / <0 - short / 0 no trade)defparam flatafter = 210000ONCE January1 = 3 //0 risk(3)ONCE January2 = 0 //3 okONCE February1 = 3 //3 okONCE February2 = 3 //0 risk(3)ONCE March1 = 3 //0 risk(3)ONCE March2 = 2 //3 okONCE April1 = 3 //3 okONCE April2 = 3 //3 okONCE May1 = 1 //0 risk(1)ONCE May2 = 1 //0 risk(1)ONCE June1 = 1 //1 ok 2ONCE June2 = 2 //3 okONCE July1 = 3 //1 chanceONCE July2 = 2 //3 okONCE August1 = 2 //1 chance 1ONCE August2 = 3 //3 okONCE September1 = 3 //0 risk(3)ONCE September2 = 0 //0 okONCE October1 = 3 //0 risk(3)ONCE October2 = 2 //3 okONCE November1 = 1 //1 okONCE November2 = 3 //3 okONCE December1 = 3 // 1 chanceONCE December2 = 2 //3 ok// set saisonal multipliercurrentDayOfTheMonth = DaymidOfMonth = 15IF CurrentMonth = 1 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = January1ELSEsaisonalPatternMultiplier = January2ENDIFELSIF CurrentMonth = 2 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = February1ELSEsaisonalPatternMultiplier = February2ENDIFELSIF CurrentMonth = 3 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = March1ELSEsaisonalPatternMultiplier = March2ENDIFELSIF CurrentMonth = 4 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = April1ELSEsaisonalPatternMultiplier = April2ENDIFELSIF CurrentMonth = 5 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = May1ELSEsaisonalPatternMultiplier = May2ENDIFELSIF CurrentMonth = 6 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = June1ELSEsaisonalPatternMultiplier = June2ENDIFELSIF CurrentMonth = 7 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = July1ELSEsaisonalPatternMultiplier = July2ENDIFELSIF CurrentMonth = 8 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = August1ELSEsaisonalPatternMultiplier = August2ENDIFELSIF CurrentMonth = 9 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = September1ELSEsaisonalPatternMultiplier = September2ENDIFELSIF CurrentMonth = 10 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = October1ELSEsaisonalPatternMultiplier = October2ENDIFELSIF CurrentMonth = 11 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = November1ELSEsaisonalPatternMultiplier = November2ENDIFELSIF CurrentMonth = 12 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = December1ELSEsaisonalPatternMultiplier = December2ENDIFEndifposition = 2// End Pathfinder-System//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Start Code Indicator NR7//-------------------------------------------------------------------------// C1= Range<Range[1] and Range<Range[2] and Range<Range[3] and Range<Range[4] and Range<Range[5] and Range<Range[6] and Range<Range[7]// RETURN C1//-------------------------------------------------------------------------// End Code IndicatorNr7//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Start Hauptcode//-------------------------------------------------------------------------// Hauptcode : H4 Live//-------------------------------------------------------------------------//-------------------------------------------------------------------------//-------------------------------------------------------------------------//-------------------------------------------------------------------------//cx = CALL "NR7"cx1 = cci[11]<80cx2 = cci[21]>-90cx3 = Momentum[6](close)>0cx4 = ADX[11] >15// cx5 = MoneyFlow[11](close)<0cx6 = TR(close) >25//cx7 = PVT(close)<1cx8 = EaseOfMovement[14]<95cx9 = SmoothedStochastic[14,3](close)<95cx10 = PriceOscillator[5,25](close)<0.5cx11 = LinearRegressionSlope[10](close)>-14cx12 = AccumDistr(close)>-0.1cx13 = Chandle [20](close)>-51cx14 = STD[6](close)<99cx15 = DPO[21](close)>-50cx16 = DPO[21](close)<50TradingDayShort = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5TradingTimeShort = time = 090000 or time = 130000 or time = 170000TradingtimeLong = time = 090000 or Time = 130000 or time = 170000IF TradingDayShort and TradingTimeShort Then//IF not cx ThenIF cx1 and cx4 and cx8 and cx9 and cx10 and cx12 and cx14 and cx15 ThenIF ExponentialAverage [1] (close) < ExponentialAverage [8] (close) THENsellshort position*saisonalPatternMultiplier CONTRACTS AT MARKETENDIFEndif//EndifEndifIF TradingDayLong and TradingTimeLong ThenIF cx2 and cx3 and cx6 and cx11 and cx13 and cx16 ThenIF ExponentialAverage [1] (close) > ExponentialAverage [8] (close) THENbuy position*saisonalPatternMultiplier CONTRACT AT MARKETENDIFEndifEndifSet Stop %Loss 1Set Target %profit 201/12/2018 at 6:24 PM #5923901/12/2018 at 7:22 PM #5925501/12/2018 at 7:27 PM #59256Hello JohnScher. Yes speaking German is fine….. only I don’t understand a word of it…. oh and the moderators will be along any minute to tell you not to in an English speaking forum. I just use Google translate though – it is normally good for a laugh.
I have not tested the above strategy for two reasons that are shown in the images. It just will not work in real life which is why the equity line is so perfect.
01/12/2018 at 7:28 PM #5926001/12/2018 at 7:31 PM #59261 -
AuthorPosts