When to stop a strategy and money management code snippet

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #174637 quote
    Link
    Participant
    Senior

    Wow, the drawdown code is good, but it hasn’t had the desired effect.

     

    Another question:

     

    If in the last 10 operations the winrate is higher than 80%, operate with the usual amount of € pip.

     

    If in the last 10 trades the winrate is less than 80%, trade with half the usual amount of € pip.

     

    I need code … thanks!

    #174768 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM CumulateOrders = false
    ONCE AllTrades     = 0
    ONCE WinningTrades = 0
    ONCE InitialLots   = 2
    ONCE LotSize       = InitialLots
    ONCE Trades        = 10                    //10  trades in a row over 80%
    MyGain             = StrategyProfit
    // tally each trade
    t1                 = OnMarket AND Not OnMarket[1]                              //it's a new trade
    t2                 = Not OnMarket AND Not OnMarket[1] AND MyGain <> MyGain[1]  //detect any 1-bar trade
    t3                 = ShortOnMarket AND LongOnMarket[1]                         //it's a new trade (S & R)
    t4                 = ShortOnMarket[1] AND LongOnMarket                         //it's a new trade (S & R)
    AllTrades          = AllTrades + ((t1 OR t2 OR t3 OR t4) AND IsLastBarUpdate)
    // tally winning trades
    IF MyGain > MyGain[1] THEN
       WinningTrades = WinningTrades + 1
    ENDIF
    // calculate % of winning trades
    IF AllTrades > Trades THEN
       WinPerCent      = WinningTrades * 100 / AllTrades
       IF summation[Trades](WinPerCent > 80) = Trades THEN
          LotSize      = InitialLots             //restore initial lotsize
       ELSE
          LotSize      = InitialLots *  0.5      //halve lotsize
       ENDIF
    ENDIF
    ONCE Periods      = 10
    MyLongConditions  = close crosses over  average[Periods] AND Not OnMarket
    MyShortConditions = close crosses under average[Periods] AND Not OnMarket
    IF MyLongConditions THEN
       BUY LotSize CONTRACTS AT Market
    ELSIF MyShortConditions THEN
       SELLSHORT LotSize CONTRACTS AT Market
    ENDIF
    set target pprofit 200
    set stop   ploss   2000
    #174782 quote
    Link
    Participant
    Senior

    You are Big!

    #174801 quote
    GraHal
    Participant
    Master

    Link to Roberto code above added as Log 297 here …

    Snippet Link Library

    robertogozzi thanked this post
    #174861 quote
    Link
    Participant
    Senior

    What if we did the same but with an ATR?
    If strategyprofit is above ATR, operate with the usual € pip.
    If strategyprofit is below ATR, trade with half a € pip.

    #174864 quote
    Link
    Participant
    Senior

    Sorry with traductors.

     

    🙁

    #174865 quote
    robertogozzi
    Moderator
    Master

    It’s impossible to compare STRATEGYPROFIT to ATR, they are two different scales.
    STRATEGYPROFIT can range from -100K to +100K (or even more), while ATR is a price range (could be from 0 to a few hundreds).
    Even if applied to STRATEGYPROFIT, it can be compared to itself, as it normally cannot be compared to CLOSE.

Viewing 7 posts - 16 through 22 (of 22 total)
  • You must be logged in to reply to this topic.

When to stop a strategy and money management code snippet


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 21 replies,
has 3 voices, and was last updated by robertogozzi
4 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/11/2019
Status: Active
Attachments: No files
Logo Logo
Loading...