Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Spread Indicator

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

    Spread Indicator

    I created a spread indicator to be used with Market Analyzer.

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.Firebrick, PlotStyle.Bar, "Spread"));
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    Value.Set(GetCurrentAsk() - GetCurrentBid());
    }

    I works perfectly if I add it in one of the columns. However the reason why I wanted to use it is that I wanted to a column to keep track of the difference between the advancing and declining issued on NYSE and NASDAQ. For some reason the indicator does not make the calculation for the two indexes but it does for all the other insutruments, as shown in the picture.
    Attached Files

    #2
    This is likely since indexes do not have a bid/ask price since they are not tradeable.
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. Can you suggested another route to be able to watch the difference between advincing and declining issues in the market analyzer? Is there a way to use the actual instrument inside Ninjascript and create an indicator that can substruct the two instruments?

      Comment


        #4
        Unfortunately multi-series indicators are not currently supported. This is on our list for future enhancements.
        RayNinjaTrader Customer Service

        Comment


          #5
          Another little question on the Market Analyzer and Indicators: I created an indicator that keeps track keeps track of the difference between the last price and the open of the current bar and that works on Market analyzer (I set it to 30 min bar and Calculate on bar close set to False.

          protected override void OnBarUpdate()
          {
          Value.Set(Close[0] - Open[0]);
          }

          How would go about creating an indicator that calculates the difference between the the current bar open and the last bar Open (30 min bars)? This is because I need to have in one Market Analyzer cell this number). I tried with

          protected override void OnBarUpdate()
          {
          Value.Set(Open[0] - Open[1]);
          }

          but it does not seem to work. The only thing I was able to do is create an indicator (to be used in a Market analyzer cell) that has the value of the open of the previous bar by having Calculate on bar close set to True and then

          protected override void OnBarUpdate()
          {
          Value.Set(Open[0])
          }

          How can I solve my problem?

          Comment


            #6
            IMO all you have to do is set calculate on bar close to false. The value should be calculate for the current bar, bit of a waste but that's how it is.

            Comment


              #7
              Thanks for your reply. Actually I do not want it to change with every tick. I need to have a cell that has one number: the difference between the open of the current 30 minute bar and the open of the last third minute bar. Obviously every 30 minute the number will change, but only after there is new bar

              Comment


                #8
                Why don't you use Close[0] - Open[0]? This would produce about the same result when calculate on bar close is true?
                Logic behind it is: the value is calculate when a new bar starts to print, 0 refers in this case to the previous bar and Close of the previous bar should theoretically be very close to the Open of the current bar.

                When I say current, previous, next I mean the bars on the chart, NT is lagging one bar behind if calculate on bar close is true.

                If caluclate on bar close is false: it's Open[ 0 ] - Open[ 1 ], Open[ 0 ] doesn't change, only Close[ 0 ], High, Low ... can change with every tick, sorry for confusing you.
                Last edited by Rollins; 12-13-2007, 05:31 AM.

                Comment


                  #9
                  This is actually a very good idea, but in this way the number will be the difference between the close and the open of the previous bar; but the close of the previous bar and the open of the current bart may be VERY different. Unfortunately I relly need that particular number.

                  How is it possible that NT does not have a way to keep track and use the data of the previous bars in an indicator?

                  I looked at data Series

                  Add(Instrument, PeriodType.Minute, 30);

                  but they do not seem to work for indicators, only for strategies. I really do not know what to do

                  Comment


                    #10
                    Originally posted by luitom View Post
                    This is actually a very good idea, but in this way the number will be the difference between the close and the open of the previous bar; but the close of the previous bar and the open of the current bart may be VERY different. Unfortunately I relly need that particular number.

                    Intraday the difference should be minor, especially on long period bars like 30mins. Between sessions things are very different.

                    The 2nd approach with calculateonbarclose false should deliver the exact results. Open[ 0 ] - Open[ 1 ]

                    Comment


                      #11
                      Unfortunately, I am trying right now in real time and the difference is sometimes significant.

                      The second approach I have tried already but for some reason if I use
                      Open[ 0 ] - Open[ 1 ] with calculateonbarclose false what happens is that the number changes in real time and the Open[1] apparently does not work inside the indicator script

                      Comment


                        #12
                        Either set BarsRequired to 2 in Initialize()

                        or use if( CurrentBar > 0 ) Value.Set(Open[0] - Open[1]);

                        Otherwise the indicator might crash.

                        I have no idea why Open[ 0 ] should change in real time, that would be a bug.
                        Unless it represents the Open of the last tick, which I don't think.

                        In that case add if( FirstTickOfBar )
                        Last edited by Rollins; 12-13-2007, 06:56 AM.

                        Comment


                          #13
                          I have not read through all recent replies but to get what you want...
                          Code:
                          protected override void OnBarUpdate()
                          {
                              if (CurrentBar > 0)
                                  Value.Set(Open[0] - Open[1]); 
                          }
                          Then apply indicator to MA column and select 30 min series.
                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            I added the line as you suggested if( CurrentBar > 0 ) Value.Set(Open[0] - Open[1]); and it works now. Thanks a lot for your help. Even though I do not understand why it works.

                            Comment


                              #15
                              This will explain it.

                              RayNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X