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

issues loading and saving times

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

    issues loading and saving times

    I have an indicator that draws vertical lines. I created a list to save these times. On original load it will draw but when I press the button it does draw but it only contains 1 time stamp in my whole list. this is what I have.


    exampleButton.Content = "Trend";
    exampleButton.Background = Brushes.LavenderBlush;
    exampleButton.Foreground = Brushes.Black;
    bRegularTrend = true;
    if(this.drawTrendList.Count > 0)
    {
    for(int x = 0; x< this.drawTrendList.Count; x++)
    {
    Print("in here");
    Print(this.drawTrendList[x].TagTime);
    RemoveDrawObject(this.drawTrendList[x].TagName);
    if(this.drawTrendList[x].IsVerticalLine ==true)
    {
    Draw.VerticalLine(this,this.drawTrendList[x].TagName,this.drawTrendList[x].TagTime,PVLineColor,DashStyleHelper.Dash,NVLineWi dth,true);
    Print(this.drawTrendList[x].TagTime);
    }

    }
    }



    the original loading this is the code

    tagNumber = tagNumber +1;
    Print(CurrentBar);
    Print(Bars.GetTime(CurrentBar));

    drawTrendList.Add(new TrendList(tagNumber.ToString(),Bars.GetTime(Curren tBar),dUpTrendOld -3*TickSize,true,false));


    my results are the picture belowClick image for larger version

Name:	picture1.PNG
Views:	1
Size:	13.5 KB
ID:	908855

    Click image for larger version

Name:	picture2.PNG
Views:	1
Size:	82.9 KB
ID:	908856

    #2
    Hello ballboy11,

    After you have added an item to your list or array or dictionary does the count go up?

    What is the count of the array/list/dictionary when the button is clicked?

    Is there other code in the script that may be declaring the array within a method causing the list to become a new object each time the method is triggered or is the array/list/dictionary object within the scope of the class and initialized when the State is State.DataLoaded/.Historical?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      The count is fine. It is 436

      Comment


        #4
        Hello ballboy11,

        What is the exact issue?

        Is the issue that the array does not have all of the elements you are expecting?

        Is the issue that your loop is not printing "I'm here" for every element in the array?

        Is the issue that second value of the TrendList object where the 'Bars.GetTime(CurrentBar)' is saved is the wrong value?
        What is the value before it is saved?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ballboy11,

          What is the exact issue?

          Is the issue that the array does not have all of the elements you are expecting?
          No. All the elements are there but the timestamp is always the first bar time .

          Is the issue that your loop is not printing "I'm here" for every element in the array?
          yes it is printing with no issue

          Is the issue that second value of the TrendList object where the 'Bars.GetTime(CurrentBar)' is saved is the wrong value?

          Exactly. When printied is shows the correct value, but in the array it is the incorrect value.

          I am not sure what state the information is when loading.



          What is the value before it is saved?

          I have a button that when pressed it removes the draw Objects then it is supposed to then go in my draw list and draw vertical lines at the time stamps in the list.
          On loading my lines are drawn, when i press the button it does remove the lines but draws all the lines at the first bar because this time stamp is 0001-01-01.

          The question is do I put my logic in state.Historical, state.Transition, state dataloaded? My logic is in OnBarUpdate


          i will print out the 2 pictures all i want to do is redraw those lines if needed there is a button called trend on the top to change I have different trends. The weird thing is the time stamp is the same on all arrows and lines when I press the button, so on the inital load Current bar or TIme[0] is always the same.
          Attached Files
          Last edited by ballboy11; 12-11-2017, 03:27 PM.

          Comment


            #6
            Hello ballboy11,

            When the items are added what is the time you are adding them with?

            CurrentBar only increments in OnBarUpdate as the data progresses.
            Are you attempting to use CurrentBar outside of OnBarUpdate? (Don't do this)

            Are you adding them with the time of the current bar?

            Are you loading them with the time of that bar number?

            Are you adding them in a loop?

            Are you adding them on each bar?

            Print the time you are using when adding the object to the array. Is that print showing the time expected?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              My logic is quite basic. All I want to do is draw vertical lines when the trend changes. I have 2 trends an aggressive trend and a regular trend. In the picture below it displays the lines correctly. When you press the button above from Trend to aggressive I wanted to erase the lines and repaint the lines to aggresive mode. When you press the button again, it will erase the aggessive lines and repaint the regular trend lines. My goal was to capture the times where the lines to be drawn so when i repaint i just loop and paint the lines accordingly.

              The issue arises on loading for some reason. I tried Time[0] to save into my list AND then I tried Bars.GetBar(CurrentBar). My results are the same when I try to store the timestamp.

              What I need to figure out what phase are these lines being drawn being loaded. I tried State.Historical, Dataloaded etc.

              I am at this point and am starting to see proper time results

              if (State == State.Historical)
              {
              RegularTrendLogic();
              }
              if (CurrentBar == Bars.Count - 2)
              {
              if(bInitialLoad == true)
              {
              for(int x = CurrentBar; x>0;x--)
              {
              Print(Bars.GetTime(CurrentBar- x));
              //RegularTrendLogic();
              }
              bInitialLoad =false;
              }


              The weird thing is State.Historical will draw the lines on the screen but will not save the proper timestamp in the list. The RegularTrendLogic() goes through the historical to paint the lines AND after that I have go AGAIN in RegularTrendLogic to write the same logic in the List. I don't understand why I have to do this. I have not yet wrote the second part yet but just verified the for loop times do correlate. RegularTrendLogic is in OnBarUpdate(). Lastly, in the beginning RegularTrendLogic was not in State.Historical AND still get same results.
              Attached Files
              Last edited by ballboy11; 12-13-2017, 07:14 AM.

              Comment


                #8
                Hello ballboy11,

                Bars.GetBar(CurrentBar) returns the current bar number not of a historical bar.

                If you are using a loop, then you want the bar number of that bar (likely the index in your loop).

                If you are allowing objects to be drawn in historical data, then these will be drawn in OnBarUpdate when State is State.Historical and then in real time when State is State.Real-time.

                However, OnStateChange is going to trigger with State.Historical before OnBarUpdate starts processing the data and drawing objects.

                If you want to trigger an action on the last historical bar, do this in OnBarUpdate when State is State.Historical and CurrentBar is equal to Count - 2.

                Code:
                protected override void OnBarUpdate()
                {
                if (State == State.Historical && CurrentBar == Count - 2)
                {
                for (int i = 0; i < CurrentBar; i++)
                {
                Print(Time[i]); // <- prints time of bar using a barsAgo value starting with most recent bar (0 bars ago)
                Print(Bars.GetTime(i)); // <- prints time of bar using absolute index starting with first bar
                }
                }
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Aviram Y, Today, 05:29 AM
                0 responses
                1 view
                0 likes
                Last Post Aviram Y  
                Started by quantismo, 04-17-2024, 05:13 PM
                3 responses
                25 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by ScottWalsh, 04-16-2024, 04:29 PM
                7 responses
                34 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cls71, Today, 04:45 AM
                0 responses
                6 views
                0 likes
                Last Post cls71
                by cls71
                 
                Started by mjairg, 07-20-2023, 11:57 PM
                3 responses
                216 views
                1 like
                Last Post PaulMohn  
                Working...
                X