Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Max Down Day

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

    #76
    If I have the following Add's below where the 5min primary series for each instrument is indexes 0-2 and the 1min series is indexes 3-5, how do I fit this into the script below using BarsInProgress as you have suggested. The 1min secondary series is always +3 of the primary. I made an attempt to plug it in below but the im getting 0 trades which I would expect because it doesn't look right at all...

    Add("APA", PeriodType.Minute, 5); //series 1 primary for APA
    Add("DIA", PeriodType.Minute, 5); //series 2 primary for DIA
    Add(PeriodType.Minute, 1); //series 3 secondary for SPY
    Add("APA", PeriodType.Minute, 1); //series 4 secondary for APA
    Add("DIA", PeriodType.Minute, 1); //series 5 secondary for DIA

    Original..
    Code:
    for (int series = 0; series < 3; series++)
    if ((BarsInProgress == series + 3)
    && (SMA(BarsArray[series],Fast)[1] > SMA(BarsArray[series],Slow)[1] && SMA(BarsArray[series],Fast)[2] < SMA(BarsArray[series],Slow)[2] && Closes[series+ 3][0] > Highs[series][1] + distance))
    Plugging in BarsInProgress..
    Code:
    if ((BarsInProgress == BarsInProgress + 3)
    && (SMA(BarsArray[BarsInProgress],Fast)[1] > SMA(BarsArray[BarsInProgress],Slow)[1] && SMA(BarsArray[BarsInProgress],Fast)[2] < SMA(BarsArray[BarsInProgress],Slow)[2] && Closes[BarsInProgress + 3][0] > Highs[BarsInProgress][1] + distance))
    Last edited by zachj; 07-10-2013, 05:46 PM.

    Comment


      #77
      Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - unfortunately we cannot offer such debug or code modification services here, but please see the provided resources below to help you proceed productively :

      For debugging tips: http://www.ninjatrader.com/support/f...ead.php?t=3418

      If you would prefer the debug assist of a professional NinjaScript consultant, please check into the following listings - http://www.ninjatrader.com/partners#...pt-Consultants
      LanceNinjaTrader Customer Service

      Comment


        #78
        So basically you have no clue?

        Comment


          #79
          Unfortunately we do not have the resources to offer such debug or code modification services here free of charge. You will want to Begin adding Print() statements to check values and you'll be see you have logical checks that are never going to evaluate to true.

          if ((BarsInProgress == BarsInProgress + 3)

          Will never evaluate to true.

          We are happy to help users with simple questions here and there to assist them in their learning process. However we will not be able to create you a script free of charge. If you would prefer to have a script created for you please check into the following listings - http://www.ninjatrader.com/partners#...pt-Consultants
          LanceNinjaTrader Customer Service

          Comment


            #80
            Oh really well Bertrand offered code. Unfortunately it was incorrect as he offered the series + 3 idea earlier in this post. Maybe you should let HIM know that this will "never evaluate to true" instead of users being sent on a wild goose chase like I've been sent on for the last two weeks chasing this! Thanks

            Comment


              #81
              Hello,

              series (a user created variable) is different from the pre-defined BarsInProgress



              (BarsInProgress == someVariable + someNumber) could evaluate to true.

              I would also recommend checking out these videos here: http://channel9.msdn.com/Series/C-Sh...lute-Beginners

              They are not affiliated with NinjaTrader but I know they are a valuable learning tool for learning C#
              LanceNinjaTrader Customer Service

              Comment


                #82
                Alright. Thanks

                Comment


                  #83
                  Originally posted by NinjaTrader_Lance View Post
                  Unfortunately Set methods can only be applied to the primary time data series. It does not matter what BIP you are in when you set this. If the entry order is not in BIP == 0 then the set will not necessarily be applied with the entry.

                  Notes:
                  1. Should you have multiple Bars objects of the same instrument and are using Set() methods in your strategy, you should only submit orders for this instrument to the first Bars context of that instrument. This is to ensure your order logic is processed correctly and any necessary order amendments are done properly.
                  I'm trying to understand the above, so Set methods will only recognize index 0 period. Or will it recognize the primary for each instrument if it's a multi instrument script? So if primary for the 1st instrument is index 0 and the primary for the 2nd instrument is index 1 will Set() recognize both indexes?

                  Comment


                    #84
                    I typically encourage users to stay away from the Set methods all together when dealing with Multi series scripts but you can use them without issues. You should only submit orders for this instrument to the first Bars context of that instrument.
                    Your situation described would recognize both. You would want to make sure you used signal names to match the orders accordingly.
                    LanceNinjaTrader Customer Service

                    Comment


                      #85
                      I was told by Bertrand to put this post over here even though I feel I'm trying to go a different route by seperating the instruments out to have there own entry and stoploss and using signal entry names.....

                      This is for backtesting purposes. I made an attempt at having 2 instruments in one script below but when I compare it to running a single script against the same 2 instruments seperately I get different net profit results. I tried using "else if" as well. Is there anything else I'm doing incorrectly or is it not even possible to do what I'm attempting here?

                      Code:
                       
                      protected override void Initialize()
                      {
                       
                      //SPY is Primary series 0
                      Add("DIA", PeriodType.Minute, 5); //series 1 primary for DIA
                      Add(PeriodType.Minute, 1); //series 2 secondary for SPY
                      Add("DIA", PeriodType.Minute, 1); //series 3 secondary for DIA
                       
                      }
                       
                      protected override void OnBarUpdate()
                      {
                       
                      if ((BarsInProgress == 2) && //sma cross conditions here//)
                            {
                               EnterLong(200, "SPY");
                             }
                       
                      if ((BarsInProgress == 3) && //sma cross conditions here//)
                            {
                               EnterLong(200, "DIA");
                            }
                       
                       
                      if ((BarsInProgress == 0) && (Position.MarketPosition == MarketPosition.Flat))
                           {
                              SetStopLoss("SPY", CalculationMode.Percent, stoppercent, true);
                           }
                      if ((BarsInProgress == 1) && (Position.MarketPosition == MarketPosition.Flat))
                          {
                           SetStopLoss("DIA", CalculationMode.Percent, stoppercent, true);
                           }
                      }

                      Comment


                        #86
                        Would it be possible for you to post both the complete source for this basic script as well as the non multi series script.

                        Located in (MY)Documents\NinjaTrader 7\bin\Custom\Strategy
                        LanceNinjaTrader Customer Service

                        Comment


                          #87
                          Please see attached. Also a print screen of strategy analyzer. I choose SPY from instrument list for multi series script and choose the list header for single script.
                          Attached Files

                          Comment


                            #88
                            These scripts do match the previous snippet you submitted.

                            There are several possibly logical checks that would need to be evaluated to determine why there are no trades being triggered.

                            If you can provide me with a simplified script that you believe is executing incorrectly I would be happy to look into it.
                            LanceNinjaTrader Customer Service

                            Comment


                              #89
                              There is plenty of trades being triggered. I just sent you that print screen so you could see my settings. I thought you would be running it on your end. The net profit doesn't match between the two scripts but they should.

                              Comment


                                #90
                                I won't be able to debug this script for you for free. If you would like custom debugging or development please send mail to support[at]ninjatrader[dot]com or contact one of our consultants here: http://www.ninjatrader.com/partners....pt-Consultants

                                If you can provide a simplified script with minimal logical checks that has issues I'd be happy to take a look.
                                LanceNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                599 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                344 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                103 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                558 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                557 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X