Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Max Down Day

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

    #31
    How many instruments and series are you testing with? For setting the core framework which you want to work in, I would use the minimum set to make debugging and correlating easier.

    The code checking for enough bars on all series should be at your OnBarUpdate() start.

    Have you tried printing how many bars are actually processed then for the combined test and have compared the actual trades you see?

    The difference could be also due to simply processing fewer trades / bars, as one series would be for example available only a few bars later - NT would then call OnBarUpdate only after all series had met their BarsRequired, so would be important to compare the trades you get on a limited set of symbols / series to better understand.

    Comment


      #32
      For some reason it wasn't working before but I tried adding the UniqueEntries code again and it's matching up against the single instrument script now...
      This loop setup is going to save an enormous amount of work and code.

      I just had one last thing I wanted to try to automate. You gave this script below for creating additional price series. I added in the additional "Add" for 1min.

      NinjaTrader.Cbi.InstrumentList list1 = NinjaTrader.Cbi.InstrumentList.GetObject("Stock-List");

      foreach (Instrument i in list1.Instruments)
      {
      Add(i.FullName, PeriodType.Minute, 5);
      Add(i.FullName, PeriodType.Minute, 1);
      }


      If I have a primary of 5min and a secondary of 1min for 3 instruments setup in the following order below. Can I use your script above to achieve this sequence of Add's? I added it into my script but the results do not appear as if its working correct. Basically I would need it to add all the 5min series for all instruments from my stock list and then add all the 1min afterward.

      // default series 0 primary for SPY
      Add("DIA", PeriodType.Minute, 5); //series 1 primary for DIA
      Add("APA", PeriodType.Minute, 5); //series 2 primary for MSFT
      Add(PeriodType.Minute, 1); //series 3 secondary for SPY
      Add("DIA", PeriodType.Minute, 1); //series 4 secondary for DIA
      Add("APA", PeriodType.Minute, 1); //series 5 secondary for MSFT
      Last edited by zachj; 06-30-2013, 07:18 PM.

      Comment


        #33
        zachj, unfortunately creating a sequence like this with the undocumented snippet would not be possible to my knowledge - but glad to hear it's matching up better now.

        Comment


          #34
          One more question on this, if I have all those instruments running through the for loop on the entry, how does this stoploss work below. Is it only setting a stoploss for series 0 on the first instrument? Or will it set a stop loss for every instrument?

          for (int series = 0; series < 3; series++)
          if ((BarsInProgress == series) && (Position.MarketPosition == MarketPosition.Flat))
          {
          SetStopLoss(CalculationMode.Percent, stoppercent);
          }


          Instead to make it process all the instruments would this be fairly equivalent to the stop above...
          for (int series = 0; series < 3; series++)
          if (Closes[series][0] < Position.AvgPrice - Position.AvgPrice x stoppercent)
          {ExitLong();}

          Or will Position.AvgPrice not distinguish between the different insturments.
          Last edited by zachj; 07-01-2013, 11:49 AM.

          Comment


            #35
            You would see a StopLoss for every instrument submitted, if you're doing a static one I would though leave the call in Initialize().

            For a MultiSeries suitable Positon property, please see Positions -

            Comment


              #36
              Everything seems to be matching up with the Net Profit between running the single script on multiple instruments and running the multi-instrument script using the same instruments except for this part of the code below. Why when I add this in does the Net profit not match up? I can't figure it out. I added in the Positions[] to the multiscript but it didn't change anything. And I have UniqueEntries in the multi-instrument.

              Single script..
              Code:
              if ((BarsInProgress == 1) && Position.MarketPosition == MarketPosition.Long && ToTime(Time[0]) > 94500 
              && (SMA(BarsArray[0],Fast)[1] < SMA(BarsArray[0],Slow)[1] && SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2] && Closes[1][0] < Lows[0][1] - exitdistance)
              {
              SetStopLoss(CalculationMode.Ticks, 1);
              }
              Multi-Instrument script..
              Code:
              for (int series = 0; series < 3; series++)
              if ((BarsInProgress == series + 3) && Positions[series].MarketPosition == MarketPosition.Long && ToTime(Time[0]) > 94500 
              && (SMA(BarsArray[series],Fast)[1] < SMA(BarsArray[series],Slow)[1] && SMA(BarsArray[series],Fast)[2] > SMA(BarsArray[series],Slow)[2] && Closes[series + 3][0] < Lows[series][1] - exitdistance) 
              {
              SetStopLoss(CalculationMode.Ticks, 1);
              }
              Last edited by zachj; 07-02-2013, 07:27 PM.

              Comment


                #37
                Are the series assignments you have hitting home then? I would also include a print to being able to compare exactly when the command triggered.

                Comment


                  #38
                  Not sure what you mean hitting home? Will the SetStopLoss not acknowledge the UniqueEntries? I have it in the Initialize() section. I noticed when I change the order of the 3 instruments I'm testing in the ADD section, it changes the net profit. So that seems to suggest the UniqueEntries is not working for SetStopLoss. Is there any way around this?

                  Comment


                    #39
                    I was referring to your use of series and series + 3 and if you were sure that hereby the correct series are used, comparable to what you would do in the single script you mentioned. SetStopLoss would work with .UniqueEntries, per default with PeEntryExecution used you should see a stop order then for each execution.

                    Comment


                      #40
                      Oh ya I assume the correct series must be used because when I run it the net profit comes out the same for both scripts. It's just when I add in the code I posted in the below reply that things get off track. Something with the SetStopLoss is throwing it off. If I use ExitLong instead of stoploss the scripts match up but then it throws the net profit for each into negative territtory.

                      Is there a way I can do the same exact thing as the code in previous post but with using ExitLong instead? Or some other work around.

                      Comment


                        #41
                        ExitLong would just be a market order, if you want to mimic SetStopLoss with the Exit methods offering a BIP input, then I would go with a ExitLongStop here -



                        For the price you could set it then to an offset of the Positions.AvgPrice

                        Comment


                          #42
                          So if i have stopPrice = Position.AvgPrice -TickSize; which I put underneath EnterLong();

                          Would SetStopLoss(CalculationMode.Ticks, 1); be equal to ExitLong(stopPrice); ?


                          I just put it in the Single Script like this below, coming out to a different net profit though..
                          Code:
                           
                          ((BarsInProgress == 1) 
                          && Position.MarketPosition == MarketPosition.Long && ToTime(Time[0]) > 94500 
                          && (SMA(BarsArray[0],Fast)[1] < SMA(BarsArray[0],Slow)[1] && SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2] && Closes[1][0] < Lows[0][1] - exitdistance)
                          {
                          ExitLongStop(stopPrice); 
                          }

                          Something I'm noticing though, when using ExitLong or ExitLongStop and I change the BIP from 1 to 0, it doesn't seem to be recognizing it, no change in net is taking place. But with StopLoss it does change.
                          I tried using ExitLongStop(1,false, 200, stopPrice, "", "");
                          Tried stopPrice = Positions[1].AvgPrice -TickSize;
                          Last edited by zachj; 07-03-2013, 12:47 PM.

                          Comment


                            #43
                            Hello zachj,

                            Thank you for your post.

                            SetStopLoss(CalculationMode.Ticks, 1) and ExitLong(stopPrice) should be the same.

                            Have you tried Positions[x] yet?
                            Code:
                            ((BarsInProgress == 1) 
                            &&[B] Positions[1].MarketPosition [/B]== MarketPosition.Long && ToTime(Time[0]) > 94500 
                            && (SMA(BarsArray[0],Fast)[1] < SMA(BarsArray[0],Slow)[1] && SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2] && Closes[1][0] < Lows[0][1] - exitdistance)
                            Are you intending to access the main bar series (bip = 0) of rthe SMAs? I ask this because you are using BarsArray[0] which would be the instrument you apply the strategy to in the UI.

                            Comment


                              #44
                              You meant ExitLongStop correct? Yes intending to use the main bar series for SMA's. I tried Positions[x] and it does not change anything at all.

                              Comment


                                #45
                                Maybe something else in the script is interacting with it and making the difference but I don't think so. Will this work, I have attached the cs file for the SetStopLoss and one for the ExitLongStop strategy. And an image of the strategy analyzer settings. I'm using 3 instruments, DIA, SPY, APA just for testing purposes. For SetStopLoss you will see there is a combined net of $5472 and for ExitLongStop a net of $3372 for the period tested. But if SetStopLoss() and ExitLongStop(stopPrice) are equivalent they should be the same as you say?

                                stopPrice method or definition is just below EnterLong().


                                thanks
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                580 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                335 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                102 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                554 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                552 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X