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

Request additional OIF / Direct Command

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

    Request additional OIF / Direct Command

    I would like to see the following options that are on Chart Trader also in the OIF/DLL Command options

    BUY ASK
    BUY BID
    SELL ASK
    SELL BID

    BUY/SELL is already an ACTION

    all that is missing is how to specify the PRICE as ASK or BID

    #2
    Hello vantojo,

    Thank you for the post.

    The OIF assumes you know what price and order type you wanted to use before submitting the order. You can currently do what you are asking by supplying the price you wanted to use along with the correct type of order.

    If you are missing the ask price, you would need to find a way to access that value in what you are doing in order to submit an order at that price. The OIF is simply relaying specific order instructions and is not like the internal NinjaScript order handling which has associated rules or convenience methods.

    Are you using an external appliation where the OIF may be nessasary or are you working from within NinjaTrader in NinjaScript?

    OIF is generally only intended to be used from outside applications where you already have a view of the market and where NinjaTrader does not need to be directly involved except for order entry. If your use case does not have ask price available, that is something you would need to address if you wanted to use that price when creating the OIF.



    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I trade from the chart and have written my own ClickTrader in NT7....it uses the OIF file to submit orders....

      I have to programatically click a button on ChartTrader to make the trades I want...and I have not ported this code yet to NT8

      I could attach two tick level datastreams, one for bid and one for ask, I suppose, but it seems a bit extreme when ChartTrader already knows this data

      Comment


        #4
        In a fast moving run it is not humanly possible each moment to know the bid/ask price....and to place a Limit order....software is needed to do this

        then, during a fast run, a Limit order at a fixed price is much safer than a market order

        if it doesn't fill it is OK, part of the game...but a market order price can run away before a fill

        Comment


          #5
          I also use the OIF to automate exits...this way I don't have to think about where to exit...I set various conditions on the chart and then indicator software makes the exit

          I had to do this in Ninja7 because your architecture made a strict definition between Indicator and Strategy....that the Indicator base did not include functionality for making trades without manual interaction with chart trader

          I am not using Strategies at all, for now, until I have time to make a bot architecture

          Comment


            #6
            Hello vantojo,

            From what you described, you are already in NinjaScript so you should have access to ask and bid prices. As you are submitting OIF orders, you would need to observe ask prices and use those if you wanted to do a ask price order. OIF has no convenience methods and is only intended to be an exact order entry, you enter exactly the type of order and values you wanted to submit.

            Based on the other details you provided, I believe you are limiting yourself by using NT7 for this use case as NT8 would handle this type of development much better. NT8 has the Addon framework which interfaces directly with an account to submit orders. You don't need to use a strategy, you can submit orders from a indicator or a new custom window you developed, really anywhere you wanted. Rather than writing an OIF file, you could just use native NinjaScript methods to do everything you wanted.



            Specifically see:



            and





            Please let me know if I may be of further assistance.



            JesseNinjaTrader Customer Service

            Comment


              #7
              Yes, I know...I intend to port all the custom NT7 code to NT8, but really it is a lot of work and learning WPF....and I've not been able to allocate that as an active project yet....I am just starting to consider the effort...so perhaps all this will resolve itself as I move forward...as with your response, I was not aware that NT8 now has a better architecture for Ninjascript trade entries from an Indicator...that would be a huge improvement over NT8....and I look forward to learning more.

              Comment


                #8
                Hello vantojo,

                I just wanted to provide a little more info here based on your reply. For what you are asking, technically you don't need to learn any WPF to begin your migration, really all of this can be accomplished from an indicator just using code if you wanted to begin testing with something less complex. There are a lot of WPF samples on the forum and in the help guide, one I could suggest specifically is the chart trader modification examples shown here: https://ninjatrader.com/support/foru...ns?postcount=1

                To start working from just an indicator, you can follow the Addon Account samples I linked in the last post, that is strictly code only and can be used in an indicator. If you note from the sample, it just shows A scripts "OnStateChange", this could be an indicator or whatever type really. When we say Addon, that can mean "code which is relevant toward most types" or "AddOnBase" which is a NinjaScript type of its own in the sense that Indicator is a type of its own.

                If you wanted to skip some of the lower level WPF learning process, you could technically use one of the WPF samples as a starting point. I do suggest learning WPF as it is required for further custom development but the samples on the forum are good starting points at making a tool rather than being locked into the strategy framework.

                Also you do not need to make a whole UI or modify existing controls, you can also just append buttons etc to the chart, here is an Indicator sample adding some buttons: https://ninjatrader.com/support/help...sercontrolcoll



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

                Comment


                  #9
                  Hi Jesse,

                  I'm encouraged by the new information, and perhaps the port to NT8 will not be as hard as I imagined....

                  I think my first task will be to convert my ClickTrader code...and it seems I can get real time bid/ask via two plots like this (from your forum)

                  ================================================== ===================================

                  Initalize(){
                  //
                  //Add(string instrumentName, PeriodType periodType, int period, MarketDataType marketDataType)
                  Add("ES 12-17", PeriodType.Tick, 1, MarketDataType.Ask);
                  Add("ES 12-17", PeriodType.Tick, 1, MarketDataType.Bid);

                  }

                  protected override void OnBarUpdate()
                  {

                  if (BarsInProgress == 1)
                  {
                  Print("Ask" + Close[0]);
                  }

                  if (BarsInProgress == 2)
                  {
                  Print("Bid" + Close[0]);
                  }
                  }

                  ================================================== ==============================================
                  Would not this be more or less the same as OnMarketData()?

                  In that documentation it has this warning....
                  5. Do not leave an unused OnMarketData() method declared in your NinjaScript object. This will unnecessarily attach a data stream to your strategy which uses unnecessary CPU cycles.
                  And what about

                  CalculateOnBarUpdate = False (in NT7)....would that not be the same?

                  One Tick level data stream?

                  ================================================== ==============================================

                  as part of this process I suppose I would convert the OIF file to the manner you describe...to have the ClickTrader indicator use an AddOn to submit (and Close) the orders?

                  Thanks

                  Comment


                    #10
                    Hello vantojo,

                    Thank you for the questions.

                    Would not this be more or less the same as OnMarketData()?
                    Not quite, Add() or AddDataSeries() in NT8 provides a series of data (if provided by the data provider) which includes historical data. OnMarketData() provides update events in realtime (or tick replay), so you'll get a Last event and then a Ask and a Bid as separate events as they occur.

                    When you add a BarsType using Add(), you are converting the data into the specified format. For example adding 1 tick data will just supply 1 tick bars, however 100 tick data you now have 100 tick bars for the added series. This relates to OnBarUpdate and will call OnBarUpdate in the frequency of each series the script has. OnMarketData never uses bars and only uses data points or individual ticks.


                    Do not leave an unused OnMarketData() method declared in your NinjaScript object.
                    The warning is just saying to not leave the OnMarketData override in your script if your not using it. Your script will make the platform subscribe to OnMarketData if you have the override in your script. It can use some CPU if this is in the script, so if you don't use it you should remove it.

                    CalculateOnBarUpdate = False (in NT7)....would that not be the same?

                    CalculateOnBarUpdate is a concept which controls Bar updates specifically. This only has relation to OnMarketData in the sense that OnMarketData is observing the same data which is building the bars. Changing this to true makes OnBarUpdate called for each bars close, using false calls OnBarUpdate for each tick instead. This is not the same as OnMarketData but does produce a similar effect, for example if we printed the Close[0] price from OnBarUpdate for each tick, it would be similar output to printing the Last price for each Last event in OnMarketData.

                    as part of this process I suppose I would convert the OIF file to the manner you describe...to have the ClickTrader indicator use an AddOn to submit (and Close) the orders?
                    Exactly, this removes the filesystem from the equation, you would just call the native NinjaScript method with the details for the order type you wanted to use. You can likely use most of what you made, it would mainly just be your outlet for writing the OIF file that would be changed to the addon frameworks order methods.

                    I look forward to being of further assistance.

                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Ok, does this make sense then....

                      Probably I should use OnMarketData to get the Bid/Ask....if I use a Plot/Data Series that is more than I need, as I don't need an array of historical ticks for this purpose...just the last tick bid or ask for the purpose of making a trade order at those data points.

                      Also, I don't think on the regular chart plotthe recent Bid/Ask is available on OnBarUpdate unless it is a tick dataseries with CalculateOnBarUpdate = false... And then I would need a data series for both Bid and Ask....so, no difference than coding a dataseries plot...

                      ??

                      Comment


                        #12
                        Hello vantojo,

                        Yes that sounds like it would work for the goal. If you do not need historical or Series based data, OnMarketData is one area where you can collect the ask or bid prices.

                        Also, I don't think on the regular chart plotthe recent Bid/Ask is available on OnBarUpdate unless it is a tick dataseries with CalculateOnBarUpdate = false... And then I would need a data series for both Bid and Ask....so, no difference than coding a dataseries plot...
                        This is not entirely correct, by default the Ask and Bid series are not included with your script, it would see either the Close series or the Input you supplied. You can add Ask and Bid series if needed, or you can call GetCurrentAsk() or GetCurrentBid() to just get their prices. CalculateOnBarUpdate = false will simply change how OnBarUpdate is called, but does not add or change the underlying data. If you were using a 1 minute series and use CalculateOnBarUpdate = true, you will see OnBarUpdate calls for each 1 Minute bar. If you use CalculateOnBarUpdate false, we see OnBarUpdate being called for each tick in the minute series.

                        If you need ask and bid data, it will likely be easiest to either use the GetCurrentAsk/Bid() methods from where you need the price, or using OnMarketData. Keep in mind OnMarketData produces only 1 data point per update, you wont see both Ask and Bid at once in OnMarketData. If you needed the Ask or Bid price at any given time, for example to submit an order at that price, you should probably use GetCurrentAsk(). You could alternatively use OnMarketData to store the last seen price as a variable so you could use the variable in other areas of your script.







                        I look forward to being of further assistance.

                        JesseNinjaTrader Customer Service

                        Comment


                          #13

                          Hi Jesse,

                          It may be that we have drilled down to the solution I need...I only need the bid or ask price when I make a certain combination of control keys / mouse click...that is the signal to go long or short, and at ask or bid....

                          I don't need a continuous stream, such as OnMarketData, or a data series

                          The question:

                          Say I have a one minute interval (or less) and CalculateOnBarClose = false....then when I call GetCurrentBid/Ask, will it return the Bid/Ask at the last (immediate) tick?

                          Thank you for your patience, as I am mostly self taught in this area....and was not even aware of these methods.

                          Comment


                            #14
                            Hello vantojo

                            Say I have a one minute interval (or less) and CalculateOnBarClose = false....then when I call GetCurrentBid/Ask, will it return the Bid/Ask at the last (immediate) tick?
                            Yes, this will return the last known Ask/Bid for the current instrument.

                            As you noted this would be going in a button handler or other non market data event driven areas, another detail which will help is using TriggerCustomEvent to make sure your NinjaScript properties are up to date when accessing them in that context:




                            Here is a quick example of surrounding code with a trigger:

                            Code:
                            TriggerCustomEvent((o)=>{
                                double ask = GetCurrentAsk();
                            
                            Print(Close[0]);
                            
                            //other order submission
                            
                            }, 0, null);
                            This type of syntax makes sure the NinjaScript properties are valid when you access them, for example Close[0] means nothing inside a button handler, but does mean something for the current processing bar in OnBarUpdate. Inside the TriggerCustomEvent you can access script variables just like from inside OnBarUpdate. When migrating to NT8 there are many more areas where this is required due to the expanded GUI design options. This is a concept to become aware of when doing GUI design which requires NinjaScript values.


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

                            Comment


                              #15
                              Thanks Jesse....now that I remember the details of this particular entry....it would be with a Control Key Down event handler

                              Would the TriggerCustomEvent be inside that event handler?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by aa731, Today, 02:54 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post aa731
                              by aa731
                               
                              Started by thanajo, 05-04-2021, 02:11 AM
                              3 responses
                              470 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,237 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Working...
                              X