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

Strategy calling another strategy

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

    Strategy calling another strategy

    Hi,
    I was wondering if the following is possible:

    I would have a strategy that would work on 30 min bars.
    After each bar close...
    - It would close out any open orders/positions
    - It would make some calculations based on values of the most recent bar
    - Call another strategy with those calculated values. This other strategy would be tick based.

    In the other "called" tick based strategy,
    - It would take the values passed by the 30 min bar strategy
    - Place orders based on price data of each tick meeting the strategy rules.

    The whole sequence would be repeated every 30 min bar close.

    Is the above possible?

    Thanks for your help!

    #2
    Hi menlo, you can directly create a multitimeframe strategy in NinjaTrader combining your 30 minute and tick frame - http://www.ninjatrader-support.com/H...struments.html

    For an example you could review the SampleMultiTimeFrame code installed per default.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply...

      I take it I would have to create 2 bars objects - one a 30 min bar and the other a 1 min bar.
      However, for my strategy to work, I would need to have 2 different settings for CalculateOnBarClose.

      Would it be possible to set CalculateOnBarClose to true for the 30 min bar object and CalculateOnBarClose to false for the 1 min bar in the same strategy?

      Comment


        #4
        Hi menlo, unfortunately you can only have one CalculateOnBarClose setting per strategy, but you could let your strategy run on false and manually filter this for the bars object where you want to calculate on close. You can do so by putting your logic for this bars object into
        Code:
        if (FirstTickOfBar)
        {
        do some calculations
        }
        You want to reference then one bar back further to adjust for calling on the open of the next bar instead of the close, so [0] calls would then become [1] calls.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks Betrand!

          Can you please tell me where I can find the SampleMultiTimeFrame code?

          Comment


            #6
            It's installed per default with your NinjaTrader installation, just go Tools > Edit NinjaScript > Strategy and open the 'SampleMultiTimeFrame' script.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks Bertrand!

              I copied the SampleMultiTimeFrame strategy and edited it to achieve what I am trying to do.

              I added two Bars objects. One is a 30 minute bar and the other is a 1 tick bar.

              I have the following code snippet after editing the original multitime frame strategy:
              --------------------------------------------------------------------
              protected override void OnBarUpdate()
              {
              // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
              // We only want to process events on our primary Bars object (index = 0) which is set when adding
              // the strategy to a chart

              if (BarsInProgress == 0) // This refers to the 30 min bar
              {
              Clean up open orders;
              calculate numbers to be used by the 1 tick bar to place orders;
              }

              if (BarsInProgress == 1) // This refers to the 1 tick bar
              {
              Place orders using numbers calculated in the 30 min time frame;
              }
              }
              --------------------------------------------------------------------

              The strategy compiled OK. When attached to a 30 min chart, it did not place any orders.

              The following message was in the log:

              "Error on calling 'OnBarUpdate' method for strategy 'jatpat1': Object reference not set to an instance of an object."

              I have CalculateOnBarClose set to true.

              Thanks for your help!

              Comment


                #8
                Hi menlo, thanks - when using multiple timeframes on a single instrument we would suggest executing only against the primary bars object, so in your case please reverse the order of your two series calls.

                Also I would suggest you disconnect from your live feed and go to Tools > Options > Misc to Repair your DB.

                Then reconnect and retest this please.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hi Bertrand,

                  I tried that but the same error persists.

                  It seems most of the strategy logic needs to be specified for an update of the primary bar. Problem is, I need to have some calculations done and order clean up done at the 30 minute bar.

                  I am thinking of just using one time frame - the 30 min with CalculateOnBarClose set to false.

                  As you suggested in one of your earlier replies, I am planning to use FirstTickOfBar. However, I am confused about...

                  1) If I use the FirstTickofBar construct in the current 30 minute bar, how do I reference the High, Low and Close of the previous 30 minute bar?

                  2) In the current 30 minute bar, after the first tick has already occurred, how do I reference the price of each incoming tick to compare with certain calculated numbers?

                  Hope that makes sense.

                  Thanks for your help!

                  Comment


                    #10
                    Hi menlo,

                    1. You can simply reference the needed price values one bar back, like High[1] or Close[1]

                    2. Just place the 'on every tick' logic outside the if (FirstTickOfBar) statement and you can use Close[0] which is then updated on every tick.
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by James650, 05-07-2024, 08:25 AM
                    3 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_ChristopherJ  
                    Started by xepher101, 05-10-2024, 12:19 PM
                    5 responses
                    66 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Vitamite, Yesterday, 12:48 PM
                    3 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by aligator, Today, 02:17 PM
                    0 responses
                    16 views
                    0 likes
                    Last Post aligator  
                    Started by lorem, 04-25-2024, 09:18 AM
                    22 responses
                    96 views
                    0 likes
                    Last Post lorem
                    by lorem
                     
                    Working...
                    X