Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
      BertrandNinjaTrader Customer Service

      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 f.saeidi, Today, 12:14 PM
        2 responses
        5 views
        0 likes
        Last Post f.saeidi  
        Started by TradeForge, 04-19-2024, 02:09 AM
        2 responses
        28 views
        0 likes
        Last Post TradeForge  
        Started by aprilfool, 12-03-2022, 03:01 PM
        3 responses
        327 views
        0 likes
        Last Post NinjaTrader_Adrian  
        Started by giulyko00, Today, 12:03 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by AnnBarnes, Today, 12:17 PM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Working...
        X