Capital curve as an indicator?

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

    Capital curve as an indicator?

    I have an old problem that I am still struggling with.

    I want to change my long conditions if after a trade my capital is smaller than the highest capital ever reached with this strategy.
    (current capital of the strategy is smaller than the all-time high of the capital of the strategy).

    My starting capital was 10,000 euros.
    My all-time high in capital was 14,700 euros with this strategy.
    After a losing trade, the current capital is 14,100 euros. After another losing trade 13.800, after a third losing trade 13.500 and so on.

    HowI can use the all-time-high in capital as a condition in this way?
    As long as my current capital is less than the all-time-high of my capital, then Longcondition 1
    alternatively
    if my current capital is greater than the all-time-high of my capital then Longcondition 2

    For the all-time-high you could also use the highest capital level of the last 100 trades, so that quite simplified, analogous to an indicator, the code would be (the code is not correct, it should serve to understand my question)

    
    once capital = 10000
    
    equitity = capital + strategyprofit
    
    
    IF equitity < all-time-high (equitity) then
    condition1
    Elsif equitity > all-time-high (equitity) then
    condition2
    Endif
    
    
    in case the high of 100 Trades
    
    IF equitity < highest [100] (equitity) then
    condition1
    Elsif equitity > highest [100] (equitity) then
    condition2
    Endif
    
    #222482 quote
    robertogozzi
    Moderator
    Master

    This version is for the highest Equity in ALL trades:

    once capital    = 10000
    once maxcapital = capital
    
    equity     = capital + strategyprofit
    maxcapital = max(maxcapital,equity)     //max CAPITAL in ALL trades
    
    IF equity < maxcapital then
       condition1 = x
    Elsif equity > maxcapital then
       condition2 = y
    Endif

    This version is for the highest Equity in the last 100 (or less, if not yet 100) trades:

    once capital    = 10000
    once maxcapital = capital
    once equity     = capital
    once Trades     = 100
    
    IF StrategyProfit <> StrategyProfit[1] THEN
       TradeCount            = lastset($myEquity) + 1
       equity                = capital + strategyprofit
       $myEquity[TradeCount] = equity
       N    = 1
       IF TradeCount >= Trades THEN
          N = TradeCount - (Trades - 1)
       ENDIF
       maxcapital = capital
       FOR i = TradeCount downto N
          maxcapital = max(maxcapital,$myEquity[i])
       NEXT
    ENDIF
    
    IF equity < maxcapital then
       condition1 = x
    Elsif equity > maxcapital then
       condition2 = y
    Endif
    plbourse, JohnScher and slumpy man thanked this post
    #223092 quote
    JohnScher
    Participant
    Veteran

    Hello Roberto.

    Thank you for the coding, that really helps me, if I understood it correctly at all.

    From the 2 offered codes above, I took the first simpler one right away and the Cross EMA 20 over EMA 50 as entry condition.

    As a result, from my understanding, it looks like the following, but no trades are triggered.

    Can you correct my errors?

     

     

     

    //---------------------------------------------------------
    // moneymanagement maxcapital
    // using the example  Average Cross
    // created by JohnScher coded with the help of friends
    //---------------------------------------------------------
    
    defparam cumulateorders = false
    
    once capital = 10000
    once maxcapital = capital
    
    equitity   = capital + strategyprofit
    maxcapital = max(maxcapital,equitity)
    
    If equitity < maxcapital then
    ordersize = 2
    Elsif equitity > maxcapital then
    ordersize = 1
    Endif
    
    
    tradebuy = average [20] (close) crosses over average [50] (close)
    
    If tradebuy then
    buy ordersize contracts at market
    endif
    
    
    set stop %loss 2
    set target %profit 1
    
    #223095 quote
    GraHal
    Participant
    Master

    I think you need to get it going first, so try

    If equitity <= maxcapital then
    ordersize = 2
    
    OR
    
    Elsif equitity >= maxcapital then
    ordersize = 1
    Endif
    JohnScher thanked this post
    #223196 quote
    JohnScher
    Participant
    Veteran

    Yes, thanks, that works now.
    The code as below now does what it should.

    //---------------------------------------------------------
    // moneymanagement maxcapital
    // using the example  Average Cross
    // created by JohnScher coded with the help of friends
    //---------------------------------------------------------
    
    defparam cumulateorders = false
    defparam flatbefore     = 080000
    defparam flatafter      = 210000
    
    
    once capital    = 10000
    once maxcapital = capital
    
    equitity   = capital + strategyprofit
    maxcapital = max(maxcapital,equitity)
    
    If equitity >= maxcapital then
    ordersize = 1 
    Elsif equitity < maxcapital then
    ordersize = 2
    Endif
    
    
    tradebuy = average [20] (close) crosses over average [50] (close)
    
    If tradebuy then
    buy ordersize contracts at market
    endif
    
    set stop %loss 1
    set target %profit 1
    
    
    graph maxcapital
    #223221 quote
    JohnScher
    Participant
    Veteran

    Hello Roberto, hello Grahal, hello et al

    I went back here to pick up the idea that when the take profit of the trade (2%) is reached, the highest capital ever reached increases by 1% at the same time.

    In other words
    In a trading system, we increase the position size so that when the trade reaches its target profit, the highest capital ever achieved grows by 1%.

    This is especially interesting for systems with a time stop (e.g. defparam flatafter = 210000). Here the target profit is not always reached and therefore the highest capital ever reached does not grow by 1% despite a won trade, or a new highest capital ever reached is not even formed.

    Ex.
    maxcapital = 10.000 Euro
    available capital = 8,600 euros
    Position size = 10.56
    Profit in trade = 20 Euro

    The task now is to calculate for the next trade what position size must be traded if the next trade (exceptionally) reaches its profit target and thus the highest capital ever reached grows by 1%.
    target profit trade = 2%
    target profit capital = 1% (12.100 auf 12.221)

     

    The question of this type of calculation has already been raised here and there and also by me.

    Again Moneymanagement calculate

    Strategyprofit on fixed tp

     

    I have worked through all the links above again and I have come to the following coding.
    But somehow I have the feeling that my coding cannot be correct.
    That’s why I’ve added the code below, including comments.

    The comment should show what exactly I want to get with the lines of code
    With comments marked with “**” I am unsure whether the intended result is get

    So please take my thoughts on board and confirm the code as correct or, more likely, correct it.

    Many thanks in advance.
    For this is no rush.

     

    //---------------------------------------------------------
    // moneymanagement maxcapital
    // using the example  Average Cross
    // created by JohnScher coded with the help of friends
    //---------------------------------------------------------
    
    // Basic settings
    defparam cumulateorders = false
    defparam flatbefore     = 080000
    defparam flatafter      = 210000                         // timestop
    
    
    // moneymanagement
    once capital    = 10000                                  // set capital to 10,000 as an once-only basis
    once maxcapital = capital                                // set the highest capital ever achieved the an once-only basis **
    
    equitity   = capital + strategyprofit                    // the available capital is calculated from the capital plus the strategy profit                    
    maxcapital = max(maxcapital,equitity)                    // the highest capital ever achieved is fixed as highest capital ever achieved **                      
    
    tpTrade = close/100*2                                  // calculates the target profit of the trade, here 2% of the price, this corresponds to the instruction "set target %profit 2"  **
    tpCapital = (maxcapital + maxcapital/100*1) - equitity    // calculates the target profit in the capital, here 1% **
    lotsize = round(tpCapital/tpTrade,2)                     // calculates the position size in the way that when the target profit of the trade is reached, the target profit in the capital too **
    
    
    If equitity >= maxcapital then
    ordersize = 1                                            // in the case that the available capital is greater than the highest capital ever reached, the position size is set to 1
    Elsif equitity < maxcapital then
    ordersize = lotsize                                      // in the case that the available capital is lower than the highest capital ever reached, the position size is calculated as in line 20
    Endif
    
    If ordersize < 1 then                                    
    ordersize = 1                                            // for any reason the position size falls below 1, the position size is set to 1                                     
    endif
    
    
    // tradingsystem
    tradebuy = average [20] (close) crosses over average [50] (close)
    
    If tradebuy then
    buy ordersize contracts at market
    endif
    
    set stop %loss 10
    set target profit tpTrade
    
    //give-away
    graph maxcapital
    GraHal thanked this post
    #223357 quote
    robertogozzi
    Moderator
    Master

    I think you should:

    1. make the calculations about money management and lot size ONLY when Not OnMarket, to prevent data from being changed while a trade is open
    2. calculate the Capital increase only when STRATEGYPROFIT > STRATEGYPROFIT[1], which means a profit was reached, but only if TIME < the time used with FLATAFTER, or it will not be the real TP that has been reached.
    JohnScher thanked this post
    #223462 quote
    JohnScher
    Participant
    Veteran

    Hello Roberto.

     

    Thank you very much in advance.

    It will take me a little while to get to grips with it. I will be happy to come back.

    #223534 quote
    JohnScher
    Participant
    Veteran

    Hello Roberto.

    Thankyou very much again! So many times you still helped me and you do it again and again and again… with heartpiece.
    But here I would like to contradict you – it doesn’t seem correct to me. Or I have misunderstood you again, so please excuse my mistakes.

    To point 1
    that I am in the market with several positions is excluded by cumulateorders = false
    Inserting this condition in the following way does not change anything. (line24, line34)

     +

    //---------------------------------------------------------
    // moneymanagement maxcapital
    // using the example  Average Cross
    // created by JohnScher coded with the help of friends
    //---------------------------------------------------------
     
    // Basic settings
    defparam cumulateorders = false
    defparam flatbefore     = 080000
    defparam flatafter      = 210000                         // timestop
     
     
    // moneymanagement
    once capital    = 10000                                  // set capital to 10,000 as an once-only basis
    once maxcapital = capital                                // set the highest capital ever achieved the an once-only basis **
     
    equitity   = capital + strategyprofit                    // the available capital is calculated from the capital plus the strategy profit
    maxcapital = max(maxcapital,equitity)                    // the highest capital ever achieved is fixed as highest capital ever achieved **
     
    tpTrade   = close/100*2                                  // calculates the target profit of the trade, here 2% of the price, this corresponds to the instruction "set target %profit 2"  **
    tpCapital = (maxcapital + maxcapital/100*1) - equitity   // calculates the target profit in the capital, here 1% **
    lotsize   = round(tpCapital/tpTrade,2)                    // calculates the position size in the way that when the target profit of the trade is reached, the target profit in the capital too **
     
    If not onmarket then                         
    If equitity >= maxcapital then
    ordersize = 1                                      // in the case that the available capital is greater than the highest capital ever reached, the position size is set to 1
    Elsif equitity < maxcapital then
    ordersize = lotsize                                // in the case that the available capital is lower than the highest capital ever reached, the position size is calculated as in line 20
    Endif
     
    If ordersize < 1 then
    ordersize = 1                                      // for any reason the position size falls below 1, the position size is set to 1
    endif
    Endif
     
     
    // tradingsystem
    tradebuy = average [20] (close) crosses over average [50] (close)
     
    If tradebuy then
    buy ordersize contracts at market
    endif
     
    set stop %loss 10
    set target profit tpTrade
     
    //give-away
    graph maxcapital

    To point 2
    I do not see that the condition “Strategyprofit > Strategyprofit[1]” is useful. The additional strategy profit can also consist of 1 euro and does not change the calculation basis. The basis of calculation is the highest capital ever achieved. I would like to increase this highest capital ever reached by 1% via the position adjustment*, provided that the take profit is reached before the flattener.

    The adjustment can consist of an increase after a losing trade or a decrease after a winning trade that does not reach the take profit of 2% in the trade.

    Attached is another picture showing the Maxcapital graph.
    You can see that after the first trade, a new highest ever capital (=maxcapital) was reached. This highest value is now the calculation basis for the next trade. As long as there is no new highest capital, the position size is adjusted to this highest capital ever reached.
    Here in the picture a new highest capital cannot be seen and maxcapital is still a horizontal line, because the take profit in the trade of 2% has never been reached since then. See also the other screenshot.

    Dear readers, please note that this is not about the strategy (crossover 20 over 50) per se, but about money management.
    If there are difficulties in solving this problem, I see that it has not yet been dealt with (conclusively) here on Prorealtime. In this respect, it could make a contribution to the entire community.

    Screenshot_3.jpg Screenshot_3.jpg Screenshot_4.jpg Screenshot_4.jpg
    #223568 quote
    JohnScher
    Participant
    Veteran

    the discussion continues here

    Again Moneymanagement calculate

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

Capital curve as an indicator?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
JohnScher @johnscher Participant
Summary

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

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