How to calculate only losing trades

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #214292 quote
    ZeroCafeine
    Participant
    Senior

    Hi

    How to calculate only the losing trades of a day without taking into account the gains of the winning trades of the same day:

    TimeCondition = Time >= 080000 AND Time <= 170000
    
    IF Time =075500 THEN
     LastStrategyProfit = StrategyProfit
    ENDIF
    
    IF TimeCondition AND DayOfWeek = 1 THEN
     DayProfit = StrategyProfit - LastStrategyProfit
    
     if DayProfit < 0 then
      MondayLosses = DayProfit
     endif
    ENDIF

    I feel that if I have gains during the day then my loss calculation is wrong

    Best Reguards,
    ZeroCafeine

    #214293 quote
    PeterSt
    Participant
    Master
    If PositionPerf < PositionPerf[1] then
      // Count your losses. :-)
    endif
    ZeroCafeine thanked this post
    #214297 quote
    ZeroCafeine
    Participant
    Senior

    tks you I will try it and post result,

    and what this solution works if I am already in position before Monday, So I don’t want to include the gains and losses of the day before ?

    #214300 quote
    PeterSt
    Participant
    Master
    Once PostionPerfYesterday = 0   // We have to start somewhere ... Very 1st time will be incorrect.
    
    If LastBarOfDay then   // Determine LastBarOfDay yourself. FirstBarOfDay is fine too.
      PositionPerfYesterday = PositionPerf
    endif
    
    PostionPerfToday = PositionPerf - PositionPerfYesterday   // Will be actual throughout the day.
    PositonPerfYesterday = 0
    
    // From here on use PositionPerfToday instead of PositionPerf.

    I think this could work. Not tested of course.
    It it does not work you can make it work.

    ZeroCafeine thanked this post
    #214332 quote
    ZeroCafeine
    Participant
    Senior

    Thanks for all your answers but I’m having a bit of trouble, how do I get the value of positionperf once the position is closed

    Capture-decran-2023-05-09-a-05.25.19.png Capture-decran-2023-05-09-a-05.25.19.png
    #214335 quote
    PeterSt
    Participant
    Master

    Yes, I now see that I changed my example from something like PositionPerfToday = PositionPerfToday + xxxx into what I presented.

    You can combine it with StrategyProfit.

    I think that with these hints you can work it out yourself ? sure you can. You can write code so you can solve this. Maybe it takes a few hours, but you will learn from it again.

    ZeroCafeine thanked this post
    #214337 quote
    ZeroCafeine
    Participant
    Senior

    It took me several days to find a solution, and I have more or less found it, but I still have conflicts, so I’m asking again for another method

    tks again 😊

    #214353 quote
    robertogozzi
    Moderator
    Master

    PositionPerf returns the temp performance each bar, while on market. To tally the real loss you must wait for STRATEGYPROFIT to be updated (which occurs when a trade is closed).

    To both count losing daily trades and their total loss (cleared every day) :

    ONCE LosingTrades = 0
    ONCE TotalLoss    = 0
    IF IntraDayBarIndex = 0 THEN
       LosingTrades = 0
       TotalLoss    = 0
    ENDIF
    IF StrategyProfit < StrategyProfit[1] THEN
       LosingTrades = LosingTrades + 1
       TotalLoss    = TotalLoss + (StrategyProfit[1] - StrategyProfit)
    ENDIF
    IF close CROSSES OVER average[10,0](close) AND Not OnMarket THEN
       BUY AT MARKET
       SET TARGET pPROFIT 50
       SET STOP   pLOSS   20
    ENDIF
    //graph LosingTrades
    //graph TotalLoss
    ZeroCafeine thanked this post
    #214360 quote
    ZeroCafeine
    Participant
    Senior

    @robertogozzi
    And once again the alien has come through with a few lines of magic code, Merci

    I did almost a similar solution but a bit more complicated with more code (More complicated as a beginner), here is an excerpt, your solution seems much simpler and I had not thought to compare the StrategyProfit with StrategyProfit[1]

    I’ll test this out in my head and come back to this post

    IF MoreMath = 0 THEN
      DayProfitJPY  = StrategyProfit - LastStrategyProfit // Unit : JPY
    ENDIF
    
    IF MoreMath = 1 AND Flag = 0 THEN
      DayProfitJPY  = StrategyProfit - TodayStrategyProfit + DiffEntreeSortieJPY // Unit : JPY
    ENDIF
    

    tks again for all 😊

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

How to calculate only losing trades


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/08/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...