Change size depending on result

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #203165 quote
    ullle73
    Participant
    Senior

    Hi, took a look at the snippet library but could not find what i was looking for. I want to add to my system following:

     

    • If x of last trades were losses, increase size by y
    • If x of last trades were wins, decrease size back to y

    Saw something similar on ICT and how to flatline your equitycurve by going down to normal size after x number of wins in a row

    #203170 quote
    robertogozzi
    Moderator
    Master

    There you go (not tested):

    ONCE x             = 5
    ONCE y             = 1
    ONCE LotSize       = y
    ONCE WinningTrades = 0
    ONCE LosingTrades  = 0
    IF StrategyProfit > StrategyProfit[1] THEN
       WinningTrades = WinningTrades + 1
       IF WiningTrades >= x THEN
          WiningTrades = 0
          LotSize      = y
       ENDIF
    ELSIF StrategyProfit < StrategyProfit[1] THEN
       LosingTrades  = LosingTrades  + 1
       IF LosingTrades >= x THEN
          LosingTrades = 0
          LotSize      = LotSize + y
       ENDIF
    ENDIF
    ullle73 thanked this post
    #203173 quote
    GraHal
    Participant
    Master

    Link to above added as Log 342 here …

    Snippet Link Library

    robertogozzi thanked this post
    #203174 quote
    ullle73
    Participant
    Senior

    Thanks as always Roberto!!

     

    ONCE y             = 0.2
    ONCE LotSize       = 0.2
    ONCE WinningTrades = 0
    ONCE LosingTrades  = 0
    IF StrategyProfit > StrategyProfit[1] THEN
    WinningTrades = WinningTrades + 0.2
    IF WiningTrades >= 5 THEN
    WiningTrades = 0
    LotSize      = y
    ENDIF
    ELSIF StrategyProfit < StrategyProfit[1] THEN
    LosingTrades  = LosingTrades  + 0.2
    IF LosingTrades >= 1 THEN
    LosingTrades = 0
    LotSize      = LotSize + 0.2
    ENDIF
    ENDIF

    This is what i got this far, but size does not reset back to 0.2 lots, i want the system to have:

    • 0.2 lot size as STANDARD.
    • When making one loss, i want to add 0.2 lots, if it makes a loss again (two in a row) Add another 0.2 lots. Makes 3 in a row, another 0.2 lots and so on until it makes a win, then i want it to reset back to Standard 0.2 lot size
    • When got a win, add 0.2 up to 5 wins, if system reaches 5 wins in a row, reset back to standard 0.2 lot size.
    • If possible, also add max lotsize of MAXLOTSIZE
    robertogozzi thanked this post
    #203175 quote
    robertogozzi
    Moderator
    Master

    Add 1 in lines 6 and 12, not 0.2.

    ullle73 thanked this post
    #203176 quote
    ullle73
    Participant
    Senior

    thanks! But still does not reset lotsize, in the end size is 20 lots ^^,

    #203177 quote
    ullle73
    Participant
    Senior

    Here is the full code if it helps 🙂

    // pl: 130 sl: 70 t & ts: 50 x: 1 = 3min 528$, 46,88W, 25% BE, 3.1 G/L ratio, 1,82 time in the market. 64 trades
    
    DEFPARAM CumulateOrders = FALSE
    ONCE MaxTrades = x                     //no more than 2 trades a day
    ONCE Tally     = 0
    IF IntraDayBarIndex = 0 THEN
    Tally = 0
    ENDIF
    IF Not OnMarket THEN
    MyExit = 0
    ELSE
    c1 = 0
    ENDIF
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR ((Not OnMarket AND Not OnMarket[1]) AND (StrategyProfit <> StrategyProfit[1]))
    IF NewTrade THEN
    Tally = Tally + 1
    ENDIF
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // ADR Average Daily Range
    MyADR       = average[20,0](Dhigh(1) - Dlow(1))
    //
    IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
    MyHI     = high
    MyLO     = low
    c1       = 0
    ENDIF
    IF Time <= 142900 THEN
    MyHI     = max(MyHI,high)
    MyLO     = min(MyLO,low)
    MyRange  = MyHI - MyLO
    c1       = ((MyRange / MyADR) * 100) < adr
    ENDIF
    IF LongOnMarket THEN
    SET TARGET pPROFIT PL          //you can change this value for LONG trades
    SET STOP   pLOSS   SL         //you can change this value for LONG trades
    ELSIF ShortOnMarket THEN
    SET TARGET pPROFIT PL          //you can change this value for SHORT trades
    SET STOP   pLOSS   SL         //you can change this value for SHORT trades
    ENDIF
    IF Time >= 142900 AND Time <= 220000 AND c1 AND Tally < MaxTrades AND Not OnMarket THEN   //trade only between 15:30 and 18:00
    BUY       0.2 Contract AT MyHI + 1 * pipsize STOP
    SELLSHORT 0.2 Contract AT MyLO - 1 * pipsize STOP
    SET TARGET pPROFIT PL     //initial values cannot be different with pending orders
    SET STOP   pLOSS   SL
    ENDIF
    IF MyExit = 0 THEN
    IF LongOnMarket AND (close - TradePrice) >= t * pipsize THEN    //you can change this value for LONG trades
    MyExit = TradePrice
    ENDIF
    IF ShortOnMarket AND (TradePrice - close) >= ts * pipsize THEN   //you can change this value for SHORT trades
    MyExit = TradePrice
    ENDIF
    ENDIF
    IF MyExit > 0 THEN
    IF LongOnMarket THEN
    SELL      AT MyExit STOP
    ELSIF ShortOnMarket THEN
    EXITSHORT AT MyExit STOP
    ENDIF
    ENDIF
    
    #203179 quote
    PeterSt
    Participant
    Master
    WinningTrades = WinningTrades + 0.2
    IF WinningTrades >= 5 THEN  // Winning, not wining.
      WinningTrades = 0         // Winning, not wining.
      LotSize      = y
    ENDIF

    Ulle, the above is from your example. It should work better with these corrections.

    Btw, I don’t find this back in your main code (which is not for my brains anyway – it really is too full with mistakes/faults 😉 ).

    Try to get your sample code to work, and when it does what you want, slowly expand it to your strategy idea.
    🙂

    robertogozzi thanked this post
    #203182 quote
    robertogozzi
    Moderator
    Master

    Sorry for mispelling, but I could not test it, as I was writing it from my mobile phone.

    In such cases using GRAPH may help quite a lot!

    #203186 quote
    PeterSt
    Participant
    Master

    It is a best example of why PRT should not allow to use variables (without producing an error) that were not defined earlier in the code. Thus :

    WinningTrades = WinningTrades + 0.2
    IF WiningTrades >= 5 THEN  // This should error out.
      WiningTrades = 999       // But because this is here, the line above is treated as OK and WiningTrades will always be 0.
      LotSize      = y
    ENDIF

    PRT developers apply the intelligence that because the WiningTrades = 0 line exists, the If above it does not produce an error.
    I once lost money because of such a typo and IIRC the response was that I should not make typos.
    So I repeat from back then : there is no language that I know of which allows this.  And it is worse :

    The official response from PRT support (in Paris) was :
    If we don’t do it this way, nobody is able to get his program to run because of errors.

    A weirdest response ever. Apparently it is better to lose money.

     

    PS: V12 provides a kind of solution to this.

    #203188 quote
    robertogozzi
    Moderator
    Master

    To be honest I prefer the current solution to the previous one, when it was difficult to test variables as you always got the “undefined  variable” error message and you had to always comment/uncomment lines. It was so much time consuming!

    #203189 quote
    GraHal
    Participant
    Master

    nobody is able to get his program to run because of errors.

    PRT likely got many Coding Support Queries due to above and so easy way to reduce Queries … make errors not show as errors at all!?

    #203196 quote
    PeterSt
    Participant
    Master

    To be honest I prefer the current solution to the previous one, when it was difficult to test variables as you always got the “undefined  variable” error message and you had to always comment/uncomment lines. It was so much time consuming!

    I 100% agree with you. That is, would it be really like that. But it was not ..

    The crazy time consuming was about that a variable was not used
    Example :

    MyVar = 1              // <-- Errors on this line because it is not used in the program. 
    My2ndVar = 1
    
    //If MyVar = 1 then
    If My2ndVar = 1 then   // Like this now.
      Buy x at Market
    Endif

    So we could not comment-out lines unless in this case the first line was commented out as well.
    And back to the old If ? indeed a crime (requires 1st line to uncomment and the 2nd to comment out).

    But this is not related to what’s odd today (in V11).

    #203197 quote
    ullle73
    Participant
    Senior

    PeterST, no i did not get it to work anywhere close to what i wanted, it took positions up to 20 lots, I want a maxsize of total of 2-3 lots and add to every loss. So i scrapped it, hoping code-wizards like Roberto could make some magic and add to my original code 😀 my codingskillz are way worse than my english ^^,

    #203199 quote
    robertogozzi
    Moderator
    Master

    Shall the X trades, either winning or losing ones, be consecutive?

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

Change size depending on result


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ullle73 @jonas_rydqvist Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/28/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...