Help with increase/decrease in number of contracts in steps

Forums ProRealTime English forum ProOrder support Help with increase/decrease in number of contracts in steps

Viewing 11 posts - 1 through 11 (of 11 total)
  • #151224

    Hi!

    I’m a rookie and I’m having trouble to create a code that increases and decreases the number of contracts based on profits/losses.

    I need a code that’s increasing contracts by 0.25 for every 350$ profit. So if a single trade profits 700$ that would mean that the system should increase with two steps immediately (increase with 0.5 contracts in this example).

    The same if it loses a single trade for  1050$ then it would need to decrease contracts with three steps (0.75 contracts in this example).

    I have searched a lot on the forum without finding anything that works the way I want it to. Everything I found does not take into account if a trade make a huge profit or a huge loss, that it need to increase/decrease several steps at once.

    If anyone could help me to create this code I would be extremely grateful!

    Regards

    The rookie

     

    #151227

    There you go (not tested):

     

    #151229

    Sorry, line 4 should read:

     

    1 user thanked author for this post.
    #151236

    Thank you!! I’m gonna try it later tonight!

    #199043

    Hi to everybody here.

    Well, I found this topic and it seems interesting to me.  I tried to add it into a strategy running in demo and I got different results on long and short trades.

    Then I modified it as follows (just setting different quantities and profit amount for short and long trades) but I can’t find a way to obtain the strategyprofit only for long trades and/or for short ones.  Is there any way to know the profit generated by long or short trades ????  

    // for LONG trades
    Once MinSizeL = 1 //minimum sizecrequired
    Once LotSizeL = MinSizeL //starting size (can be bigger than minimum)
    Once LotStepL = 250 //increase/decrease this money step
    LotSizeL = max(MinSizeL,MinSizeL + (MinSizeL * round(StrategyProfit / LotStepL)))
    myLotL=LotSizeL

    // for SHORT trades
    Once MinSizeS = 1 //minimum sizecrequired
    Once LotSizeS = MinSizeS //starting size (can be bigger than minimum)
    Once LotStepS = 250 //increase/decrease this money step
    LotSizeS = max(MinSizeS,MinSizeS + (MinSizeS * round(StrategyProfit / LotStepS)))
    myLotS=LotSizeS

    Many thanks !!!!!!!!!!!!!

    #199054

    This snippet should to, to split STRATEGYPROFIT into two parts, Long and Short performances (not tested):

    1 user thanked author for this post.
    #199055

    @ rOBERTO

    many thanks for your prompt answer.

    I’m testing it but it seems to work unproperly.

    At the end of the backtest i’ll send here the complete system for your comments.

    Thanks !!

    #199079

    There was an issue when a single-bar trade occurred, with this modification everything seems to work fine (tested on DAX, Daiky TF):

    1 user thanked author for this post.
    #199082

    Dear ROBERTO,

    many thanks for spending your time about this issue.  I will try your new system but I think is missing the part regarding the definition of buy/sell number of contracts . Here below I added a part of your previous reply to let the system calculate the contract q.ty based on profit levels (SEE BOLD WORDS).   Do you think it’s OK in this way ????

    ONCE LongProfit  = 0

    ONCE ShortProfit = 0

    IF StrategyProfit <> StrategyProfit[1] AND BarIndex > 0 THEN

    Profitto = StrategyProfit – StrategyProfit[1]

    IF LongOnMarket[1] THEN

    LongProfit  = LongProfit  + Profitto

    ELSIF ShortOnMarket[1] THEN

    ShortProfit = ShortProfit + Profitto

    ELSE

    p1 = 1

    p2 = 2

    IF OnMarket THEN

    p1 = 2

    p2 = 3

    ENDIF

    IF TradePrice(p1) > TradePrice(p2) THEN

    IF Profitto > 0 THEN

    LongProfit  = LongProfit  + Profitto

    ELSE

    ShortProfit = ShortProfit + Profitto

    ENDIF

    ELSIF TradePrice(p1) < TradePrice(p2) THEN

    IF Profitto < 0 THEN

    LongProfit  = LongProfit  + Profitto

    ELSE

    ShortProfit = ShortProfit + Profitto

    ENDIF

    ELSE

    LongProfit  = LongProfit  + (Profitto / 2)

    ShortProfit = ShortProfit + (Profitto / 2)

    ENDIF

    ENDIF

    ENDIF

     

    // for LONG trades

    Once MinSizeL = 1      //minimum sizecrequired

    Once LotSizeL = MinSizeL  //starting size (can be bigger than minimum)

    Once LotStepL = LL200 //250      //increase/decrease this money step

    LotSizeL = max(MinSizeL,MinSizeL + (MinSizeL * round(LongProfit / LotStepL)))

    myLotL=LotSizeL

     

    // for SHORT trades

    Once MinSizeS = 1      //minimum sizecrequired

    Once LotSizeS = MinSizeS  //starting size (can be bigger than minimum)

    Once LotStepS = LS200 //250      //increase/decrease this money step

    LotSizeS = max(MinSizeS,MinSizeS + (MinSizeS * round(ShortProfit / LotStepS)))

    myLotS=LotSizeS

     

    if close crosses over average[200,0](close) then

    buy myLotL contract at market

    elsif close crosses under average[200,0](close) then

    sellshort myLotS contract at market

    endif

    set target pprofit 600

    set stop   ploss   200

    //

    #199084

    Mine is just the way to split STRATEGYPROFIT into its two components, Short and Long.

    You seem to have used it correctly.

     

    1 user thanked author for this post.
    #199086

    many thanks.!!

    It seems working well. Maybe I’ll add limits for the quantities.

    So you think it’s an interesting snippet for GRAHAL ????

     

Viewing 11 posts - 1 through 11 (of 11 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login