Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

market analyzer calculate sma

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

    market analyzer calculate sma

    I cannot seems to have my script calculate the difference between a sma50 and the close price and display the result in the market analyzer column, the calculation works fine on a chart.

    protected override void OnBarUpdate()
    {

    double valueSMA = SMA(50)[0];

    if (Close[0] > valueSMA)
    {
    val = (Close[0] - valueSMA);
    }else if(Close[0] < valueSMA){
    val =(valueSMA - Close[0]);
    }

    valResult = String.Format("{0:0.00}", val);

    }


    #region Miscellaneous
    public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
    {
    graphics.DrawString("Price: " +valResult,textFont,textBrush,2,15);
    }



    #endregion

    #2
    kenford,

    The Market Analyzer only takes plot values. Plot values as not in what you place in a Plot() override, but as in what you store inside an actual indicator plot. Hopefully that makes sense.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I was about to create a new post and saw this - it pretty much is the same situation for me. I wanted a custom SMA so I could use the Typical calculation instead of the usual Close**. The indicator works perfectly when placed on the chart.

      However in Market Analyzer, my indicator only returns the LastPrice. Here is the very simple code in the indicator:

      Code:
      // shortperiod and longperiod are made available to enter the values
      // use typical for price type
      Plot0.Set (SMA(shortperiod) [0]);
      Plot1.Set (SMA(longperiod) [0]);
      I have the same situation in regards to Pivot Points, I would love to display them in the Market Analyzer, but again, it only returns the last price.

      Am I missing a key step here?

      Thanks!

      Dan

      ** It's odd that it's not built into Market Analyzer to switch price types....

      Comment


        #4
        Dan,

        Please ensure you have enough bars loaded in your Market Analyzer. Right click -> Properties -> # of bars back.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          Dan,

          Please ensure you have enough bars loaded in your Market Analyzer. Right click -> Properties -> # of bars back.
          Josh, the funny thing is, my SMA is only for 1 and 3 periods, so the default property setting should be fine! I'll have to try that for the pivots though.

          Any other ideas/resources on the SMA problem? Either I need to add something to my indicator, or I'm missing on how to set the price type to Typical in Market Analyzer....

          Thanks!

          Comment


            #6
            If you want SMA typical just open up the SMA indicator, save it as a new name and change the indicator code. Change all references to Input to Typical and then you will have a typical SMA instead of one that uses Close by default.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            94 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            49 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            31 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            34 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            70 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X