heres a snippet of code from a program im working on, what the program does is every time a condition is met, it goes long and stores the entry price into an array ( LongList[] ), and then when any of the prices listed in the array is exceeded by a certain amount, it should exit that particular position and erase it from the array.
recognizing the entry and exit as well as erasing from the array seems to be working properly, it entered and exited two trades just fine, but then when 3 entries got stacked into the array and then an exit was triggered (they all got triggered on one bar) the array was cleared, but not all long positions were exited according to the backtest.. would anyone be able to help me figure out why? this is the code to exit long positions.
recognizing the entry and exit as well as erasing from the array seems to be working properly, it entered and exited two trades just fine, but then when 3 entries got stacked into the array and then an exit was triggered (they all got triggered on one bar) the array was cleared, but not all long positions were exited according to the backtest.. would anyone be able to help me figure out why? this is the code to exit long positions.
PHP Code:
if(Strategy.isLong() == true){
for (var i = 0; i <= LongList.length - 1; i++){
if (high() >= LongList[i] + Limit) {
Strategy.doSell("", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, LongList[i] + Limit)
LongList.splice(i)
i--
}
}
}