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
Determine if the last position was closed because of StopLoss [SOLVED]
Re: Determine if the last position was closed because of StopLoss [SOLVED]
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;