again martingale to code
Forums › ProRealTime English forum › ProOrder support › again martingale to code
- This topic has 4 replies, 2 voices, and was last updated 2 years ago by
JohnScher.
-
-
12/17/2022 at 2:27 PM #205950
Have a great day.
I have again taken an old indicator from the library, rebuilt it into a strategy and added a temporal component. It is not the holy grail but the result is quite respectable. Explanation attempt is the dependence of the Dax40 on the (strong) us indices and their opening.
Clear to me is the danger of martingale if you do not have an infinite number of attempts and infinite funds.
I searched Prorealcode for Martingale and found some things, but there was nothing really suitable. I am sorry.
What I would like to ask you is that one of you program me here a martingale that after a loss increases the number of positions by 1 position and after a profit decreases the number of positions by 1 position, but at least always trades 1 position.
Below the code of the strategy and also attached the itf-file.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546//PRC_MACD Platinum | indicator// 29.09.2016// Nicolas @ www.prorealcode.com// Sharing ProRealTime knowledge// written to a long only strategy buy JohnScher 17.12.2022// timeframe 15M// timezone europetime, berlindefparam cumulateorders = falseshort = 12long = 26signal = 9EMAshort1 = exponentialaverage[short](close)EMAshort2 = exponentialaverage[short](EMAshort1)DifferenceShort = EMAshort1 - EMAshort2ZeroLagShort = EMAshort1 + DifferenceShortEMAlong1 = exponentialaverage[long](close)EMAlong2 = exponentialaverage[long](EMAlong1)DifferenceLong = EMAlong1 - EMAlong2ZeroLagLong = EMAlong1 + DifferenceLongZeroLagMACD = ZeroLagShort - ZeroLagLongsignal1=ExponentialAverage[signal](ZEROLAGMACD)signal2=ExponentialAverage[signal](signal1)DIFFERENCE2=signal1-signal2SignalMACD=signal1+DIFFERENCE2c1 = time >= 160000 and time <= 170000c2 = signalMACD >= zerolagMACD and zerolagMACD crosses under signalMACDtradebuy = c1 and c2If tradebuy thenbuy at marketEndifset stop ploss 100set target pprofit 10012/17/2022 at 4:04 PM #205959There you go:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657//PRC_MACD Platinum | indicator//29.09.2016//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge// --- settings//written to a strategy buy JohnScher 17.12.2022defparam cumulateorders = falseONCE PositionSize = 1ONCE Incr = 1 //increments after each winONCE Decr = 1 //decrements after each lossONCE MinLots = 1 //not less that 1 positionONCE MaxLots = 999 //max lots to be tradedshort = 12long = 26signal = 9//IF StrategyProfit > StrategyProfit[1] THENPositionSize = min(MaxLots,PositionSize + Incr)ELSIF StrategyProfit < StrategyProfit[1] THENPositionSize = max(MinLots,PositionSize - Decr)ENDIF// --- end of settingsEMAshort1 = exponentialaverage[short](close)EMAshort2 = exponentialaverage[short](EMAshort1)DifferenceShort = EMAshort1 - EMAshort2ZeroLagShort = EMAshort1 + DifferenceShortEMAlong1 = exponentialaverage[long](close)EMAlong2 = exponentialaverage[long](EMAlong1)DifferenceLong = EMAlong1 - EMAlong2ZeroLagLong = EMAlong1 + DifferenceLongZeroLagMACD = ZeroLagShort - ZeroLagLongsignal1=ExponentialAverage[signal](ZEROLAGMACD)signal2=ExponentialAverage[signal](signal1)DIFFERENCE2=signal1-signal2SignalMACD=signal1+DIFFERENCE2c1 = time >= 160000 and time <= 170000c2 = signalMACD >= zerolagMACD and zerolagMACD crosses under signalMACDtradebuy = c1 and c2If tradebuy thenbuy PositionSize contracts at marketEndifset stop ploss 100set target pprofit 1001 user thanked author for this post.
12/17/2022 at 6:44 PM #20597312/17/2022 at 7:07 PM #205975And thanks again, but it doesn’t fit.
We start with strategy profit = 0 and trade 1 position. We win the first trade. So the strategy profit is bigger than the strategy profit before. So we continue trading with 1 position.
Only when we have lost 1 trade, we trade with 2 positions. If we have lost 2 trades in a row, we trade with 3 positions. If we then win 1 trade, the number of positions decreases by 1 position (3 to 2). And so one.
1 Position we won, 1 position decrease. 1 position we lost, 1 position increase. This is not done with your code.
Can you code it that way?
see attached12/19/2022 at 5:55 PM #206034Danke.
Ich habe es hier auf Proreal gefunden.
Ich habe es in die 4HS Storm integriert…
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273//------------------------------------------------------------------// OnlyShort Strategy on Dax// Dax 1 Euro Mini// TimeZone europe, berlin// TimeFrame 4H// Maincoce : 4HS STORM - ShorT On Rising Markets with martingale// created and coded by JohnScher//------------------------------------------------------------------defparam cumulateorders = false // works with true tooONCE OrderSize = 1ONCE ExitIndex = -2period1 = 50period2 = 100//Pentuple Exponential Moving AveragePeriod = MAX(Period1, 1)MA1 = ExponentialAverage[Period](close)MA2 = ExponentialAverage[Period](MA1)MA3 = ExponentialAverage[Period](MA2)MA4 = ExponentialAverage[Period](MA3)MA5 = ExponentialAverage[Period](MA4)MA6 = ExponentialAverage[Period](MA5)MA7 = ExponentialAverage[Period](MA6)MA8 = ExponentialAverage[Period](MA7)pema = (8 * MA1) - (28 * MA2) + (56 * MA3) - (70 * MA4) + (56 * MA5) - (28 * MA6) + (8 * MA7) - MA8//Hull Moving AveragePeriod2 = MAX(Period2, 1)hma = WeightedAverage[ROUND(SQRT(Period2))](2 * WeightedAverage[ROUND(Period2 / 2)](close) - WeightedAverage[Period2](close))tm = openmonth <> 4 and openmonth <> 10td = opendayofweek >= 2 and opendayofweek <= 5tt = time >= 090000 and time <= 210000c1 = close > pema //two averagesc2 = pema > hmac3 = close < close[1] // could be tested with some bearish candlestick patternc4 = close[2] < close[1]c5 = averagetruerange [5] > 40 // filter, someone could be find betteronec11 = tm and td and ttc12 = c1 and c2 and c3 and c4 and c5IF c11 and c12 thensellshort ordersize contracts at marketendifIf ShortOnMarket THENExitIndex=BarIndexENDIFset stop %loss 2set target %profit 2// positions sizingIF Barindex= ExitIndex+1 THENExitIndex =0IF PositionPerf(1)<0 THENOrderSize = OrderSize+1ELSIF PositionPerf(1)>=0 THENOrderSize =MAX(OrderSize-1,1)ENDIFENDIF -
AuthorPosts
Find exclusive trading pro-tools on