• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading the trend

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

    Trading the trend

    The channel regression offers an immediate idea of the trend. For this reason I'm planning to get an entry alert whenever the regression channel shows the same direction in three different timeframes
    How can I implement this with Ninja?
    Is it correct that the code

    if (RegressionChannel(35, 2).Middle[5]*1.1 < RegressionChannel(35, 2).Middle[0]
    && RegressionChannel(35, 2).Middle[60]*1.1 < RegressionChannel(35, 2).Middle[0]

    identifies a situation where the regression channel is rising both in the 5-minute and in the 60-minute timeframes (if the midline is greater now than 5 and 60 bars ago), and that the 1.1 multiplier can be a measure of the channel slope ?
    I'd also like to know how to signalize the crossing of the price above the upper channel and below the lower one.
    Thank you in advance

    #2
    Hello fliesen,

    Thank you for your post.

    For the Regression Channels you will need to familiarize yourself with multiple time frames and instruments in NinjaScript, you can find this information at the following link: http://www.ninjatrader.com/support/h...nstruments.htm

    For the crossing conditions you have CrossAbove() and CrossBelow(), you can find these methods and their information at the following links:
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Trading the trend

      I already have a couple of working strategies with multiple timeframes. I tried to extend these strategy to the Regression Channel, but I get some strange errors.
      Can you please tell me where I'm wrong ?
      The errors lay just in the last two condition sets (# 9 and 10, lines 183-200) and in the initialization (lines 59-61): the rest of the code is 100% ok.
      The algorytm of the lines 183-200 means to check if the Regression Midchannel is positive (or negative) in three different timeframes, in this case 1, 15 and 30 minutes.
      The other question is which condition identifies a rising or a dropping Regression Channel.
      Thanks in advance
      Mauro
      Attached Files
      Last edited by fliesen; 02-17-2014, 05:57 PM.

      Comment


        #4
        Hello fliesen,

        Thank you for your response.

        Once I correct the Initialize() method's calls to the RegressionChannel() method under Add() I see no errors. Please change your Initialize() method's section for the RegressionChannel() to the following:
        Code:
        			Add (RegressionChannel(35, 2));
        			Add (RegressionChannel(35, 2));
        			Add (RegressionChannel(35, 2));
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Perfect, thank you.
          Now I have a problem for a further condition set:
          for checking if current price is cheaper than the Regr.Channel lower line or higher than the Regr. Channel upper line, must I add/initialize two more RegressionChannel(35, 2)) calls multiplied by three timeframes (then 6 calls as a whole), or are the three ones that you corrected enough ?
          (For this check I can't use the crossabove/crossbelow function, since it's practically impossible that a crossover simultaneously occurs in all three timeframes).

          Comment


            #6
            Hello fliesen,

            Actually, there is no need to set any indicators in the Initialize() method if you only plan to call them in your conditions. Indicator methods can be called at any time to pull the value of an indicator without needing to Add() the indicator to the script. So the answer here is none.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Trading The Trend

              Thanks.
              I have just run the new code: the strategy compiles with NO ERROR, however there is surely something wrong with it.
              I'm attaching a reduced version of the alert strategy, limited to the scripts with possible problems (whenever the conditions are triggered, i.e. when there is the same trend in 3 different timeframes, the alert window displays a blue row, then 2 other rows for my control of the different values as to the Regression Channel's Lower and Upper lines now and 30 bars ago in the 3 timeframes):

              • first of all, when I check / enable the related box in Control Center -> Strategies, for most instruments the check disappears immediately and the strategy can't be enabled. This problem disappears when I delete the line 88, or when I avoid to display the RegressionChannel(BarsArray[3],35, 2).Upper[30]: why ?
              • once avoided this and enabled the strategy, I get only negative alerts ("RegrCh-") and absolutely NO positive one ("RegrCh+") although I even reduced the conditions of the latter in order to make the triggering much easier. This discrepancy is too strange to be correct;
              • also, the negative alerts are many more than expected;
              • this is probably because the alert window shows values of the RegressionChannel that sometimes - not always - are wrong (as for istance the RegressionChannel(BarsArray[2],35, 2).Lower[30]). Therefore, the whole strategy can't be reliable;
              • in any case, the alerts seem to appear just for a few of the enabled symbols;
              • conditions # 11 and # 12, checking for prices movements above or below in all three timeframes, never occur. This could be also strange.


              What is causing the isssue(s) ?
              Attached Files
              Last edited by fliesen; 02-19-2014, 07:03 AM.

              Comment


                #8
                Hello fliesen,

                What instruments do you run this strategy on?
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  I have a limited default list of currency pairs (the ones versus EUR), main index futures (/ES, /NQ, /YM), two commodities (/CL and /GC) and a few stocks (AAPL, AMZN, GOOG, IBM): from Control Center -> Strategies, I enable this strategy to them all, when looking for entry points.

                  Comment


                    #10
                    Hello fliesen,

                    Thank you for your response.
                    Originally posted by fliesen View Post
                    • first of all, when I check / enable the related box in Control Center -> Strategies, for most instruments the check disappears immediately and the strategy can't be enabled. This problem disappears when I delete the line 88, or when I avoid to display the RegressionChannel(BarsArray[3],35, 2).Upper[30]: why ?
                    Are you referring to the following line in the code?
                    Code:
                    Alert("MyAlert491", Priority.High, "RegrCheck  "+RegressionChannel(BarsArray[1],35, 2).Upper[30]+"   "+RegressionChannel(BarsArray[2],35, 2).Upper[30]+"   "+RegressionChannel(BarsArray[3],35, 2).Upper[30], @"C:\Programmi\NinjaTrader 7\sounds\Alert4.wav", 59, Color.White, Color.Blue);
                    For the no positive alerts, this is due to what we are checking. If we check the RegressionChannel() 30 bars ago we will not be checking the same lines that you see on the current bar, even though the current bar may show that the line is going up the RegressionChannel() value for upper or lower may be higher or lower 30 bars ago. I recommend printing these values to see what I am detailing here:
                    Code:
                                // Condition set 9
                    			Print("RegCh 30: " + RegressionChannel(BarsArray[1],35, 2).Upper[30]);
                    			Print("RegCh 0: " + RegressionChannel(BarsArray[1],35, 2).Upper[0]);
                    And finally Conditions 11 and 12 will never occur as the Close[0] will never be less than the RegressionChannel's current Lower or higher than it's Upper.
                    Patrick H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you.
                      1. Yes, I'm referring to that line. However, I noticed that only the RegressionChannel(BarsArray[3],35, 2).Upper[30] is responsable for the unchecking and the block of the strategy, while the first 2 ones (with BarsArray[1] and BarsArray[2]) may remain in the code without any disabling effect. This means to me that the one with BarsArray[3] has some initializing problem or similar;
                      2. during the day I could see some occurences of the positive alerts, therefore we may forget this point;
                      3. and I got alerts for conditions 11 and 12 either (why should higher bar closes than the upper channel, or lower than the lower channel not be possible ? These are exactly the moments when chances of a reversal are greater, please see the present attachment).

                      When tomorrow the markets reopen, I will check the suggested prints with pleasure, since the crucial point remains how correct are the channel values to compare. With regard to this: is it ok that the channel in my attachment is plotted by all values of the RegressionChannel(BarsArray[2],35, 2).Lower[N] till RegressionChannel(BarsArray[2],35, 2).Lower[0], where the former is the lower line N bars ago, the latter the current lower line, and the BarsArray[2] is the 15-minute timeframe; this eventually, but not necessarily repeated for the Middle and the Upper channel lines, as well as for the 3-minute BarsArray[1] and the 60-minute BarsArray[3] timeframe as a confirmation ? And is it correct that the trend is dropping when a current lower (or middle or upper) line value is lower than N bars ago, i.e when RegressionChannel(BarsArray[1],35, 2).Lower[N] < RegressionChannel(BarsArray[1],35, 2).Lower[0], and rising in the opposite case ?
                      If I'm wrong here, it's a nonsense to go forth.
                      I also need to understand why the strategy can't be enabled when codifying RegressionChannel(BarsArray[3],35, 2).Upper[30], since right now I'm prevented from enabling and testing the script.
                      Thank you
                      Attached Files
                      Last edited by fliesen; 02-19-2014, 06:58 PM.

                      Comment


                        #12
                        Hello MuFr,

                        Thank you for your response.

                        Please go to the NinjaTrader Control Center's Log tab and advise if you see the following error after you attempt to enable the strategy with line 88 included:
                        Error on calling 'OnBarUpdate' method for strategy 'MuFr/fa3f92822c1b42719030a17514127f28': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                        And finally, you are correct the current Close can be above the Upper or below the Lower of the RegressionChannel. I was looking at an isolated instance of the RegressionChannel on my end.
                        Patrick H.NinjaTrader Customer Service

                        Comment


                          #13
                          Yes, I found it and corrected the code. Now everything is fine (sofar).
                          Thank you very much.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by ArmKnuckle, Today, 01:59 AM
                          1 response
                          15 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by seppyr, Today, 01:53 AM
                          1 response
                          17 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by matthewbartlett, Today, 01:22 AM
                          1 response
                          8 views
                          0 likes
                          Last Post Emma1
                          by Emma1
                           
                          Started by ct_fx, Today, 05:14 AM
                          0 responses
                          12 views
                          0 likes
                          Last Post ct_fx
                          by ct_fx
                           
                          Started by Beauregard, Today, 04:36 AM
                          0 responses
                          9 views
                          0 likes
                          Last Post Beauregard  
                          Working...
                          X