Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop execution if less than supertrend line

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

    #16
    Ok just as I was suspecting, its basing all the conditions off the secondary or 1minute bars, so its executing buy orders off the secondary instead of just the exit orders as intended. How do I get this to just bring the secondary bars into play only on the exit orders, or in other words how do i localize it to just a part of the code that executes the exit? Its spreading to the whole strategy code.

    Comment


      #17
      zachj, will need to work with BarsInProgress to filter updates, as OnBarUpdate() will be called for all series.

      If you wanted to exclude processing on all series except for the primary, you can use the following:
      if (BarsInProgress != 0) return;

      You may also want to take a look at this sample here for help entering on one time frame and exiting another.
      Ryan M.NinjaTrader Customer Service

      Comment


        #18
        In the sample code you provided..
        /* OnBarUpdate() method will execute this portion of the code when incoming ticks are on the
        primary bar object. */
        if (BarsInProgress == 1)

        should that say secondary bar object? BarsInProgress would == 0 if it was primary wouldn't it?

        Comment


          #19
          Thanks, Zach. Good spot - our documentation team is looking into now.
          Ryan M.NinjaTrader Customer Service

          Comment


            #20
            ok so I have..

            Code:
             
            // Condition set 4 Long Exit. If price Closes below supertrend for previous bar, exit long.
            if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired) return;
            if (BarsInProgress != 0) return;
            if (SuperTrend(BarsArray[0], 14, 2.618, true).UpTrend[1] > Closes[1][0]
            && ToTime(Time[0]) > ToTime(timestart, 0, 0)
            && ToTime(Time[0]) < ToTime(timeend, 0, 0))
            { ExitLong("", ""); }
            But its still entering trades based on the secondary bar object. Do I have to go up to the entry code and also put in a BarsInProgress in that section?

            Comment


              #21
              It could still submit to second BIP if it checks this before your BIP filter. You don't need two of those statements, but in general anytime you are "returning" out after checking conditions, these types of statements should be at the very top of OnBarUpdate(). You could combine all yours into this one:

              if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || BarsInProgress != 0) return;
              Ryan M.NinjaTrader Customer Service

              Comment


                #22
                I figured those were doing the same thing. I put another BIP in the Entry section and that seems to make it use the primary bar object for the entry, but its still not exiting based on the secondary, its exiting based on the primary.

                Code:
                 
                // Condition set 4 Long Exit. If price Closes below supertrend for previous bar, exit long.
                if (BarsInProgress != 0) return;
                if (SuperTrend(BarsArray[0], 14, 2.618, true).UpTrend[1] > Closes[1][0]
                && ToTime(Time[0]) > ToTime(timestart, 0, 0)
                && ToTime(Time[0]) < ToTime(timeend, 0, 0))
                { ExitLong("", ""); }
                in the code above code do I have it correct for exiting when the Supertrend of the primary bar object(SuperTrend(BarsArray[0], 14, 2.618, true).UpTrend[1]) is greater than the close of the secondary bar object(Closes[1][0])?

                Comment


                  #23
                  Yes, the code matches your description, but it may not work the way you expect. To understand bar referencing model for multiseries scripts, it's good to print time stamps of all series, so you can see exactly what bar and values are used in your comparisons.

                  For help using Print statements and TraceOrders output to debug, please see the following link:
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #24
                    I can see the same thing from looking at a chart in the strategy analyzer when doing a backtest, I can visually see the buy and exit points. Isn't the print statements showing me the same thing? I would rather see it visually on the chart if possible.

                    Comment


                      #25
                      A chart would not show the same things you can see with Print statements. You're not able to see at all the TimeStamp comparisons that are needed to debug this strategy.

                      The bar referencing model for multiseries script (how bar data is referenced) is detailed in the link below, and you could use the print statement example as well for some insight on how it works in your strategy.


                      if (BarsInProgress == 0)
                      Print("Primary series time: " + Times[0][0] + " Secondary Series Time: " + Times[1][0]);
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #26
                        Is there any place in the helpguide that instructs how to read and analyze these print statements. I can't find anything real specific. And I posted your code in the initialize section of my strategy file and getting error in the output window...Failed to call method initialize....

                        Do I put your code in exactly as you wrote it or do I need to change something in there first?

                        Comment


                          #27
                          Yes, we have this post to help with debugging and using print statements:


                          The print statement I included as an example belongs in OnBarUpdate() since you're accessing bar properties. (timestamps).
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #28
                            That was the first thing i tried, putting it in OBU, nothing showed in output window?

                            Comment


                              #29
                              I'm happy to take a look if you can post the latest strategy file you're working from. Post either the .cs from docs\Nt7\bin\custom\indicator, or export and attach zip using File > Utilities > Export NinjaScript.
                              Last edited by NinjaTrader_RyanM1; 02-07-2012, 11:32 AM.
                              Ryan M.NinjaTrader Customer Service

                              Comment


                                #30
                                attached the .cs file. Do you have to have the file open for it to print to the output window or how does it know which file to pull from. I guess it must just pull from whichever file has a print statement in it.
                                Attached Files
                                Last edited by zachj; 02-07-2012, 01:54 PM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                656 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                371 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                579 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X