again martingale to code

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #205950 quote
    JohnScher
    Participant
    Veteran

    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.

    //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, berlin
    
    defparam cumulateorders = false
    
    short = 12
    long = 26
    signal = 9
    
    EMAshort1 = exponentialaverage[short](close)
    EMAshort2 = exponentialaverage[short](EMAshort1)
    
    DifferenceShort = EMAshort1 - EMAshort2
    ZeroLagShort = EMAshort1 + DifferenceShort
    
    EMAlong1 = exponentialaverage[long](close)
    EMAlong2 = exponentialaverage[long](EMAlong1)
    
    DifferenceLong = EMAlong1 - EMAlong2
    ZeroLagLong = EMAlong1 + DifferenceLong
    
    ZeroLagMACD = ZeroLagShort - ZeroLagLong
    
    signal1=ExponentialAverage[signal](ZEROLAGMACD)
    
    signal2=ExponentialAverage[signal](signal1)
    
    DIFFERENCE2=signal1-signal2
    SignalMACD=signal1+DIFFERENCE2
    
    c1 = time >= 160000 and time <= 170000
    c2 = signalMACD >= zerolagMACD and zerolagMACD crosses under signalMACD
    tradebuy = c1 and c2
    
    If tradebuy then
    buy at market
    Endif
    
    
    set stop ploss 100
    set target pprofit 100
    
    strat-macd-platinum.itf
    #205959 quote
    robertogozzi
    Moderator
    Master

    There you go:

    //PRC_MACD Platinum | indicator
    //29.09.2016
    //Nicolas @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    // --- settings
    //written to a strategy buy JohnScher 17.12.2022
    
    defparam cumulateorders = false
    
    ONCE PositionSize = 1
    ONCE Incr         = 1     //increments after each win
    ONCE Decr         = 1     //decrements after each loss
    ONCE MinLots      = 1     //not less that 1 position
    ONCE MaxLots      = 999   //max lots to be traded
    
    short  = 12
    long   = 26
    signal = 9
    //
    IF StrategyProfit > StrategyProfit[1] THEN
    PositionSize = min(MaxLots,PositionSize + Incr)
    ELSIF StrategyProfit < StrategyProfit[1] THEN
    PositionSize = max(MinLots,PositionSize - Decr)
    ENDIF
    
    // --- end of settings
    EMAshort1 = exponentialaverage[short](close)
    EMAshort2 = exponentialaverage[short](EMAshort1)
    
    DifferenceShort = EMAshort1 - EMAshort2
    ZeroLagShort = EMAshort1 + DifferenceShort
    
    EMAlong1 = exponentialaverage[long](close)
    EMAlong2 = exponentialaverage[long](EMAlong1)
    
    DifferenceLong = EMAlong1 - EMAlong2
    ZeroLagLong = EMAlong1 + DifferenceLong
    
    ZeroLagMACD = ZeroLagShort - ZeroLagLong
    
    signal1=ExponentialAverage[signal](ZEROLAGMACD)
    
    signal2=ExponentialAverage[signal](signal1)
    
    DIFFERENCE2=signal1-signal2
    SignalMACD=signal1+DIFFERENCE2
    
    c1 = time >= 160000 and time <= 170000
    c2 = signalMACD >= zerolagMACD and zerolagMACD crosses under signalMACD
    tradebuy = c1 and c2
    
    If tradebuy then
    buy PositionSize contracts at market
    Endif
    
    set stop ploss 100
    set target pprofit 100
    JohnScher thanked this post
    strat-macd-platinum-2.itf
    #205973 quote
    JohnScher
    Participant
    Veteran

    Thank you, thank you, thank you.
    It’s not the first time you helped me, all the more, thank you!

    #205975 quote
    JohnScher
    Participant
    Veteran

    And 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 attached

    Screenshot_7.png Screenshot_7.png
    #206034 quote
    JohnScher
    Participant
    Veteran

    Danke.

    Ich habe es hier auf Proreal gefunden.

    Ich habe es in die 4HS Storm integriert…

     

     

    //------------------------------------------------------------------
    // 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 too
    
    ONCE OrderSize = 1
    ONCE ExitIndex = -2
    
    
    period1 = 50
    period2 = 100
     
    //Pentuple Exponential Moving Average
    Period = 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 Average
    Period2 = MAX(Period2, 1)
    
    hma = WeightedAverage[ROUND(SQRT(Period2))](2 * WeightedAverage[ROUND(Period2 / 2)](close) - WeightedAverage[Period2](close))
    
    tm = openmonth <> 4 and openmonth <> 10
    td = opendayofweek >= 2 and opendayofweek <= 5
    tt = time >= 090000 and time <= 210000
    
    c1 = close > pema //two averages
    c2 = pema  > hma
    
    c3 = close    < close[1] // could be tested with some bearish candlestick pattern
    c4 = close[2] < close[1]
    
    c5 = averagetruerange [5] > 40 // filter, someone could be find betterone
    
    c11 = tm and td and tt
    c12 = c1 and c2 and c3 and c4 and c5
    
    IF c11 and c12 then
    sellshort ordersize contracts at market
    endif
    
    If ShortOnMarket  THEN
    ExitIndex=BarIndex
    ENDIF
    
    set stop %loss 2
    set target %profit 2
    
    // positions sizing
    IF Barindex= ExitIndex+1 THEN
    ExitIndex =0
    IF PositionPerf(1)<0 THEN
    OrderSize = OrderSize+1
    ELSIF PositionPerf(1)>=0 THEN
    OrderSize =MAX(OrderSize-1,1)
    ENDIF
    ENDIF
    
    4HS-Storm-martingale.itf
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

again martingale to code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
JohnScher @johnscher Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/17/2022
Status: Active
Attachments: 4 files
Logo Logo
Loading...