Pause system X time after Y losses

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #203853 quote
    SnorreDKSnorreDK
    Participant
    Junior

    Hi.

    I need help to make this possible for a 6min-algo

    Pause system X time after Y losses

     

    X= variable in minutes , bars or hours

    Y=variable count of losses (1-10)

    #203856 quote
    SnorreDKSnorreDK
    Participant
    Junior

    See picture.

    loss.jpg loss.jpg
    #203866 quote
    SnorreDKSnorreDK
    Participant
    Junior

    This one did not work:

    positionperf2 = positionperf(1)
    graph positionperf
    graph positionperf(1) coloured (255,0,0)
    
    if positionperf2<positionperf2[1] then
    if (positionperf2 > 0) then
    lossrunno = 0
    buysignal = barindex
    winrunno = (winrunno + 1)
    endif
    
    if (positionperf2 < 0) then
    winrunno = 0
    lossrunno = (lossrunno + 1)
    endif
    endif
    
    if lossrunno=1 then
    distancebuysignal=(Barindex-buysignal)
    endif
    
    if lossrunno=1 and (distancebuysignal > x)  then
    lossrunno=0
    endif
    
    if (lossrunno=0) then
    If MyConditionLong  then 
    Buy PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS sll
    ENDIF
    If MyConditionShort then
    sellshort PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS sls
    ENDIF
    endif
    #203873 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    ONCE MaxLosses = 2     //Y losses
    ONCE PauseBars = 30    //X bars to pause
    ONCE Losses    = 0
    ONCE BarStart  = 0
    MyLongConditions  = close CROSSES OVER  average[20,0](close) AND Not OnMarket
    MyShortConditions = close CROSSES UNDER average[20,0](close) AND Not OnMarket
    IF StrategyProfit > StrategyProfit[1] THEN
       Losses   = 0
       BarStart = 0
    ELSIF StrategyProfit < StrategyProfit[1] THEN
       Losses   = Losses + 1
       IF Losses = MaxLosses THEN
          BarStart = BarIndex
          Losses   = 0
       ENDIF
    ENDIF
    IF (BarIndex - BarStart) >= PauseBars THEN
       BarStart = 0
    ENDIF
    IF MyLongConditions  AND BarStart = 0 THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    IF MyShortConditions AND BarStart = 0 THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    SET STOP   pLOSS   100
    SET TARGET pPROFIT 300
    SnorreDK thanked this post
    #203896 quote
    SnorreDKSnorreDK
    Participant
    Junior

    Thanks robberto. it seems to work on the trades of same direction but not the oposit direction:

    See attached

     

    ONCE MaxLosses = 1     //Y losses
    ONCE PauseBars = x    //X bars to pause
    ONCE Losses    = 0
    ONCE BarStart  = 0
    
    IF StrategyProfit > StrategyProfit[1] THEN
    Losses   = 0
    BarStart = 0
    ELSIF StrategyProfit < StrategyProfit[1] THEN
    Losses   = Losses + 1
    IF Losses = MaxLosses THEN
    BarStart = BarIndex
    Losses   = 0
    ENDIF
    ENDIF
    IF (BarIndex - BarStart) >= PauseBars THEN
    BarStart = 0
    ENDIF
    
    
    if BarStart =0 then
    If MyLongCond then
    Buy PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS sll
    ENDIF
    If MyShortCond  then
    sellshort PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS sls
    ENDIF
    endif

    I even tried this:

    If MyLongCond and BarStart =0 then
    Buy PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS sll
    ENDIF
    If MyShortCond and  BarStart =0 then
    sellshort PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS sls
    ENDIF
    1-1.jpg 1-1.jpg 2-1.jpg 2-1.jpg
    #204018 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    This one works like a charm:

    ONCE MaxLosses = 3     //Y losses
    ONCE PauseBars = 30    //X bars to pause
    ONCE Losses    = 0
    ONCE BarStart  = 0
     
    MyLongCond  = close CROSSES OVER  average[20,0](close) AND Not OnMarket
    MyShortCond = close CROSSES UNDER average[20,0](close) AND Not OnMarket
    
    IF StrategyProfit > StrategyProfit[1] THEN
    Losses   = 0
    BarStart = 0
    ELSIF StrategyProfit < StrategyProfit[1] THEN
    Losses   = Losses + 1
    IF Losses = MaxLosses THEN
    BarStart = BarIndex
    Losses   = 0
    ENDIF
    ENDIF
    IF (BarIndex - BarStart) >= PauseBars THEN
    BarStart = 0
    ENDIF
     
     
    if BarStart = 0 then
    If MyLongCond then
    Buy 1 CONTRACTS AT MARKET
    SET STOP %LOSS 0.1
    ENDIF
    If MyShortCond  then
    sellshort 1 CONTRACTS AT MARKET
    SET STOP %LOSS 0.1
    ENDIF
    endif
    graph Losses
    graph BarStart
    graph StrategyProfit < StrategyProfit[1] coloured("Red")
    graph StrategyProfit > StrategyProfit[1] coloured("Green")
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Pause system X time after Y losses


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
SnorreDK @snorredk Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
3 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/09/2022
Status: Active
Attachments: 3 files
ProRealCode ProRealCode
Loading...