Help for adding martingala

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14313 quote
    michymx
    Participant
    New

    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!

    
    mygreen, myred, ignored = CALL TDI
    c1= mygreen crosses over myred
    c2=mygreen crosses under myred
    a=ExponentialAverage[100](close)
    
    ONCE OrderSize =1
    ONCE ExitIndex =-2
    
    if c1 and close > a  then
    buy ordersize shares at market
    endif
    ExitIndex=BarIndex
    
    if c2 and close <a  then
    sellshort ordersize shares at market
    endif
    
    ExitIndex=BarIndex
    
    IF Barindex = ExitIndex + 1 THEN
    ExitIndex = 0
    IF PositionPerf(1) < 0 THEN
    OrderSize = OrderSize*2+1
    ELSIF PositionPerf(1) > 0 THEN
    OrderSize =1
    ENDIF
    ENDIF
    set target pprofit 60
    set stop ploss 20
    #14321 quote
    Nicolas
    Keymaster
    Master

    First 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.

    #14324 quote
    michymx
    Participant
    New

    Hi 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.

    #14348 quote
    Nicolas
    Keymaster
    Master

    Here 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).

    defparam cumulateorders = false
    
    myrsi=RSI[13](close)
    mygreen=Average[2](myrsi)
    myred=Average[7](myrsi)
    
    c1= mygreen crosses over myred
    c2=mygreen crosses under myred
    
    a=ExponentialAverage[100](close)
    
    ONCE OrderSize =1
    
    if not onmarket then
    if c1 and close > a  then
    IF PositionPerf(1) < 0 THEN
    OrderSize = OrderSize*2//+1
    ELSIF PositionPerf(1) > 0 THEN
    OrderSize =1
    ENDIF
    buy ordersize shares at market
    endif
    
    if c2 and close <a  then
    IF PositionPerf(1) < 0 THEN
    OrderSize = OrderSize*2//+1
    ELSIF PositionPerf(1) > 0 THEN
    OrderSize =1
    ENDIF
    sellshort ordersize shares at market
    endif
    endif
    
    set target pprofit 60
    set stop ploss 20

    EDIT/ just saw that it is my 2000th post!

    #14352 quote
    michymx
    Participant
    New

    Thank you so much!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Help for adding martingala


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
michymx @michymx Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by michymx
9 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/05/2016
Status: Active
Attachments: No files
Logo Logo
Loading...