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

2 indicators and OnMarketData

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

    2 indicators and OnMarketData

    Hi, I'm a bit struggling with the concept of calling an indicator inside another indicator. Let's assume ParentIndicator is processing values from ChildIndicator. Both indicators process market data with OnMarketData, and ParentIndicator is supposed to custom draw signals based on values from ChildIndicator in OnRender().

    What is the correct pattern to synchronize the market data in both indicators? How do I force the InnerIndicator to receive correct data in OnMarketData(), before ParentIndicator.OnMarketData() if possible?

    I'm trying
    //pseudo code
    Code:
    override OnRender()
    {
       foreach(int barIndex in visibleBars)
         if(InnerIndicator().IsValidDataPointAt(barIndex)
           DrawSignal(barIndex);
    }
    but the InnderIndicator never receives OMD event, so the Values are always invalid. Inserting the indicator into a chart directly works, so I must be missing something in the indicators embedding concept. Thanks for any help.

    #2
    Hello mantak007,

    Thank you for the post.

    I dont believe the order of the events could be changed due to one indicator being hosted by another. The parent indicators OnMarketData was called first in my tests.

    I do see that I get OnMarketData called in the sub-indicator, so this portion of the question may be due to how the indicator is being added/called from the parent.

    In my simple test, I had created a sub-indicator with 1 plot and assigned the Close to the plot and also added OnMarketData with a print. In the parent, I call the sub-indicator to get the plot value so the child was called and then I can see the Print from OnMarketData for both.

    If you are not seeing this, can you provide a simple example of how you are calling the sub-indicator?



    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 05-11-2018, 07:34 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse, I'm afraid I cannot post the code, it's quite complex and it's not easy to extract only relevant parts. May I however ask you for your sample? If your sample is working, I'll probably easily spot what am I missing. Thank you.

      Comment


        #4
        Hello mantak007,

        There was not much else to the test other than what I had described. If you wanted to recreate this you could use the Indicator wizard to generate a new indicator for testing.

        In the test indicator, I had the wizard generate the OnMarketData override and a Plot. I then set a value to the Plot from OnBarUpdate and then added a Print to OnMarketData.

        Code:
        else if (State == State.Configure)
        {
        	AddPlot(Brushes.Gray, "plot0");
        }
        Code:
        protected override void OnBarUpdate()
        {
        	Value[0] = Close[0];
        }
        		
        protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
        {
        	Print("Test2 OMD");
        }
        From the main indicator, I just called the sub Indicator from OnBarUpdate normally:

        Code:
        protected override void OnBarUpdate()
        {
        	double val = Test2()[0];
        }
        I can see OnMarketData working after doing this. I am just calling the indicator as you normally would. I had noted that I had added a Plot because without a Plot the above syntax would generate an error.

        If you are using a more complex approach at calling your indicator, you would likely need to reduce or debug your code to find the problem.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by aa731, Today, 02:54 AM
        0 responses
        4 views
        0 likes
        Last Post aa731
        by aa731
         
        Started by thanajo, 05-04-2021, 02:11 AM
        3 responses
        470 views
        0 likes
        Last Post tradingnasdaqprueba  
        Started by Christopher_R, Today, 12:29 AM
        0 responses
        10 views
        0 likes
        Last Post Christopher_R  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,237 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        6 views
        0 likes
        Last Post thread
        by thread
         
        Working...
        X