found a problem but still haven’t resolved the issue, i.e., the loss is significant higher than the average gain trades.
Updated the code to:
/ /code
//Ensure sufficient data set before starting
m = 1
for j = 51 to 100 do
if strategyprofit[j] > 0 then
firstset = (strategyprofit[j] + strategyprofit[j+1])/m
m = m + 1
endif
next
if firstset <> 0 then
n = 1
for k = 1 to 50 do
if strategyprofit[k] > 0 then
sloss = (strategyprofit[k] + strategyprofit[k+1])/n
n = n + 1
endif
next
endif
set stop $loss sloss
// end