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

Little modification of spread indicator (help needed)

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

    Little modification of spread indicator (help needed)

    Hello,

    Can someone be so kind to make a small modification to the spread indicator for NT8 ?

    What I need is - to compare bid to bid (1st instrument bid to 2nd instrument bi) or ask to ask or (bid+ask)/2 to (bid+ask)2, not last to last or ask to last or bid to last.

    I know I can change data series from last to ask or bid, but still it compares with another instrument's last price (on chart there is info that the comparision is between 1 produkt ask and another product ask - but that's not true, I chacked it with price change on both ladders and how the spread chart behave)

    I will be thankful for help.


    Regards

    #2
    Hello MichalTr,

    If this is something you wanted to attempt yourself it looks like you would likely just need to change what data the script is adding. It looks like the data being added in the spread indicator is just the Last data. To add the ask or bid data would require changing the AddDataSeries syntax.



    Code:
    AddDataSeries(string instrumentName, BarsPeriodType periodType, int period, MarketDataType marketDataType)
    or to match whats already in the file: 
    AddDataSeries(Symbol2, BarsPeriod.BarsPeriodType, BarsPeriod.Value, MarketDataType.Ask);
    This will also depend if your data provider supplies ask/bid data, please ensure to check if you get historical ask/bid data in a chart prior to testing this. The primary chart series would need be changed to the ask/bid series you wanted to compare.

    Spread indicator for reference: https://ninjatraderecosystem.com/use...load/spread-2/


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

    Comment


      #3
      @NinjaTrader_Jesse

      That's very helpful. Thank you !

      And is it possible to make it (bid+ask)/2 ?


      Regards

      Comment


        #4
        Hello MichalTr,

        Yes that is also possible however that would depend on how you wanted to change the file and what primary you wanted /what bid/ask is being compared. If you mean the primary against the secondary you would just need to make sure the secondary is adding the opposite type. For example if you used an ask primary, you could add a bid secondary and then do your math. If you instead mean to compare both the ask/bid from the primary or secondary, you would need to add both the ask/bid data for the instrument in question.

        If we assume you meant the Primary bid plus secondary ask / 2, it would look like:

        Code:
        double val = Closes[0][0] + Closes[1][0] / 2;
        Keep in mind closes represents the input series here, your primary was a bid series and the added secondary data is ask, this is then available using the Close series.

        You can read more about multi time frame syntax in the following page: https://ninjatrader.com/support/help...lightsub=multi

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

        Comment


          #5
          @NinjaTrader_Jesse
          Thank you.

          What I want to do is to compare (bid+ask)/2 from 1st instrument with (bid+ask)/2 from 2nd instrument.

          Example:
          CLZ19 (december crude oil) is trading 54,10 (bid) 54,11 (ask)
          CLF20 (january crude oil) is trading 54,17 (bid) 54,18 (ask)

          If I make simple spread let's say 1*CLZ19 - 1*CLF20, I want that calculation: (54,10 + 54,11)/2 - (54,17 + 54,18)/2

          btw: I know that the result of bid - bid is same as result of ask - ask and same as result of equation above, but it's not about this. It's about clean and more accurate shorter term chart (that is based on time intervals). Your help with ask-ask and bid-bid has already improved it a lot, and with this it would be perfect.

          I will be thankful for help


          Regards

          Comment


            #6
            Hello MichalTr,

            In that case you would need 4 total series, so 3 in addition to the primary.

            Right now the spread script is programmed in a way to work with 2 series only, if you are trying to use the existing logic in the script it would require modification. If you are trying to do a custom calculation like the one you mentioned, it may be easiest to just remove the existing logic and make the calculation you actually wanted.

            To do what you are asking, you could duplicate the AddDataSeries syntax two times and then enter the information you need for those series. For example assuming you were using a bid chart:

            Code:
            AddDataSeries("ES 12-19", BarsPeriodType.Minute, 1, MarketDataType.Ask);
            AddDataSeries("CL 12-19", BarsPeriodType.Minute, 1, MarketDataType.Bid);
            AddDataSeries("CL 12-19", BarsPeriodType.Minute, 1, MarketDataType.Ask);
            The next 3 series add the Ask for the primary, and then the secondary both ask and bid. How this is represented in the script would be with the plural named series like Closes or Opens. In the existing code you can see this concept being used:

            Code:
            Value[0] = Closes[Instrument1][0] * mul1 + Instrument2Close[0] * mul2;
            For your calculation you would do a similar item or:

            Code:
            double calculatedVal = Closes[0][0] + Closes[1][0] / 2;
            This would take the primary series Bid + Ask divided by 2. The same would happen for the other calculation, you just increase the BarsInProgress:

            Code:
            double calculatedVal2 = Closes[2][0] + Closes[3][0] / 2;

            This type of change would also require changing the data check at the beginning of OnBarUpdate:

            Code:
            if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[2] < 1)
            return;



            If any of this is not clear please let me know, also I would suggest reviewing the multi series development page as this explains the concepts we are talking about: https://ninjatrader.com/support/help...lightsub=multi


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

            Comment


              #7
              @NinjaTrader_Jesse

              Thank you for info. I will try to play with that.


              Regards

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by algospoke, Yesterday, 06:40 PM
              2 responses
              19 views
              0 likes
              Last Post algospoke  
              Started by ghoul, Today, 06:02 PM
              3 responses
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              44 views
              0 likes
              Last Post jeronymite  
              Started by Barry Milan, Yesterday, 10:35 PM
              7 responses
              20 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by AttiM, 02-14-2024, 05:20 PM
              10 responses
              180 views
              0 likes
              Last Post jeronymite  
              Working...
              X