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

Change Historical Bars in DataSeries

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

    Change Historical Bars in DataSeries

    OK, I give up. I've tried lots of things and can't get this to work. Help would be appreciated.

    What I'm actually trying to do is cumulate volume for up waves and down waves. Starting with a simple Close[0] > Close>[1] for up volume and vice versa for down volume. This works but I would like to change the previous bar, if it was a down close in an up wave. Seems simple enough, the IDataSeries class says to do this:
    myDataSeries.Set(1,value)
    This should change the historical value one bar ago to whatever I want. It does not work.What it does do is change the present bar to something really screwy when cumulating volume. So I reduced this using numbers for values rather then volume. Still not getting correct results.

    Here is the code snippet, can you please tell me what I'm doing wrong? I replaced volume with numbers just to simplify it. The real code sets DownVolume dataseries for down waves, ie, down closes. This code below is doing some crazy things. The last if statement is the statement used to cumulate volume in an upwave.

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < BarsRequired)
    return;
    //Attempt to fix a down bar in up wave . This didn't work
    // Up wave fix
    if (Close[0] > Close[1]
    && Close[1] < Close[2]
    && Close[2] >= Close[3])
    {
    DownVolume.Set(5);
    UpVolume.Set(1,20); //This should set the UpVolume 1 bar ago to 20 but it does not!!
    }

    if (Close[0] > Close[1] || (Close[0] == Close[1] && Close[1] > Close[2]))
    {
    UpVolume.Set(10);
    DownVolume.Set(1);
    }

    #2
    Thanks for the post gdavis74 - do you set a value for every bar for your custom dataseries objects? As if you would not do so, an internal dummy value would be stored (which usually would be your input series price / close). To check if you have set a value and not calculating off a dummy for the specific bar the .ContainsValue could be used.

    If I understand correctly what you look to create I believe this has been already done in the community, so you might find it helpful to review and use as base - http://www.ninjatrader.com/support/f...ad.php?t=62719
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand, thanks for your response.

      I still don't understand. Even if the prior UpVolume series bar has a dummy value, once the above condition is met, why does the code not change the dummy value to 20?
      I ran this again tonight and on the bar after the down close, I see the DownVolume set to 5 and UpVolume set to 10, so this tells me the logic detected the condition yet it did not change the prior UpVolume bar !

      I tried setting DownVolume series to 10 if Close[0] < Close[1] and UpVolume series to 1 prior to calling the above code but still, the prior bar is not changed for the problem I have presented. This should have avoided a dummy value for the UpVolume series.

      I guess I don't understand how to use the function for changing the historical bar.

      If the code is executed in order, line by line and the down close just mentioned is before the up close logic, then why doesn't this work?

      Is there some Reset() I have to do first. I also am not sure about how to use the .ContainsValue function. I tried using it in an if statement prior to setting the previous UpVolume bar to 20 and if false, do so but nothing happened.

      Any further help, explanation or pointing to a YouTube video or something would be greatly appreciated.

      I do know this indicator exists but I'm trying to learn to code myself to be independent.

      Thanks

      Comment


        #4
        Originally posted by gdavis74 View Post
        OK, I give up. I've tried lots of things and can't get this to work. Help would be appreciated.

        What I'm actually trying to do is cumulate volume for up waves and down waves. Starting with a simple Close[0] > Close>[1] for up volume and vice versa for down volume. This works but I would like to change the previous bar, if it was a down close in an up wave. Seems simple enough, the IDataSeries class says to do this:
        myDataSeries.Set(1,value)
        This should change the historical value one bar ago to whatever I want. It does not work.What it does do is change the present bar to something really screwy when cumulating volume. So I reduced this using numbers for values rather then volume. Still not getting correct results.

        Here is the code snippet, can you please tell me what I'm doing wrong? I replaced volume with numbers just to simplify it. The real code sets DownVolume dataseries for down waves, ie, down closes. This code below is doing some crazy things. The last if statement is the statement used to cumulate volume in an upwave.

        protected override void OnBarUpdate()
        {
        if (CurrentBars[0] < BarsRequired)
        return;
        //Attempt to fix a down bar in up wave . This didn't work
        // Up wave fix
        if (Close[0] > Close[1]
        && Close[1] < Close[2]
        && Close[2] >= Close[3])
        {
        DownVolume.Set(5);
        UpVolume.Set(1,20); //This should set the UpVolume 1 bar ago to 20 but it does not!!
        }

        if (Close[0] > Close[1] || (Close[0] == Close[1] && Close[1] > Close[2]))
        {
        UpVolume.Set(10);
        DownVolume.Set(1);
        }
        How do you know that your values are not being set as you want?

        Use some Print() statements to get those values, and let us see what is shown in the Output Window.

        Comment


          #5
          The indicator plots a histogram of up and down wave volume, red for down, green for up. That is how I can tell what the output is.

          It sounds like there is no doubt that historical dataseries bars can be changed if used correctly and the code is written correctly . Also, I have some more to learn about boolean and branching to clean up the code.

          Admittedly, I have the cart before the horse knowing some basics of C programming but by no means what it takes to do advanced programming. I will learn more and get this !

          Thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Aviram Y, Today, 05:29 AM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          26 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by bmartz, 03-12-2024, 06:12 AM
          3 responses
          30 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X