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

Spread indicator

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

    Spread indicator

    Hi, I need create SIMPLE indicator,

    Basically, I need an indicator that tells me the spread, a lot of programming, I can make robots with the system I want, but what I want to implement is something more advanced.

    I am very grateful that they could help me, I need to have an indicator that gives me the value of the spread.

    #3


    OK, very thanks, proced dowloand indicator but not,
    They do not do what I want, or maybe they explain me wrong (sorry my english)

    Bid price is 1.2303,3
    Ask price is 1.2303,4

    Diference is "1", how can it be 2 or 7 or 10

    I need to make a function that detects that difference and include the function (like any indicator), ejample "Moving Average is < 1.22", next to activate other blocks in my robot.

    I know it is possible to do what I want, but I find it complicated, although I know that I will end up doing it anyway.

    Regards and gretings

    Comment


      #4
      I need to create a variable that detects the difference between Ask Bid, to put that variable into a function. Could someone help me with the code? Can be done? it would be every tick

      Comment


        #5
        HTML Code:
                    if (GetCurrentAsk() == GetCurrentBid())
        I'm not good at programming but what I want is (Bid-Ask), that a value (negative or positive, I always take it as positive), that value put it in a variable, said variable inside a function.

        But I do not know how to put that in CODE.

        Comment


          #6
          Hello samir,

          You could do subtraction to get the difference between the ask and bid and set this to a plot value.

          In Initialize():
          AddPlot(Color.Blue, "myPlot");


          In OnBarUpdate():
          Values[0].Set(GetCurrentAsk() - GetCurrentBid());


          Below is a public link to a forum post with helpful information about getting started with NinjaScript.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #7
            protected override void Initialize()
            {
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
            Overlay = false;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            Values[0].Set(GetCurrentAsk() - GetCurrentBid());
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            Plot0.Set(Close[0]);
            }


            Chelsea, Thanks for Answer

            I do not understand much programming, could you correct the code? An indicator appears in the graph, but always indicates "1.24" (It moves in the graph, the line). Now, the "GetCurrent ask" and "GetCurrentBid", those data are exactly the ones that appear in the "control panel" or are they taken from the graph ?, that is, the "CurrentAsk" is the same as the "ASK" of the control panel ?

            I say it where is an indicator and the indicators are based on the candles or the data of the graph, but in this case the "CurrentAsk (by indicator)" the DATA is exactly the "Ask Price" that appears in the control panel with the instrument?

            What I need is an indicator that tells me the value of the spread of my broker, at the close or opening of each candle, that tells me the difference between bid and ask.

            I would like that you could help me, greetings.
            Last edited by samir; 03-14-2018, 06:28 PM. Reason: fixed

            Comment


              #8
              Hello samir,

              Yes, the example I posted would use ask as shown on the Control Center minus the bid as shown on the Control Center.

              This would be the difference between the two values.

              GetCurrentAsk() and GetCurrentBid() will only work in real-time.

              If you want this only when the bar closes use CalculateOnBarClose true. If you want this to update for every tick, use CalculateOnBarClose false.

              Below are publicly available links to the help guide on GetCurrentAsk(), GetCurrentBid(), and CalculateOnBarClose.




              Also. below is a link to a forum thread with helpful information about getting started with NinjaScript.


              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #9
                using notes here i created a spread indicator that plots the spread onbarclose, What i would really like to have is the highest is to plot oneachtick or onpricechange and plot the intrabar Highest value of the plot

                Spread[0] = (GetCurrentAsk() - GetCurrentBid());

                this is my plot in the OnBarUpdate() regiion

                any help appreciated

                Comment


                  #10
                  Hello DTSSTS, thanks for writing in.

                  The highest value of each OnBarUpdate call can be monitored like so:

                  private double highest = -1;

                  OnBarUpdate()
                  {

                  Spread[0] = (GetCurrentAsk() - GetCurrentBid());

                  if(Spread[0] > highest)
                  {
                  highest = Spread[0];
                  }

                  }

                  To solidify a value at the end of a bar when using an intrabar script, see the BuySellVolume indicator as an example. This demonstrates how to keep track of the active bar and set the final values once the bar is complete.

                  Chris L.NinjaTrader Customer Service

                  Comment


                    #11
                    Thanks alot

                    Well I tried the above script, ran OnEachTick and OnBarClose but the plot only plots the spread at bar close value

                    I would think while plotting OnEachTick that the plot as it reach a new intrabar High the It would remain at that level even if the intrabar spread pull back to a lower level (but OnEachTick plot moves up and down with current spread value)

                    Not sure this can be done with Ask and Bid
                    Last edited by DTSSTS; 09-30-2020, 04:42 PM. Reason: added results

                    Comment


                      #12
                      Chrisl also would like to know if using GetCurrentAsk and Bid can produce a plot that shows historical plot as well, currently when i load the indicator it starts out flat and produces the plot so long as the chart is open.

                      HOW WILL this effect using in a strategy from control panel - will the strategy know prev bar levels as the strategy runs throughout the session
                      Thanks

                      Comment


                        #13
                        Hello DTSSTS, thanks for your reply.

                        If you are looking at the historical data results then you would need to use GetBid() and GetAsk() during the historical mode. GetCurrentAsk/Bid is meant for real time only.

                        To check for historical mode:

                        OnBarUpdate()
                        {

                        if(State == State.Historical)
                        {
                        //run historical logic here
                        }
                        else
                        {
                        //Run Real Time code.
                        }
                        }
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #14
                          any ideas why the Highest is not being plotted (the plot is rending the spread value at bar close rather than the highest intrabar levels

                          Thanks

                          Comment


                            #15
                            real time

                            Spread[0] = (GetCurrentAsk() - GetCurrentBid());

                            historical

                            Spread[0] = (GetAsk() - GetBid());

                            WILL NOT COMPILE with GetAsk and GetBid

                            error "the name GetAsk does not exist in the current context

                            COMPLETE CODE

                            protected override void OnBarUpdate()

                            {
                            if(State == State.Historical)
                            {
                            //run historical logic here
                            Spread[0] = (GetAsk() - GetBid());

                            if(Spread[0] > highest)

                            {
                            highest = Spread[0];
                            }

                            }
                            else
                            {
                            //Run Real Time code.
                            Spread[0] = (GetCurrentAsk() - GetCurrentBid());

                            if(Spread[0] > highest)

                            {
                            highest = Spread[0];
                            }
                            }
                            }

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by elirion, Today, 01:36 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post elirion
                            by elirion
                             
                            Started by gentlebenthebear, Today, 01:30 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post gentlebenthebear  
                            Started by samish18, Yesterday, 08:31 AM
                            2 responses
                            9 views
                            0 likes
                            Last Post elirion
                            by elirion
                             
                            Started by Mestor, 03-10-2023, 01:50 AM
                            16 responses
                            391 views
                            0 likes
                            Last Post z.franck  
                            Started by rtwave, 04-12-2024, 09:30 AM
                            4 responses
                            34 views
                            0 likes
                            Last Post rtwave
                            by rtwave
                             
                            Working...
                            X