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

Bid/Ask Spread + CurrentBar

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

    Bid/Ask Spread + CurrentBar

    Hey guys, quick question. I entered the code
    Code:
    	
    spread = Math.Abs(GetCurrentAsk() - GetCurrentBid());
    									DrawText("Sell Trig" + CurrentBar, "Sell Trigger: " + Instrument.MasterInstrument.Round2TickSize(sellEntryPrice).ToString(), 1, High[1] + 6 * TickSize, Color.Orange);
    										DrawText("SPread" + CurrentBar, "Spread: " + Instrument.MasterInstrument.Round2TickSize(spread).ToString(), 1, High[1] + 15 * TickSize, Color.Blue);
    Into my indicator. and The "Sell Trig" works as always, just fine. shows Trig at every Signal. but the "Spread" always Shows 0. How can I show what the Spread was at Every Signal occurence? regardless of Strategy or signal. I just want the Spread to show on CurrentBars.

    #2
    Hello ginx10k,

    Thanks for your post.

    If I understand correctly you are looking for the spread in ticks. In that case you would want to change the first line to:

    spread = Math.Abs((GetCurrentAsk() - GetCurrentBid()) / TickSize); // get absolute difference then / TickSize.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hey Paul, I just tried this spread = Math.Abs((GetCurrentAsk() - GetCurrentBid()) / TickSize); and it didn't work either. It keeps showing 0. Any suggestions

      Comment


        #4
        Hello ginx10k,

        Thanks for your reply.

        Is spread a double?

        What instrument are you apply this to?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Code:
          private double spread = Math.Abs((GetCurrentAsk() - GetCurrentBid()) / TickSize);;
          Applied Only to EUR/USD. It Doesn't work for some reason.

          Comment


            #6
            Hello ginx10k,

            Here is what i am using:

            Code:
            if (Historical) return;
            			
            double spread = Math.Abs((GetCurrentAsk() - GetCurrentBid()) / TickSize);
            Print ("Spread:  "+spread +"  ticks: "+Instrument.MasterInstrument.Round2TickSize(spread).ToString());
            Output window results $EURUSD as source):
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 2.000000000002 ticks: 2
            Spread: 2.000000000002 ticks: 2
            Spread: 2.000000000002 ticks: 2
            Spread: 2.000000000002 ticks: 2
            Spread: 2.000000000002 ticks: 2
            Spread: 2.000000000002 ticks: 2
            Spread: 2.000000000002 ticks: 2
            Spread: 2.000000000002 ticks: 2
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 2.000000000002 ticks: 2
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Spread: 3.00000000000189 ticks: 3
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hey Paul, I get that also on Output window. but my original post was stating that I want

              Into my indicator. and The "Sell Trig" works as always, just fine. shows Trig at every Signal. but the "Spread" always Shows 0. How can I show what the Spread was at Every Signal occurence? regardless of Strategy or signal. I just want the Spread to show on CurrentBars.
              Meaning I want to see what the Spread was 10 bars ago. 50 bars ago. No matter how far back ago, just on Every Signal occurrence: example: if(EMA(10) > EMA(20) { enterSignal = true; DrawText("SPread" + CurrentBar, "Spread: " + Instrument.MasterInstrument.Round2TickSize(spread) .ToString(), 1, High[1] + 15 * TickSize, Color.Blue);
              }

              So is it possible to get Historical Spread? that's what I'm after

              Comment


                #8
                Hello ginx10k,

                Thanks for your reply.

                You would not be able to get historical bid/ask information as it is not stored.



                In both cases, on historical look, the close price of the evaluated bar is used.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Is it possible to add some kind of Slippage calculation into an Indicator (Not Strategy), so I can set my own Spread?

                  Comment


                    #10
                    Hello ginx10k,

                    You can take the work done with the spread and instead of printing to the output window send it to the chart using DrawTextFixed() method: http://ninjatrader.com/support/helpG...wtextfixed.htm
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      I already have an indicator that does that. I guess can't get it to do what I want. thx anyways

                      Comment


                        #12
                        Originally posted by ginx10k View Post
                        I already have an indicator that does that. I guess can't get it to do what I want. thx anyways
                        Have you tried adding a Bid and an Ask DataSeries, and calculating off those?

                        Comment


                          #13
                          I don't know how to do that. How can you use bid data series. If it doesn't get stored? I would appreciate if you showed me. Thanks.

                          Comment


                            #14
                            Originally posted by ginx10k View Post
                            I don't know how to do that. How can you use bid data series. If it doesn't get stored? I would appreciate if you showed me. Thanks.
                            Here is the reference, with necessary links: http://ninjatrader.com/support/helpG..._ask_serie.htm

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by MacDad, 02-25-2024, 11:48 PM
                            7 responses
                            158 views
                            0 likes
                            Last Post loganjarosz123  
                            Started by Belfortbucks, Today, 09:29 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post Belfortbucks  
                            Started by zstheorist, Today, 07:52 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post zstheorist  
                            Started by pmachiraju, 11-01-2023, 04:46 AM
                            8 responses
                            151 views
                            0 likes
                            Last Post rehmans
                            by rehmans
                             
                            Started by mattbsea, Today, 05:44 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post mattbsea  
                            Working...
                            X