Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TF's and orders

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

    TF's and orders

    Hello,

    I have read the related documentation about what I am going to ask because I don't get the point.

    First question:
    I have got a strategy which its main data is in TF 5min. In the script I add an extra time frame 1min. Both work on the same instrument. When I use 'FirstTickOfBar' I guess I am checking if we are at the first tick of the 5 minute bar, as 5 min. is the main data. Is this correct?
    I am asking, because my script doesn't seem to be doing this.

    Second question:
    I enter trades with EnterLongLimit and EnterLongStop with the property LiveUntilCancelled set to true. Let's suppose that the orders have not been filled yet. Will ExitLong("") cancel all orders? Or it's necessary to cancel each order with the instruction CancelOrder()?
    If they have been filled, will ExitLong("") close all orders?

    Thank you

    #2
    Hello bonnies,

    Thank you for your inquiry.

    To answer your first question:
    FirstTickOfBar will be checking all time frames unless you have specifically specified which time frame this code should run on with a BarsInProgress check.

    For example, if you want to only run code with FirstTickOfBar only on the primary Data Series, you would need to specify a BarsInProgress of 0.

    Example:
    Code:
    protected override void OnBarUpdate()
    {
         if (BarsInProgress == 0) // only run the code below if OnBarUpdate() has been called by the primary Data Series
              if (FirstTickOfBar)
              {
                   // stuff
              }
    }
    For more information about working with multiple time frames, I would suggest taking a look at the NinjaTrader help guide at this link: http://ninjatrader.com/support/helpG...nstruments.htm

    For more information about using BarsInProgress, please take a look at the NinjaTrader help guide at this link: http://ninjatrader.com/support/helpG...inprogress.htm

    To answer your second question:
    Utilizing ExitLong() will exit long positions. If you are not currently in a long position, then this method call will be ignored.

    Please take a look at the Tips section on the ExitLong() page of the help guide: http://ninjatrader.com/support/helpG.../?exitlong.htm

    "This method is ignored if a long position does not exist"

    To cancel these unfilled orders, you would use CancelOrder(). As CancelOrder requires a specific IOrder object to cancel in its parameters, ensure you have assigned those orders to IOrder objects.

    More information about IOrder can be found here: http://ninjatrader.com/support/helpG...t7/?iorder.htm

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your assistance. I have rewrite my code according to your notes. Thank you.

      I have an issue with the strategy. As I said the strategy runs on every tick. The compilation has no errors, and the backtest works. But when I add the strategy to a chart with real time data and I try to enable it, It doesn't allow me to enable it. On the output window I get this message:

      **NT**Error on calling 'OnBarUpdate' method for strategy '.......': Reference to object not stablish as instance of object

      What can I do?

      Thank you.

      Comment


        #4
        Hello bonnies,

        This would normally mean that your code is attempting to access an object that is set to null.

        I would suggest using a null check to ensure your code does not attempt to access a null object. Here is a link to a post here on our support forum that details checking for null references: http://ninjatrader.com/support/forum...44&postcount=1

        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Started by yertle, Today, 08:38 AM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by adeelshahzad, Today, 03:54 AM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X