Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to implement Bid/Ask fills in Strategy

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

    How to implement Bid/Ask fills in Strategy

    Hi,
    To implement more realistic fills in Forex, we need to use Bid/Ask data for the fills.
    The syntax for adding a Bid/Ask data series is
    Code:
    Add(string instrumentName, PeriodType periodType, int period, MarketDataType marketDataType)
    My question is how do I know what is the name of the instrumentName I'm testing against? Can I retrieve it prior to adding this data series?

    Baruch

    #2
    Baruch, yes, you can use a certain property to get the instrument's name:

    Code:
    string instName = Instrument.FullName;
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin thanks,
      Yes I know that, but the Add() function is used in Initialize. Will at that point the instrument be known to the strategy?

      Baruch
      p.s.
      Why don't you have an overload for bid/ask without the instrumentName?

      Comment


        #4
        Baruch, please try checking if instrument is null first.
        Code:
        if (Instrument != null)
        {
          string instName = Instrument.FullName;
          Add(instName, ...);
        }
        If that does not work, then you'll have to manually add the instrument.

        I am not sure why there isn't a add bid/ask overload. I'll forward that as a suggestion.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Austin hi,
          I know how to check and prevent the strategy from crashing. Do you really think that
          If that does not work, then you'll have to manually add the instrument.
          is an appropriate answer?

          Baruch

          Comment


            #6
            you can get the current bid/ask from the following code. no need to add any additional dataseries.

            Code:
            this.GetCurrentAsk();
            this.GetCurrentBid();
            the same has an overload too, useful for multiseries strategies/indicators.

            Comment


              #7
              bukkun thanks,
              But I think that I do need the Add(). This is because I need to enter and exit my trades on different BarsInProgress. So I enter LongLimit on Ask series and exit Shorts on Ask series.

              Baruch

              Comment


                #8
                Originally posted by Baruch View Post
                bukkun thanks,
                But I think that I do need the Add(). This is because I need to enter and exit my trades on different BarsInProgress. So I enter LongLimit on Ask series and exit Shorts on Ask series.

                Baruch
                you dont need to add the bid ask series. if you wan to enter long limit at ask you can simply use this code.

                Code:
                EnterLongLimit(GetCurrentAsk(),"signal name");
                anyway to get the instrument name in Initialize you can get it from the below code.

                Code:
                ChartControl.GetChartCaption
                you have to clean up it a bit.

                Comment


                  #9
                  you don't need to add the bid ask series. if you wan to enter long limit at ask you can simply use this code.


                  Code:
                  EnterLongLimit(GetCurrentAsk(),"signal name");
                  The syntax for limit orders is usually EnterLimit Long/Short(BarsInProcess, true,...,MyPrice,...)
                  I don't want to enter immediately, but at specific price! The question is if on current bar the high >= MyPrice so it will enter a trade.

                  Baruch

                  p.s.
                  I'm running back tests on granular resolution of 1 minute.

                  Comment


                    #10
                    GetCurrentAsk() and Bid() return the close of the bar when you're backtesting, not actual bids and asks. When running real-time, these methods behave as expected.

                    Baruch, the reason I suggested adding in the null check is because sometimes it works.

                    From the help guide, "NOTE: The properties in this class [Instrument] should NOT be accessed within the Initialize() method."

                    That is why I recommended you add in the manual name, so you have a working solution.

                    Basically, anything that could give you the instrument name (Instrument, BarsPeriod, etc) you can't access from Initialize().
                    Attached Files
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Austin,
                      I understand perfectly.
                      From the help guide, "NOTE: The properties in this class [Instrument] should NOT be accessed within the Initialize() method."
                      Thats exactly my point if it is not a working solution then I can't use it. On the other hand if I want to backtest Forex strategy, I need bid/ask series.
                      So your second solution is to hard code the curency I run the back test against in to the Add(). So do you prepose to create 20 strategies for 20 curency pairs only to work with bid/ask?

                      Baruch

                      Comment


                        #12
                        Baruch, this is unfortunately correct - or you add a string input so you can set the symbol needed at runtime.

                        Comment


                          #13
                          Bertrand,
                          I have a question:
                          If in my strategy I add:
                          Add(PeriodType.Tick,10);

                          And I backtest my strategy on instrument XXX and "Price based on = Last" and "Type=Minute"
                          What will be the instrument and the MarketDataType of my second data series?
                          Now if I backtest my strategy on instrument XXX and "Price based on = Ask" and "Type=Minute"
                          What will be the instrument and the MarketDataType of my second data series?
                          Hopefully from your answers you will understand that it needs to be an overload with MarketDataType but without an Instrument.

                          Baruch

                          Comment


                            #14
                            Hello Baruch,

                            If you don't specify a MarketDataType within the add statement, then added series will be last. It will work this way even if you select ask as primary series when running the strategy.

                            Hard coding instrument name is only solution for now. I will forward a request for new overload that allows specifying marketdata type without requiring instrument.
                            Last edited by NinjaTrader_RyanM1; 01-17-2011, 12:29 PM.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks,
                              I will wait. In the mean time I want to say that it works by extracting the name from Instrument.FullName

                              Baruch

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X