Strategyprofit on fixed tp

Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • #210307 quote
    robertogozzi
    Moderator
    Master

    How can 1.5% TP be reached if the trade was lost?

    For the next trade to come.

    Then it must be applied toWINNING trades, AFTER a losing one?

    #210524 quote
    JohnScher
    Participant
    Veteran

    How can I explain it what should be coded.

     

    If I lose 1 trade, then the position size should be calculated, which leads to the capital growing by 1% when the take profit of the trade is reached.

     

     

    Example

    Capital = 100%
    1.trade ordersize = 1
    Trade won, capital = 100.2%
    set capital 100.2% to capital 100%

     

    Capital = 100%
    2nd Trade Ordersize = 1
    2.trade won, capital = 100.7%
    set capital 100.7% to capital 100%

     

    capital = 100%
    3rd Trade Ordersize = 1
    3. trade lost, capital = 99.2%

     

    capital 99.2%
    4th trade calculate order size for the 4th trade so that when the take profit of the trade (1.5%) is reached, the capital rises to 101%.
    4th trade lost, capital = 88.9%

     

    capital 88.9%
    5th trade calculate order size for the 5th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
    5th trade won, but capital only 99.1%

     

    capital 99.1%
    6th trade calculate order size for the 6th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
    6th trade won, capital 100.4%
    set capital 100.4% = 100%

     

    capital = 100%
    7.Trade Ordersize = 1
    ……

     

     

     

    general:
    as long as capital > capital [1] should capital = 100%
    as long as capital < last 100% order size is to be calculated in such a way that with this order size and with reaching the TakeProfit of the trade here = 1.5% the capital rises on 101%.

     

    Translated with http://www.DeepL.com/Translator (free version)

    #210525 quote
    JohnScher
    Participant
    Veteran

    correction

    general:
    as long as capital > last 100%  should capital = 100%
    as long as capital < last 100% order size is to be calculated in such a way that with this order size and with reaching the TakeProfit of the trade here = 1.5% the capital rises on 101%.

    #210527 quote
    PeterSt
    Participant
    Master

    Then it must be applied toWINNING trades, AFTER a losing one?

    No … BUT, John by now made it clear. I suppose it is clear to you too now, Roberto ?
    It is the goal to always trade as much in order to get back to a set level (this is the 101% for John).

    Maybe superfluously :

    set capital 100.4% = 100%

    This is now the new base line, as if the Trading System just started. Thus, we act as if we made no profit by resetting all to zero (meanwhile having that 1% in the pocket).

     

    For John : John, IMHO this is nothing for someone who is not involved really apart from finding it great to help others (Roberto) to solve until the end (when it works). This is because it will require numerous if not infinite re-iterations, you (John) always finding new culprits to solve (Roberto always helping).

    In your Martingale-like idea this will be very soon about more protective means, because your backtest will show more and more loss because that is the way it’s setup (please trust me). So my biggest tip I can give you is : First make a strategy which is winning (and recognize that your idea is about Money Management and nothing more) and then apply this system, which is difficult to do yourself (coding stuff and such).


    So … Roberto may come up with something which does what you want. Next it goes way under – which is upon something which is a Strategy (unvisible to us) – which next must be turned into something winning or else it is only extra losing.

     

    Edit : I did not read the “correction” post from John, at composing my previous post.

    #210585 quote
    robertogozzi
    Moderator
    Master

    I came up with this code:

    //-------------------------------------------------------
    // late noon trade
    // instrument dax40
    // timezone europe, berlin
    // timeframe 30m
    // created and coded by JohnScher
    //-------------------------------------------------------
    
    defparam cumulateorders = false
    defparam flatafter      = 213000
     
    once Capital    = 10000
    once Equity     = Capital
    once BaseEquity = Equity
    once CapitalInc = Equity / 200    //0.5% increase
    once ordersize  = 1
    once LotSize    = ordersize
    
    td = opendayofweek >= 1 and opendayofweek <= 6
    tt = time = 133000 //AND time <= 17000013
    c  = close > exponentialaverage[6](close)
    
    IF (StrategyProfit <> StrategyProfit[1]) AND IsLastBarUpdate THEN
       myProfit   = StrategyProfit - StrategyProfit[1]
       TempEquity = BaseEquity * 1.01    //101%
       Temp       = 1 - ((TempEquity - StrategyProfit) / TempEquity)
       LotSize    = ordersize + (ordersize * Temp)
       IF myProfit > 0 THEN
          // when Equity exceeds the previous one, reset it to 100%
          IF (StrategyProfit + Capital) >= BaseEquity THEN
             BaseEquity = StrategyProfit + Capital
             LotSize    = ordersize
          ENDIF
       ENDIF
    ENDIF
    
    if td and tt and c AND not OnMarket then
       buy max(ordersize,LotSize) contracts at market
    Endif
    
    set target %profit 1.5
    set stop   %loss   0.5
    //graph Temp
    //graph BaseEquity

    let me know whether I understood your request correctly, or not.

    JohnScher thanked this post
    #210686 quote
    JohnScher
    Participant
    Veteran

     

    Hello Roberto-

    A big thank you for being on the road for me again and doing work.
    It looks quite excellent, but it seems to me to be a bug that I can’t program away. But we are already very close to the solution.

    With lines 28-33 we at myProfit set > 0 the equity to 100%. Clear.

    But we also need to check whether myProfit >0 and the new capital exceeds 100%. We must not set the capital to 100% after each trade won, but only when we have won the trade and the last reached 100% are exceeded!

    I think I have caught all imaginable combinations with the following example.

     

    Example

    Capital = 100%
    1st trade ordersize = 1
    Trade won, capital = 100.2%
    set capital 100.2% to newCapital 100%

    newCapital = 100%
    2nd Trade Ordersize = 1
    2.trade won, capital = 100.7%
    set capital 100.7% to newCapital 100%

    newCapital = 100%
    3rd Trade Ordersize = 1
    3. trade lost, capital = 99.2%
    // do not set to 100%

    newCapital 99.2%
    4th trade calculate order size for the 4th trade so that when the take profit of the trade (1.5%) is reached, the capital rises to 101%.
    4th trade lost, capital = 88.9%
    // do not set to 100%

    newCapital 88.9%
    5th trade calculate order size for the 5th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
    5th trade won, but capital only 99.1%
    // do not set to 100%

    newCapital 99.1%
    6th trade calculate order size for the 6th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
    6th trade won, capital 100.4%
    set capital 100.4% to newCapital = 100%

    newCapital = 100%
    7th Trade Ordersize = 1
    7th trade lost, capital = 99.5%

    newCapital 99.5%
    8th trade calculate order size for the 8th trade so that when the TakeProfit of the trade (1.5%) is reached, the capital rises to 101%.
    8th trade won, TakeProfit is reached, capital now 101%
    set capital 101% to newCapital = 100%

    newCapital = 100%
    9th Trade Ordersize = 1
    ….

    #210839 quote
    robertogozzi
    Moderator
    Master

    This version seems to be working fine, let me know if some glitches are still left:

    //-------------------------------------------------------
    // late noon trade
    // instrument dax40
    // timezone europe, berlin
    // timeframe 30m
    // created and coded by JohnScher
    //-------------------------------------------------------
     
    defparam cumulateorders = false
    defparam flatafter      = 213000
     
    once Capital    = 10000
    once Equity     = Capital
    once BaseEquity = Equity
    once TempEquity = BaseEquity
    once CapitalInc = Equity / 200    //0.5% increase
    once ordersize  = 1
    once LotSize    = ordersize
     
    td = opendayofweek >= 1 and opendayofweek <= 6
    tt = time = 133000 //AND time <= 17000013
    c  = close > exponentialaverage[6](close)
     
    IF (StrategyProfit <> StrategyProfit[1]) AND IsLastBarUpdate THEN
    myProfit   = StrategyProfit - StrategyProfit[1]
    IF myProfit > 0 THEN
    TP = 1
    // when Equity exceeds the previous one, reset it to 100%
    IF (StrategyProfit + Capital) >= BaseEquity THEN
    BaseEquity = StrategyProfit + Capital
    LotSize    = ordersize
    ENDIF
    ELSIF MyProfit < 0 THEN
    TP = 0
    ENDIF
    ENDIF
     
    if td and tt and c AND not OnMarket then
    IF TP = 0 THEN
    TempEquity = BaseEquity * 1.01    //101%
    TP         = close * 1.015        //+1.5%
    Temp       = TempEquity / ((StrategyProfit + Capital + abs(close - TP)))
    IF Temp > 0 THEN
    LotSize = ordersize * Temp
    ELSE
    LotSize = ordersize
    ENDIF
    ENDIF
    buy max(ordersize,LotSize) contracts at market
    Endif
     
    set target %profit 1.5
    set stop   %loss   0.5
    
    //graph Temp
    //graph MyProfit
    //graph BaseEquity
    //graph LotSize
    //graph StrategyProfit + Capital
    //graph TempEquity
    //graph TP
    //graph close - TP
    JohnScher thanked this post
    late-noon-trade.itf
    #210898 quote
    JohnScher
    Participant
    Veteran

    Hello Roberto.

    Thank you for your work. Your code unfortunately does not work yet in the sense I wanted. It is hard for me to express correctly and for you it is guaranteed not easy to understand me. Therefore I ask you, that we create the code piece by piece. Maybe the other one from here can help too.

    The task is: We code a money management system for a trading system that works with time stop.

    We first hide everything else. We only want to calculate the position size needed to increase the initial capital in 1% when the trade reaches the TakeProfit of 1.5%.

    Can you code this or is someone else from here trying first.
    (It has time, Rome was not built in a day either. Maybe weekend to weekend. I look in once every 2nd,3rd day).)

     

     

    // late lunch trade with money management system
    
    defparam cumulateorders = false
    defparam flatafter      = 213000
     
    once Capital    = 10000
    once OrderSize  = 1
    once LotSize    = ordersize
     
    td = opendayofweek >= 1 and opendayofweek <= 5
    tt = time = 133000 
    c  = close > exponentialaverage[6](close)
    
    lotsize = ??? // that´s the question
    
    If td and tt and c then
    buy lotsize at market
    endif
    
    
    set target %profit 1.5
    
    
    #210900 quote
    robertogozzi
    Moderator
    Master

    Ok, there you go:

    // late lunch trade with money management system
     
    defparam cumulateorders = false
    defparam flatafter      = 213000
     
    once Capital    = 10000
    once Equity     = Capital
    once OrderSize  = 1
    once LotSize    = ordersize
     
    td = opendayofweek >= 1 and opendayofweek <= 5
    tt = time = 133000
    c  = close > exponentialaverage[6](close)
    
    IF StrategyProfit > StrategyProfit[1] THEN
    Equity  = Equity * 1.01
    LotSize = Equity / Capital
    ENDIF
     
    If td and tt and c then
    buy lotsize contract at market
    endif
     
     
    set target %profit 1.5
    //graph lotsize
    JohnScher thanked this post
    #210937 quote
    JohnScher
    Participant
    Veteran

    Hello Roberto.
    You did it in seconds! Thank you very much!

    But it is not what you are looking for! Line 15 comes too early!
    We do not check yet whether the StrategyProfit > StrategyProfit[1] is! !!

    No, we want to calculate only first the position size, which is needed to increase the Capital by 1%, if the TakeProfit of the trade of 1.5% is reached.
    It is (first) (completely) irrelevant whether StrategyProfit>StrategyProfit[1] is.

    I am very sorry that we have misunderstood each other so far.

    #210941 quote
    robertogozzi
    Moderator
    Master

    StrategyProfit > StrategyProfit[1]  just tells us when 1.5% is reached.

    There’s only 1,5% target profit, why should any profit be less than that?

    JohnScher thanked this post
    #210943 quote
    JohnScher
    Participant
    Veteran

    Because we work with a time stop! Time stop!!

    The takeprofit is reached rather in few cases

    #210945 quote
    JohnScher
    Participant
    Veteran

    We work with a time stop, the TakeProfit is not always necessarily reached. Therefore, we would like to develop a money management system that allows us to continuously increase our capital.

    Step 1
    For a first trade we calculate the position size so that when the trade reaches the TakeProfit of 1.5% our capital increases by 1%.

    Step 2
    After this first trade we check if the capital is bigger than the 100% we started with or if the capital has become smaller.

    Step 3 if after the first trade the capital is > capital [1].
    We set the (now new, bigger) capital = 100% capital and calculate the position size for increase of this (new 100%) capital by 1% as in step 1.
    We do this again and again as long as after a trade the newcapital > newcapital [1].
    So as long as NewCapital>NewCapital[1], we set NewCapital= 100% Capital after each trade and start with step 1.

    Step 3 for the case that after the first trade the capital is < capital[1].
    Now it becomes complicated.
    Let’s calculate the position size so that with the next trade when we reach the TakeProfit of the trade 1.5% the capital[1] (!!!) increases by 1%.
    And
    We do this again and again until at some point the nth capital is > the last 100% capital[1].
    Then we set this NewCapital[n] = 100% capital and start step 1.

    Clear?
    Question?

    Can you programm it?

    #210954 quote
    JohnScher
    Participant
    Veteran

    see attached to step 3

    some trades lost in a raw, means some trades below the 100% line in a raw

    Screenshot_1.jpg Screenshot_1.jpg
    #210956 quote
    JohnScher
    Participant
    Veteran

    see to step 3 too

    attached

    Screenshot_2.jpg Screenshot_2.jpg
Viewing 15 posts - 16 through 30 (of 32 total)
  • You must be logged in to reply to this topic.

Strategyprofit on fixed tp


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
JohnScher @johnscher Participant
Summary

This topic contains 31 replies,
has 4 voices, and was last updated by JohnScher
2 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/07/2023
Status: Active
Attachments: 8 files
Logo Logo
Loading...