Correct way to use PositionPerf for increasing OrderSize

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #154699 quote
    theo123
    Participant
    Junior

    Hi,

    what is the correct way to increase or change ordersize based on either loss or win from previous trade.  The below I created does not proceed to order anything when I do the probacktest.  Should this be embedded somewhere?

    can “OrderSize”  be stated “OrderSize[1]” meaning previous Ordersize same as notation of close, indicators, etc?

    Once OrderSize=1
    if positionperf(1)>0 OR positionperf(2)>0 and positionperf(1)<=0 then //starts with first 2 loses, 1 order (no increase)
    OrderSize =1
    elsif positionperf(2)<=0 and positionperf(1)<=0 then //after 2 or more loses, ordersize is the sum of previous 2 ordersize
    OrderSize =OrderSize[1]+OrderSize[2]
    endif
    #154807 quote
    robertogozzi
    Moderator
    Master

    1. what size do you want to start with?

    2. what increment does it have to perform after a WIN?

    3. what decrement does it have to perform after a LOSS?

    #155836 quote
    theo123
    Participant
    Junior

    Hi Roberto, I was able to just copy the one in the manual – The Piquemouche.  Now I have a different issue.  It was working before but it is not woking after update to Ver11.  I posted it as another topic.

    #155839 quote
    Vonasi
    Moderator
    Master

    theo123 – I deleted that double post. Please pay attention to the forum rules.

    • Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.
    #155843 quote
    robertogozzi
    Moderator
    Master

    Please post the code and explain better any issue you have.

    #155850 quote
    theo123
    Participant
    Junior

    Here you go.  This works before v11 but now it does not after update.  Thanks for checking.

    defparam preloadbars=10000
    
    oNCE OrderSize = 1
    ONCE BadTrades = 0
    ONCE ExitIndex = -2
    
    //some entry codes here
    
    //The Piquemouche
    IF NOT LongOnMarket AND LongEntry THEN
    
    BUY OrderSize CONTRACTS AT MARKET
    set stop ploss LongSLpip
    set target Profit TakeProfit
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND LongExitDoor THEN
    SELL AT MARKET
    ExitIndex=BarIndex
    ENDIF
    
    // Conditions to enter SHORT positions
    IF NOT ShortOnMarket AND ShortEntry THEN
    Sellshort OrderSize CONTRACTS AT MARKET
    set stop ploss ShortSLpip
    set target Profit TakeProfit
    ENDIF
    
    // Conditions to exit long positions
    If ShortOnMarket AND ShortExitDoor THEN
    EXITSHORT AT MARKET
    ExitIndex=BarIndex
    ENDIF
    
    //----------------------------
    IF Barindex = ExitIndex + 1 THEN
    ExitIndex = 0
    IF PositionPerf(1) <= 0 THEN
    BadTrades = BadTrades + 1
    IF BadTrades < 3 THEN
    //// If the last trade was losing and there are less than 3 successive losses,
    //// add one to OrderSize.
    OrderSize = OrderSize + 1
    ELSIF BadTrades MOD 3 = 0 THEN
    //// If the last position was losing and there are more than 3 consecutive losses,
    //// double OrderSize.
    OrderSize = OrderSize * 2
    ENDIF
    ELSIF PositionPerf(1) > 0 THEN
    // If the previous trade was winning, reset OrderSize to 1.
    OrderSize = 1
    BadTrades = 0
    ENDIF
    ENDIF
    
    PositionPerf.png PositionPerf.png
    #155866 quote
    Dow Jones
    Participant
    Veteran

    I think you need to utilize strategyprofit  and strategyprofit [1] to determine when the trade closed, and make the calculation of positionperf

    Example below:

    maxconsecutiveloss = 5
    once losscount = 0
    if strategyprofit <> strategyprofit[1] then
    if positionperf(1)<0 then
    losscount = losscount + 1
    else
    losscount = 0
    endif
    endif
    
    IF losscount > maxconsecutiveloss THEN
    Quit // abandon strategy with consecutive loss above required
    ENDIF
    #155867 quote
    Dow Jones
    Participant
    Veteran

    Maybe better to directly try with your code,

    //----------------------------
    IF Barindex = ExitIndex + 1 THEN
    ExitIndex = 0
    IF strategyprofit <> strategyprofit[1] THEN
    IF PositionPerf(1) <= 0 THEN
    BadTrades = BadTrades + 1
    IF BadTrades < 3 THEN
    //// If the last trade was losing and there are less than 3 successive losses,
    //// add one to OrderSize.
    OrderSize = OrderSize + 1
    ELSIF BadTrades MOD 3 = 0 THEN
    //// If the last position was losing and there are more than 3 consecutive losses,
    //// double OrderSize.
    OrderSize = OrderSize * 2
    ENDIF
    ELSIF PositionPerf(1) > 0 THEN
    // If the previous trade was winning, reset OrderSize to 1.
    OrderSize = 1
    BadTrades = 0
    ENDIF
    ENDIF
    ENDIF

    Btw,

    1) Your comment “If the last position was losing and there are more than 3 consecutive losses,” seems doesn’t tally with the code, why to mod with 3 and not >= 3?

    2) Using my example, I’m not sure if the ExitIndex still necessary, perhaps can be removed, otherwise I’m not sure if it will enter the condition when trade is closed by STOP LOSS or TARGET

    #157217 quote
    theo123
    Participant
    Junior

    Hi DowJones,

    Thanks for the reply.  Just able to check the reply today and will try your code and update.

    Actually the whole thing is copied from the PRT manual, so I am not really sure of the use of the MOD.

    #252088 quote
    SnorreDK
    Participant
    Junior

    instead of creating a new topic

    BUY if the previous trade was a loss, but less then 0.5% in loss.
    also BUY if the previous trade was a win.

    How to code that?

    #252094 quote
    robertogozzi
    Moderator
    Master

    0.5% of the price or of your Capital?

    #252097 quote
    SnorreDK
    Participant
    Junior

    same o.5 as
    set stop %loss 0.5

    #252119 quote
    robertogozzi
    Moderator
    Master

    Try this one:

    DEFPARAM CumulateOrders = false
    ONCE TradeStart = 0
    //
    NewTrade        = (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR (OnMarket AND Not OnMarket[1]) OR (OnMarket AND (StrategyProfit <> StrategyProfit[1]))
    //
    TradeClosed     = (Not OnMarket AND OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR (Not OnMarket AND (StrategyProfit <> StrategyProfit[1]))
    //
    IF NewTrade THEN
    TradeStart = TradePrice
    ENDIF
    IF TradeClosed THEN
    IF (StrategyProfit < StrategyProfit[1]) THEN
    TradeEnd   = close[1]
    myLoss     = TradeEnd - TradeStart
    IF LongOnMarket[1] AND myLoss < 0 THEN
    PerCent = round(((TradeEnd / TradeStart) - 1) * 100,3)
    ELSIF ShortOnMarket[1] AND myLoss > 0 THEN
    PerCent = round(((TradeEnd / TradeStart) - 1) * 100,3)
    ENDIF
    IF PerCent < 5 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    ELSIF (StrategyProfit > StrategyProfit[1]) THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    ENDIF
    IF Not OnMarket AND close CROSSES OVER Average[20,0](close) THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    IF Not OnMarket AND close CROSSES UNDER Average[20,0](close) THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    SET STOP   pLOSS   100
    SET TARGET pPROFIT 200
    //
    graphonprice TradeStart
    graphonPrice TradeEnd   coloured("Cyan")
    graph PerCent
    ProfitAlgos and SnorreDK thanked this post
Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

Correct way to use PositionPerf for increasing OrderSize


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
theo123 @theo123 Participant
Summary

This topic contains 12 replies,
has 5 voices, and was last updated by robertogozzi
4 months, 2 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/21/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...