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

Picking up invalid GetCurrentAsk()

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

    Picking up invalid GetCurrentAsk()

    I wrote this code last week and it worked perfectly but today it is picking up a figure of 1.4744 for GetCurrentAsk() for the Cable, when the actual figure is 1.4120

    Can you please advise the problem:-

    if (pf40 == 0)
    {
    pfdir = "True";
    pf40 = GetCurrentAsk();
    }

    This is to set the level once on startup, I then use the print statement below :-
    Print("Ask " + GetCurrentAsk());

    Print("PF40 " + pf40);

    And right at this moment get a figure returned of 1.4744 for the Ask for the GBPUSD which is of course some 600 pips wrong!!

    If I coment out the line if (pf40 == 0), so that I have the following:-

    // if (pf40 == 0)
    {
    pfdir = "True";
    pf40 = GetCurrentAsk();
    }
    then it reads correctly but this is ridiculous as pf40 is set by default to 0 and therefore this line should evaluate correctly. I need to have this correct so that it only evaluates the once. HELP!

    #2
    nigeleyre,

    Please ensure the code is in OnBarUpdate(). How do you figure the actual figure is 1.4120? Also, remember that GetCurrentAsk() is a realtime only property.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hello Josh, yes it is see below:-

      protected override void OnBarUpdate()
      {
      // Set Point & Figure Here



      //if (pf40 == 0)
      {
      pfdir = "True";
      pf40 = GetCurrentAsk();
      }

      Yes the figure is fluctuating and currently 1.4068 but cetainly not 1.4744! I just cannot see why is it picking up the latter figure when I comment back in the line

      if (pf40 = 0)

      Comment


        #4
        nigeleyre,

        Please also remove the { } brackets when you comment out your if-statement. See what the results are then. Also, please check the close price of the starting bar on the chart. By default, this is the 20th bar on the chart. I suspect you are just getting that close price as you access it historical data to process in the beginning. Please confirm/deny this case.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          We are making progress! Removing the brakets makes no difference but if I put the If(pf40 == 0) back in then it is indeed the value of the 20th Bar, how do I get round that as I want the value of the actual GetCurrentAsk() on startup and then I don't want it to evaluate that again?

          Comment


            #6
            nigeleyre,

            Then it is as expected. You are accessing the historical value at that point in time. Instead, you want to evaluate it on the first real-time processing.

            Code:
            if (!Historical && pf40 == 0)
            {
                 pdir = "True";
                 pf40 = GetCurrentAsk();
            }
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Many thanks Josh.

              Comment


                #8
                This still is not working. I cannot see the logic in it picking up the 20th bar from the start when I am asking it for GetCurrentAak()? Particularly as the exact same code was doing what I expected on Friday?

                Comment


                  #9
                  nigeleyre,

                  If you are picking up the 20th bar it is likely because you are grabbing the value historically or from a backtest. GetCurrentAsk/Bid() is only for real-time.

                  Please also check Control Center for errors.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ttrader23, 05-08-2024, 09:04 AM
                  10 responses
                  48 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by agclub, 04-21-2024, 08:57 PM
                  6 responses
                  40 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by thumper57, 05-11-2024, 04:30 PM
                  9 responses
                  28 views
                  0 likes
                  Last Post thumper57  
                  Started by Seneca, 08-25-2020, 08:31 AM
                  2 responses
                  5,945 views
                  0 likes
                  Last Post Tin34
                  by Tin34
                   
                  Started by casabella, Today, 04:12 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post casabella  
                  Working...
                  X