Help for adding martingala
Forums › ProRealTime English forum › ProOrder support › Help for adding martingala
- This topic has 4 replies, 2 voices, and was last updated 8 years ago by michymx.
-
-
10/05/2016 at 4:25 PM #14313
Good evening to all,
i would like to implement a martingala in my ts but i’m missing something.
My sistem buy and sell according to a cross between 2 moving averages, but don’t reverse. The sistem has a strong stop and tprofit.
I set the code below, but the martingala doesn’t work.
Someone can help please?
THX!
1234567891011121314151617181920212223242526272829mygreen, myred, ignored = CALL TDIc1= mygreen crosses over myredc2=mygreen crosses under myreda=ExponentialAverage[100](close)ONCE OrderSize =1ONCE ExitIndex =-2if c1 and close > a thenbuy ordersize shares at marketendifExitIndex=BarIndexif c2 and close <a thensellshort ordersize shares at marketendifExitIndex=BarIndexIF Barindex = ExitIndex + 1 THENExitIndex = 0IF PositionPerf(1) < 0 THENOrderSize = OrderSize*2+1ELSIF PositionPerf(1) > 0 THENOrderSize =1ENDIFENDIFset target pprofit 60set stop ploss 2010/05/2016 at 5:30 PM #14321First of all, your CALL is wrong, please take a look at the documentation, to make it properly : http://www.prorealcode.com/documentation/call/
Please provide the TDI indicator code you are calling in case the problem come from this one, once you have modified your line 2. Thank you.
10/05/2016 at 5:37 PM #14324Hi Nicolas,
this is my tdi indicator.
myrsi=RSI[13](close)
a=Average[2](myrsi)
b=Average[7](myrsi)
c=Exponentialaverage[34](myrsi)
return a as “green”, b as “red”, c as “yellow”But the problem is not the call function but the martingala set. Doesn’t work in backtest. After a losing position the proorder doesn’t open the right position size.
10/05/2016 at 7:59 PM #14348Here is your modified code.
If you don’t want your strategy to take multiple orders at the same time, use the instruction I put at line 1.
If you need hard takeprofit and stoploss, you should test if you are not on market before launch another contrarian order, otherwise it will close the current one at market.
About your martingale position sizing, you need to compute it only when you try to put order on market, otherwise the code will increment the size of the position at each new candle (when the script is read).
1234567891011121314151617181920212223242526272829303132333435defparam cumulateorders = falsemyrsi=RSI[13](close)mygreen=Average[2](myrsi)myred=Average[7](myrsi)c1= mygreen crosses over myredc2=mygreen crosses under myreda=ExponentialAverage[100](close)ONCE OrderSize =1if not onmarket thenif c1 and close > a thenIF PositionPerf(1) < 0 THENOrderSize = OrderSize*2//+1ELSIF PositionPerf(1) > 0 THENOrderSize =1ENDIFbuy ordersize shares at marketendifif c2 and close <a thenIF PositionPerf(1) < 0 THENOrderSize = OrderSize*2//+1ELSIF PositionPerf(1) > 0 THENOrderSize =1ENDIFsellshort ordersize shares at marketendifendifset target pprofit 60set stop ploss 20EDIT/ just saw that it is my 2000th post!
10/05/2016 at 9:17 PM #14352 -
AuthorPosts
Find exclusive trading pro-tools on