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

Calling indicator from Market Analyzer script

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

    Calling indicator from Market Analyzer script

    Hi,

    I've read through what I could find in the docs re the MA. There didn't seem to be much, but I gather I can call an Indicator just like I can anywhere else. I just want to echo the public variable from the indie to an ma column (which I can't do unless I create some MA code as it is not a plot). I have a problem though in that my OnBarUpdate in my indicator appears to not be running when called from a market analyzer script. There are no errors in the log.

    As an example, I have the below code in the indicator

    Now, when I call my indicator from within the market analyzer code, like this

    private NinjaTrader.NinjaScript.Indicators.TheIndicator TS1;
    and
    else if (State == State.Configure)
    {
    TS1 = TheIndicator("");
    }



    it does indeed print 'LoadingTheIndicator' to the output window from the below code in the indicator, showing it got at least that far. LoadingTheIndicatorOB from the OnBarUpdate in the indicator never does print. It appears OnBarUpdate is not being called (or the print is not being printed). The indicator works perfectly fine and as expected on the chart. No errors occur in the log when you 'reload all ninjascript' from the MA.

    else if (State == State.Configure)
    {
    states = new Series<s tring>(this, MaximumBarsLookBack.Infinite);
    myFont = new NinjaTrader.Gui.Tools .SimpleFont("Consolas", fontSize) { Size = fontSiz e, Bold = true };
    Print("LoadingTheIndicator...");
    }
    else if (State == State.DataLoaded)
    {
    // if (ChartControl != null && Bars.BarsType.IsTimeB ased)
    // {
    // ChartPeriod = Bars.BarsPeriod.ToString();
    // }
    }
    }


    protected override void OnBarUpdate()
    {
    double entry=0, target=0;
    Print("LoadingTheIndicatorOB..."+CurrentBa r);
    if (IsFirstTickOfBar)


    What super obvious thing am I missing here, please!?

    #2
    Hello pjsmith,

    Thanks for the post.

    I can't tell from this sample but if you have not set IsDataSeriesRequired then OnBarUpdate will not be used. Can you check that you have IsDataSeriesRequired = true in State.SetDefaults?



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

    Comment


      #3
      Hi,
      Thank you for the response. Just checked. Yes, I have it in there. In fact, here is the entire market analyzer code. Nothing much to it really.

      PHP Code:
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public class 
      TheIndicatorMktAColumn MarketAnalyzerColumn
      {
      private 
      NinjaTrader.NinjaScript.Indicators.TheIndicator TS1;

      protected 
      override void OnStateChange()
      {
      if (
      State == State.SetDefaults)
      {
      Description = @"Returns the current status of TheIndicator from the companion indicator.";
      Name "TheIndicatorMktAColumn";
      Calculate Calculate.OnPriceChange;
      IsDataSeriesRequired true;
      DataType typeof(string);
      IsEditable true;
      }
      else if (
      State == State.Configure)
      {
      TS1 TheIndicator("");
      }
      }

      protected 
      override void OnMarketData(Data.MarketDataEventArgs marketDataUpdate)
      {
      CurrentText "TEST"TS1.StratStateString;
      //Print("TheIndicatorStatus="+CurrentText);
      }
      }

      Comment


        #4
        Hello pjsmith,

        For an Indicators OnBarUpdate to be called in this context it will also need to be used from OnBarUpdate in the column. If you don't call the indicator to retrieve a value from a Plot then it won't be used. If the indicator has no plots you need to cal the Update method on the indicator from the analyzer column OnBarUpdate.

        It also looks like that may be a public string property that you had used for the indicators StratStateString. If so make sure you have followed the sample in the following link which shows how to expose a public proeprty that is not a Plot and how Update() is used within the property.





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

        Comment


          #5
          Thank you. Your responses addressed all my problems.

          For feedback, I did not actually find one example in the standard code or in the docs of OnBarUpdate being used in a mkt analyzer column (maybe I just missed it). Also, forcing the update as there was no plot being called was required. 1 more thing. Using ChartControl != null to test to see if the indicator was able to write to a chart to avoid any draw.line etc.

          Anyway, thanks again for the detailed response.

          Comment


            #6
            Hello pjsmith,

            That's correct, the MA columns generally don't use OBU, they are live data tools so they make use of OnMarketData or Depth. The OBU items come from the indicator column and are exposed for NinjaScript use however that is not really the default use case for a MA column (you can just use the indicator column for most use cases) so there is not much information on that topic at this time.

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DayTradingDEMON, Today, 09:28 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            8 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by helpwanted, Today, 03:06 AM
            2 responses
            21 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by navyguy06, Today, 09:28 AM
            0 responses
            2 views
            0 likes
            Last Post navyguy06  
            Started by rjbtrade1, 11-30-2023, 04:38 PM
            2 responses
            77 views
            0 likes
            Last Post DavidHP
            by DavidHP
             
            Working...
            X