Determine if the last position was closed because of StopLoss  [SOLVED]

Questions about MultiCharts and user contributed studies.
Eduardo
Posts: 21
Joined: 22 May 2020

Determine if the last position was closed because of StopLoss

Postby Eduardo » 08 Nov 2020

Hello,

Is there a reserved word (or a way) to know if a position closed was closed because the setstoploss_pt was triggered?

I want to count how many times my Stop Loss was hit in my historical data.

Thank you,
Ed

Eduardo
Posts: 21
Joined: 22 May 2020

Re: Determine if the last position was closed because of StopLoss  [SOLVED]

Postby Eduardo » 08 Nov 2020

Well, I found a way to do it. Probably not the most elegant one but it works (I only trade forex):

Code: Select all

Inputs: SL(90); // in Pips vars: previousExitDate(0), numberOfSLhits(0),PipsLost(0),TotalPipsLost(0); //strategy code here if PosTradeExitDateTime(1,0) <> previousExitDate then begin if positionprofit(1) < 0 then begin PipsLost= absvalue(entryprice(1) - exitprice(1)) * PriceScale; // pips lost in this trade if PipsLost = SL * 10 then numberOfSLhits = numberOfSLhits + 1; TotalPipsLost= TotalPipsLost+ PipsLost ; //cummulative number of pips lost End; previousExitDate = PosTradeExitDateTime(1,0); End; if LastBarOnChart then begin print("Number of lost trades = ", numlostrades:0:0); print("Average pips lost per losing trade = ", Round((TotalPipsLost/10) / numlostrades,0):0:0); print("Number of SL hits = ", numberOfSLhits:0:0); End;


Return to “MultiCharts”