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 !!
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
The last GRAPH should match the ProBacktest calculations, updated to the last closed trade.
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.
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.
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?