Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Data Structure for Checking 10-15 Bars in the Past

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

    Data Structure for Checking 10-15 Bars in the Past

    I have been using an Array called TrackArr[12] to check on a function of Open and Closes. I put the result of of the function in this array symbolized as the String "G" or "W" or "S" or "R" for Green, White, Silver and Red.

    Then I make a decision at the end of the strategy based on how many e.g. "G" or " R" in the last 12 CandleSticks. It is not working.

    Right now I initialize the Array with "S" in the Variables Region like this
    string[] TrackArr ={"S","S","S","S","S","S","S","S","S","S","S","S"} ;

    Then I push the contents of each cell of the array to the back like this at the start of One Bar Update() like this using this for loop
    for (int i=0; i <= TrackArr.Length-2; i++)
    {
    TrackArr[i+1]=TrackArr[i];
    }

    Then I make an If decision on the array and Stuff "G","S","W" or " R" into the first cell that should now be unoccupied like this TrackArr[0]="G" as an example.

    When I add up all the "G" 's in the Array of 12 cells, I get crazy stuff, 0 or 12 , when likely should be uniformly 2 thru 10 as a count.

    What am I doing wrong? What is doing?

    Is there a easier, better way? Maybe Create a indicator and call the indicator?

    #2
    An alternative can be to analyse the 12 candlesticks without really storing them in a array.

    e.g. just run the For loop 12 times, and within the loop compare the Open[i] and Close[i] values and store the result in 2 different integer variables. You would have the number of red and green candles from past 12 candles.

    Hope this helps.

    Comment


      #3
      adlane, unfortunately those C# data structures are not directly supported by us - however it sounds like further debugging is clearly needed to understand the sequence of events seen that lead to your unexpected outcome here. If I understand your use correctly, wouldn't a stack then be more convenient to handle? Then you would not have to worry about the shifting - http://www.dotnetperls.com/stack

      Comment


        #4
        Yes, I took your advice and ran the whole function involving Open & Closes, Lines etc thru a For Loop. It works! The function like structure was so large and complicated I never thot of putting in a loop. Thanks!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        595 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        554 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X