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

Potting data only for a specific number of day

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

    Potting data only for a specific number of day

    Hi,

    I am trying to store data for every bar for lates 3 days and storing prices as key of a dictionary. I am checking using CurrentBar and storing them in a list called firstBar, where I am selecting Current Bar which is 3 days ago like below:

    if (Bars.IsFirstBarOfSession && !firstBar.Contains(CurrentBar))
    {
    firstBar.Add(CurrentBar);
    }

    if (firstBar.Count > 3)
    firstBar.RemoveAt(0);
    firstBarIdx = firstBar.FirstOrDefault();

    Then, I am adding the price to the dictionary like below:

    if (CurrentBar >= firstBarIdx)
    {
    if (!Dictionary.ContainsKey(Price))
    Dictionary.Add(Price , //Value );
    }
    else
    Dictionary.Clear();

    But the problem here is, It is supposed to always store only what ever the keys are for last 3 days and anything before, it was supposed to clear from the dictionary. But instead, it is keep all and plotting on chart. Is it the problem with my logic or is it a problem with how data is plotted in NT8 chart? Any advise will be appreciated.

    #2
    Hello asmmbillah,

    Are you printing the count of the dictionary after calling .Clear()?

    Is this 0?

    Can I see the output text file from the prints?

    Below is a link to a forum post that demonstrates using prints and where these appear.
    https://ninjatrader.com/support/foru...121#post791121

    Also, below is a link to an example named TnSVolume that has a demonstration of using a Dictionary.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. I have checked the examples in the link, my dictionary keys and values are printing ok. No problem with that. The problem is restricting the data for last specific days.
      I have followed instruction in how to print and I have done printing many times. But it is not printing anything for the below:

      if (CurrentBar >= firstBarIdx)
      {
      // logic and calculation
      }
      else
      {
      Dictionary.Clear();

      Print(Dictionary.Keys.Count);
      }

      But if I print in other places it does print. I don't know why it is not printing. If you want I can email you a reduced test script for this purpose. Please advice.

      Comment


        #4
        Hello asmmbillah,

        If the print isn't appearing, then that code isn't being reached.

        It is in an 'else'. If you add a print to the 'if' condition above you see that print appear?

        If so, the 'else' isn't happening because the 'if' has already triggered.

        If not, that entire if condition isn't being reached, is this inside of another if condition?

        Are you certain you want an 'else if'?


        I will not be able to debug a script on your behalf.

        But I can take you through the steps of using prints to understand behavior.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by dcriador, Today, 12:06 PM
        0 responses
        6 views
        0 likes
        Last Post dcriador  
        Started by dcriador, Today, 12:04 PM
        0 responses
        4 views
        0 likes
        Last Post dcriador  
        Started by cutzpr, Today, 08:54 AM
        0 responses
        10 views
        0 likes
        Last Post cutzpr
        by cutzpr
         
        Started by benmarkal, Today, 08:44 AM
        0 responses
        16 views
        0 likes
        Last Post benmarkal  
        Started by Tin34, Today, 03:30 AM
        2 responses
        28 views
        0 likes
        Last Post Tin34
        by Tin34
         
        Working...
        X