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

How to build a ( Bid+Ask)/2 indicator

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

    How to build a ( Bid+Ask)/2 indicator

    I'd like to have a simple (Bid+ask)/2 indicator to plot in a chart, for several time-frames..since I'm not a programmer I'm struggling to construct it...any help would be appreciated

    #2
    Originally posted by pstrusi View Post
    I'd like to have a simple (Bid+ask)/2 indicator to plot in a chart, for several time-frames..since I'm not a programmer I'm struggling to construct it...any help would be appreciated
    (GetCurrentBid() + GetCurrentAsk()) / 2

    this should get you started. the above is for the primary series. if you had added additional data series then simply modify the above code to

    (GetCurrentBid(1) + GetCurrentAsk(1)) / 2; //1 representing the 2nd data series.

    Comment


      #3
      Thanks Bukkan, studying the manual I built this code but I can see it isn't ok...can you please check it and tell me what to correct?

      Code:
      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Mpoint"));
      CalculateOnBarClose = false;
      Overlay = true;
      myDataSeries = new DataSeries(this); // this refers to the indicator/strategy itself
      // and syncs the DataSeries object to historical
      // data bars
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.
      // Calculate the range of the current bar and set the value
      myDataSeries.Set((GetCurrentBid(0) + GetCurrentAsk(0))/2);
      Mpoint.Set(myDataSeries[0]);
      }

      Comment


        #4
        I meant: it works calculating and plotting, but the calculation is not ok...I compared with actual charts from IB and results are not ok

        Comment


          #5
          A little example of what I found:

          For any bar, we had Bid 1243.50 Ask 1243.75; then the midpoint should be 1243.625 but the indicator shows either 1243.5 or 1243.75.

          The formula is ok, variables...etc but still not ok

          Comment


            #6
            Originally posted by pstrusi View Post
            A little example of what I found:

            For any bar, we had Bid 1243.50 Ask 1243.75; then the midpoint should be 1243.625 but the indicator shows either 1243.5 or 1243.75.

            The formula is ok, variables...etc but still not ok
            the best way to check the value will be to check the same in the OutputWindow

            Print("Bid: " + GetCurrentBid().ToString() + " Ask: " + GetCurrentAsk().ToString() + " Avg: " + ((GetCurrentBid() + GetCurrentAsk()) / 2).ToString());

            Comment


              #7
              Also I dont see the need for the additional dataseries in your code. Just put the calculated variable in the main plot itself.

              Comment


                #8
                Bukkan, all bid/ask of entire series are always the same...that is what is happening, do you know why or how can I correct it? Finally I see this in the output window

                Comment


                  #9
                  I've checked well in my database and all Bid/ask are ok, but somehow the functions getcurrentbid and ask are having problem,

                  Comment


                    #10
                    Originally posted by pstrusi View Post
                    I've checked well in my database and all Bid/ask are ok, but somehow the functions getcurrentbid and ask are having problem,
                    are the mkts open. make sure about that.

                    edit, aslo make sure you put

                    if (Historical) return;

                    the GetCurrentBid GetCurrentAsk is for RT quotes only.
                    Last edited by bukkan; 12-02-2011, 10:01 PM.

                    Comment


                      #11
                      Since I need to exhaust several historical analysis with other indicators, it's very important to me that I can get the whole historical calculation bar by bar; I'll try "if (Historical) return;" maybe with it it coud have the right output.

                      Thanks for your good attention

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Jonafare, 12-06-2012, 03:48 PM
                      5 responses
                      3,986 views
                      0 likes
                      Last Post rene69851  
                      Started by Fitspressorest, Today, 01:38 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post Fitspressorest  
                      Started by Jonker, Today, 01:19 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post Jonker
                      by Jonker
                       
                      Started by futtrader, Today, 01:16 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post futtrader  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      14 responses
                      1,792 views
                      0 likes
                      Last Post aligator  
                      Working...
                      X