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

MTF indicator calc. not in sync. with the right end of a chart?

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

    MTF indicator calc. not in sync. with the right end of a chart?

    Hello!
    I have coded a multi TF indicator with a primary 5 min TF and a secondary 1 min TF. When I attach the indicator to a chart, the draw objects as well as print statments are drawn and printed at once for the entire data period until the end, before I begin scrolling the chart to the right. The same happens again if I "Reload NinjaScript". This is not the case for a single TF indicator. How can I make the MTF indicator calcuations in sync with the right end of the chart?

    Best Regards,
    Poseidon_Sthlm
    Last edited by poseidon_sthlm; 01-12-2017, 02:03 AM.

    #2
    Hello poseidon_sthlm,

    Thank you for your post.

    I am not sure I follow on what you are detailing. Could you provide a screenshot of this behavior?
    To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

    Click here for instructions

    Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

    Click here for detailed instruction

    I look forward to your response.

    Comment


      #3
      My question is very basic, but I can not catch this situation on a screenshot. The question is why NT does load the enitre historical data at once for a chart when adding a MTF indicator opposed to a single TF indicator and how can I prevent this?

      Assume I open a 5 min chart with 100 days of historical data and scroll the chart to the very left so that only 1 day of data is visible on my chart. I then attach an (single TF) indicator with some draw objects and some print statments. The drawobjects will be drawn on the chart and the print statments will be printed in the output window for the first day that is displayed on my chart, but not for any of the next days. As I scroll my chart to the right, new draw objects and print statments will be added "in sync" with the timestamp for the right most bar on the chart, (until I have scrolled to end of the100 days of historical data).

      BUT if I add an MTF indicator, then all draw objects and print statments for the 100 days of historical data will be added to the chart at once. Thus my scrolling will not trigger any new drawobjects or prints, since all possible drawobjects and prints already were drawn and printed from the start.

      So how can I make the MTF indicator draw and print in sync with the right end of the chart when I scroll?
      Last edited by poseidon_sthlm; 01-12-2017, 10:01 AM.

      Comment


        #4
        Hello poseidon_sthlm,

        This sounds like a difference in how the indicators are programmed. By nature a indicator should load all data and the run from bar 0 to the total count of bars on the chart and then transition into realtime. The outcome of your single TF indicator sounds like a custom way of processing. To know why they perform differently you would need to look at the code and determine why they are different.

        You could also make a duplicate of the indicator that works how you want, and then further modify the duplicate to maintain whatever structure is needed for the action you want.



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello!
          I have coded a simple as possible indicator to illustrate my issue . The indicator is attached below. If you add this indi to a 5 min chart and switch the parameter 'add1MinTF' between true/false you can se what I try to describe, both on the chart and in the output window.

          How would I code this indicator to draw and print in sync with the right end of the chart when I scroll, in the same way that it does in 'single TF mode'?



          Code:
           public class TestDrawMTF : Indicator
              {
                 	/// Varaibles
          		private bool add1MinTF			= false;			/// Parameter
          		private double barCount			= 0.0;
          		
          		
                  protected override void Initialize()
                  {
          			Overlay					= true;
          			DrawOnPricePanel 		= false;
          			CalculateOnBarClose 	= true;
          			
          			
          			/// Add 1 min TF
          			if (add1MinTF)
          			{
          				Add(PeriodType.Minute, 1);
          			}
                  }
          
          		
                  protected override void OnBarUpdate()
                  {
          			if (Bars == null) {return;}
          			
          			if ( BarsInProgress == 0 )
          			{
          				if ( CurrentBars[0] < 1 ) {return;}
          				
          				if ( !add1MinTF) {barCount += 1.0;}
          				
          				Print(CurrentBar + " | " + Time[0] + " | " + barCount);
          				
          				/// Since drawing methods are called for the entire historical data for MTF indicator, ....
          				/// ...all drawobjects will be removed when the secondary 1 min TF is added (add1MinTF = true)
          				if (Bars.FirstBarOfSession){RemoveDrawObjects();} 
          				
          				DrawText("BarCount" + CurrentBar, barCount.ToString(), 0, High[0] + TickSize, Color.Lime);	
          			}
          			else if ( BarsInProgress == 1 ) 
          			{
          				if ( CurrentBars[0] < 1 || CurrentBars[1] < 1 ) {return;}
          				
          				barCount += 1.0;
          			}
                  }
          
          		
                  /// Properties
                  [Description("Add a secondary 1 min bar series")]
                  [GridCategory("Parameters")]
                  public bool Add1MinTF
                  {
                      get { return add1MinTF; }
                      set { add1MinTF = value; }
                  }
              }
          Attached Files

          Comment


            #6
            Hello,

            Thank you for the reply.

            I am not certain what to tell you in regard to what needs to be changed, you would need to review the indicator that does the action you want to replicate that type of logic in your script. I really couldn't say what would be required as I am unsure what specific syntax was used in the indicator you are trying to copy.

            Is the indicator you are trying to duplicate an open source indicator meaning you can view its code? If so you could just review its logic to duplicate it. If not, you would likely need to contact the developer of that item to see if they can explain what would be required to duplicate the existing system.

            An indicator by default should run from bar 0 to the count of the chart and also process all historical data for added series as well. If you are trying to do a different action, you would need to create logic that does that action for you. It is possible the other item uses the Plot override as this would see the start and end index's of the bars on the chart, but this would just be a guess.

            Additionally using dynamic secondary series as you have shown is not suggested as this is known to not work correctly.

            if (add1MinTF)
            {
            Add(PeriodType.Minute, 1);
            }

            Items in initialize may not be refreshed unless you specifically remove and re add the script, pressing F5 or reloading the chart will likely not reload the data correctly while using this approach.

            Instead you would need to just Add the secondary series, and in OnBarUpdate delegate which BarsInProgress is used depending on add1MinTF.


            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Sparkyboy, Today, 10:57 AM
            0 responses
            2 views
            0 likes
            Last Post Sparkyboy  
            Started by TheMarlin801, 10-13-2020, 01:40 AM
            21 responses
            3,917 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by timmbbo, 07-05-2023, 10:21 PM
            3 responses
            152 views
            0 likes
            Last Post grayfrog  
            Started by Lumbeezl, 01-11-2022, 06:50 PM
            30 responses
            810 views
            1 like
            Last Post grayfrog  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            3 responses
            11 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X