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 set a different data series into an indicator

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

    How to set a different data series into an indicator

    I've been looking how to set a (bid+ask)/2 as a new data series as input for different indicators (sma, ema, macd, rsi...etc)

    - How can I set this special data as input into these indicators?

    - Must I program this as new data series into the source code of any indicator? if so, what would these lines of code be?

    I thought that NT7 would bring this kind of data, (thought it was Median price but it wasn't)

    Any help would be appreciated

    #2
    pstrusi,

    Are you doing this with tick based charts? Otherwise, a bar is made of of many ticks and as such will be a composite of all the bids and all the asks.

    You can add Bid and Ask dataseries to a multi-timeframe indicator by doing the following.

    Add(string instrumentName, PeriodType periodType, int period, MarketDataType marketDataType)

    Where marketDataType is either MarketDataType.Bid or MarketDataType.Ask.

    Once you add both the bid and ask dataseries you can construct the third one.

    Please see more information at the following link.



    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam, yep I use different time-frames for intraday bar charts (5 secs, 10 secs...etc) I know what you say is the right thing, but I need some additional help through an example, cause I'm not a programmer:

      I want to plot different indicators for ES 12-11, let's say 5 secs, building (bid+ask)/2 bars...applied to sma, ema, macd...etc

      - What lines of code should be written for this example?
      - Where should be them written, in the indicator source code, or must I create a new serie of data as a new instrument?

      thanks in advance

      Comment


        #4
        I've put these lines into an indicator:
        Add(PeriodType.Second, 5, MarketDataType.Bid);
        Add(PeriodType.Second, 5, MarketDataType.Ask);

        I want to know:
        - How Can I construct the (bid+ask)/2 series data in order to feed my indicator?
        - Once I hava that series-data, How can I apply it as input for my indicator?

        Thanks

        Comment


          #5
          Pstrusi,

          Something like :

          Code:
          if ( BarsInProgress == 1)
          {
              // update the Ask data series
              askseries.Set(Closes[1][0]);
          }
          else if ( BarsInProgress == 2)
          {
             // update the Bid data series
              bidseries.Set(Closes[2][0]);
          }
          else if( BarsInProgress == 0)
          {
             Plot0.Set((bidseries[0]+askseries[0])/2)
          }
          The main issue with this is that it primarily will work best with historical data rather than current data, for example with CalculateOnBarClose = false. You can use GetCurrentBid() or GetCurrentAsk() if you know you are at the most current bar and you want to construct a more accurate dataseries from live data.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Thanks Adam for all these code tips, just great. but I can see that I'm aiming a non-easy issue here and still having questions regarding; since my strategy uses always "calculate on bar close" I don't need real time calculation but I need to know this:

            1. Where must I put those code lines into my indicator in order to feed it as "input data" ?
            2. If I set a new strategy using my indicator, what would I put in the field "input series" ?
            3. Are necessary and useful the codes I set before following your previous instruction to complete your last code? I really don't get it
            Add(PeriodType.Second, 5, MarketDataType.Bid);
            Add(PeriodType.Second, 5, MarketDataType.Ask);

            4. Adam I have to confess this is confusing me a little bit....can you please be kind and tell me what code exactly that I must write into a MACD for 30 secs bar chart on ES 12-11 calculating on (bid+ask)/2?

            it really would help a lot to complete my studies that I'm already late

            Comment


              #7
              Originally posted by pstrusi View Post
              Thanks Adam for all these code tips, just great. but I can see that I'm aiming a non-easy issue here and still having questions regarding; since my strategy uses always "calculate on bar close" I don't need real time calculation but I need to know this:

              1. Where must I put those code lines into my indicator in order to feed it as "input data" ?
              2. If I set a new strategy using my indicator, what would I put in the field "input series" ?
              3. Are necessary and useful the codes I set before following your previous instruction to complete your last code? I really don't get it
              Add(PeriodType.Second, 5, MarketDataType.Bid);
              Add(PeriodType.Second, 5, MarketDataType.Ask);

              4. Adam I have to confess this is confusing me a little bit....can you please be kind and tell me what code exactly that I must write into a MACD for 30 secs bar chart on ES 12-11 calculating on (bid+ask)/2?

              it really would help a lot to complete my studies that I'm already late
              1. You need to put the code I provided into OnBarUpdate.

              2. Input series can be anything, doesn't matter since you added your Ask and Bid to a multi-timeframe indicator.

              3. This Add() code must be put in your initialize, along with :

              Code:
              bidseries = new DataSeries(this);
              askseries = new DataSeries(this);
              These also must be declared in your variables section as :

              Code:
              DataSeries bidseries;
              DataSeries askseries;
              4.

              Hopefully I have given you everything you need to construct this indicator. I would recommend posting it after you code it and then I can comment on what parts may need changing.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Adam I'm following your instructions, adding them into a MACD indicator but I think that this is becoming a "Frankenstein indicator" because I can see all the "sets before" for last prices, is crashing with these new lines....Can I send all code to an e-mail in order to not overloading this post? of i you want I can post it through here

                Comment


                  #9
                  pstrusi,

                  Sure, please send to [email protected] with ATTN Adam in the message body.

                  I look forward to helping.
                  Adam P.NinjaTrader Customer Service

                  Comment


                    #10
                    Adam I thought this as temporary solution:

                    I'm trying to construct a custom indicator called: midpoint, where I can calculate (Bid+Ask)/2 then use this output as data series to feed any input for indicators...I think this is an easier way to solve my problem.

                    Since I'm not a programmer I'm still struggling to build it but I think being simple as it's, it won't take me too much

                    Thanks anyway

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by RookieTrader, Today, 09:37 AM
                    3 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by kulwinder73, Today, 10:31 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post kulwinder73  
                    Started by terofs, Yesterday, 04:18 PM
                    1 response
                    23 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by CommonWhale, Today, 09:55 AM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by Gerik, Today, 09:40 AM
                    2 responses
                    7 views
                    0 likes
                    Last Post Gerik
                    by Gerik
                     
                    Working...
                    X