Announcement

Collapse
No announcement yet.

Study wont exit positions properly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Study wont exit positions properly

    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.

    PHP Code:
    if(Strategy.isLong() == true){
        for (var 
    0<= LongList.length 1i++){
            if (
    high() >= LongList[i] + Limit) {
                
    Strategy.doSell(""Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, LongList[i] + Limit)
                
    LongList.splice(i)
                
    i--
            }
        }

Working...
X