strategy profit splitted for long and short

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #216380 quote
    MaoRai54
    Participant
    Master

    Hi everybody,

    is there any simple way to have the STRATEGYPROFIT result only for long and for short trades within the same strategy ???

    Many thanks in advance for your advise !!

    #216388 quote
    robertogozzi
    Moderator
    Master

    Not tested:

    ONCE LongStrategyProfit  = 0
    ONCE ShortStrategyProfit = 0
    IF StrategyProfit <> StrategyProfit[1] THEN
       EntryPrice = TradePrice[2]
       ExitPrice  = TradePrice[2]
       Difference = StrategyProfit - StrategyProfit[1]
       IF LongOnMarket[1] THEN                                               //LONG  trades
          LongStrategyProfit  = LongStrategyProfit[1]    + Difference
       ELSIF ShortOnmarket[1] THEN                                           //SHORT trades
          ShortStrategyProfit = ShortStrategyProfit[1]   + Difference
       ELSE                                                                  //UNDEFINED trades for which both the Difference and the Entry and Exit prices need to be compared to determine the direction
          IF Difference > 0 THEN
    	     IF ExitPrice > EntryPrice THEN
                LongStrategyProfit  = LongStrategyProfit[1]    + Difference  //when it's a PROFIT, a higher EXIT price implies a LONG trade
        	ELSE
                ShortStrategyProfit = ShortStrategyProfit[1]   + Difference  //when it's a PROFIT, a lower  EXIT price implies a SHORT trade
    		 ENDIF
          ELSE
    	     IF ExitPrice < EntryPrice THEN
                LongStrategyProfit  = LongStrategyProfit[1]    + Difference  //when it's a LOSS, a lower  EXIT price implies a LONG  trade
             ELSE
                ShortStrategyProfit = ShortStrategyProfit[1]   + Difference  //when it's a LOSS, a higher EXIT price implies a SHORT trade
    		 ENDIF
          ENDIF
       ENDIF
    ENDIF
    graph LongStrategyProfit    coloured("Green")
    graph ShortStrategyProfit   coloured("Red")
    graph LongStrategyProfit + ShortStrategyProfit
    #216389 quote
    robertogozzi
    Moderator
    Master

    The last GRAPH should match the ProBacktest calculations, updated to the last closed trade.

    #216392 quote
    MaoRai54
    Participant
    Master

    dear Roberto, many thanks for your reply and code.

    Is there any simplest and shortest way to reach the same results?

    I’m afraid I’ll not be able to insert it into a strategy.

    #216393 quote
    MaoRai54
    Participant
    Master

    Roberto,

    I’d like to put it into a strategy and not just a graph or indicator.

    I think that from your code is missing the second part, i.e. the one to use it as variable for deciding if increase or decrease the q.ty based on the previous success of the strategy.

    #216396 quote
    robertogozzi
    Moderator
    Master

    That’s not meant for GRAPHING, that’s to have a single  STRATEGYPROFIT split into LONG and SHORT data, so that you can decide how to use those split data. There are two variables, you can use them for what you need.

    Isn’t that what you asked in your first post?

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

strategy profit splitted for long and short


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
MaoRai54 @maorai Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by robertogozzi
2 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/17/2023
Status: Active
Attachments: No files
Logo Logo
Loading...