Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Crossover thresholds

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

    Crossover thresholds

    I run into situations often where a very slight crossover occurs and then reverses. Is there a way to alter the Crossover in NinjaScript to recognize only crossovers that are a minimum of 1 tick size or other user defined decimal setting? (Example: 0.01 in GBP/JPY) If so, how do you avoid causing a problem with the lookback setting?
    i.e. if bar [1] creates a slight crossover from bar [2] that is smaller than threshold and ignored, but then bar [0] confirms the cross with an increase in crossover. How can I maintain the cross in this case?
    thanks.

    #2
    billr,

    The only way to change this is to look for a cross over at a different value. If you were originally looking for SMA to cross close, instead of having it cross close, have it look to cross close + 1 tick.

    Code:
    if (CrossAbove(SMA(10), Close[0] + 1 * TickSize, 1))
         // Do something;
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,
      I was thinking of that logic (applied to SMA vs. SMA instead of SMA vs. Close) but I am still not versed in NinjaScript and didn't know what the, correct syntax would be for "(CrossAbove(SMA(10), SMA(20) + 1 * TickSize,1))".

      Thanks.
      Last edited by billr; 08-03-2010, 03:50 PM.

      Comment


        #4
        billr, there are two ways to use CrossAbove(). The first compares a data series to a data series and the second compares a data series to a double value. Since you are adding something to a data series, it is no longer a data series, so you will have to use the second method.

        You can get the most recent double value of a data series by adding [0] to the end, so please try this code and let me know if it does the trick:
        Code:
        if (CrossAbove(SMA(10), SMA(20)[0] + TickSize, 1));
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thanks Austin, this should do it.

          Comment


            #6
            Well, I am getting some unexpected results. Does using the comparison of a double value negate the look back part of the cross over logic? It seems to be triggering where no crossovers exist.

            For instance, I assume the crossover compares the value of SMA(10)[0] to SMA(20)[0] and then "looks back" to SMA(10)[1] compared to SMA(20)[1] to define the crossover. When inserting the double value method, it seems to be losing the comparison of the past bar or some other logic that allows triggers without an actual cross.

            Here is the syntax I used for both CrossAbove and CrossBelow:

            if (CrossAbove(DEMA (DEMA1), DEMA (DEMA2)[0] + TickSize, 1))
            //do something
            if (CrossBelow(DEMA (DEMA1), DEMA (DEMA2)[0] - TickSize, 1))
            //do something

            Comment


              #7
              Bill, it should not negate the lookback part of the logic. I am not sure why you are experiencing these results. You could always create your own data series that is adjusted by the appropriate number of ticks, and then compare the main DEMA to your adjusted DEMA data series.
              AustinNinjaTrader Customer Service

              Comment


                #8
                Isn't that what is in effect happening with the SMA(20)[0] + TickSize ?

                Comment


                  #9
                  Is there something about using the double value that changes the frequency or type of intrabar strategy updates?

                  Comment


                    #10
                    billr, no the SMA 20 snippet would be refering to a single double value and no series. I'm not sure I follow you last posted question: either the OnBarUpdate() are done at bar close (true setting) or on each incoming tick (false setting).

                    Comment


                      #11
                      Frankly, I'm not sure I understand my own question either! Up too late perhaps.

                      Thanks for your help. I need to read up on the data series topic before I can respond on that point.

                      Regarding the use of the double value vs. series, I still don't understand why I could be getting these non-crossover signals unless using the double value somehow alters the lookback comparison function?? I will do some much needed self educating so I can ask more coherent questions. Thanks.

                      Comment


                        #12
                        Bill, I tested this out myself briefly, and ran into some unexpected behavior, like a crossover happening two bars in a row. I'm going to lunch now, but I will continue testing this when I get back.
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          Yes, that is what I was getting. Thanks for looking into it.

                          Comment


                            #14
                            Bill, for now while we look at this, please create another data series that contains your "adjusted" SMA data and then reference that new data series. The reference sample for working with data series can be found here. The code would look something like this:
                            Code:
                            // in variables section
                            private DataSeries adjSMA;
                            
                            Initialize()
                            {
                               adjSMA = new DataSeries(this);
                            }
                            OnBarUpdate()
                            {
                               adjSMA.Set(SMA(SMA_Slow)[0] +/- TickSize);
                            
                               if (CrossAbove(SMA(SMA_Fast), adjSMA, 1))
                                  // do crossabove stuff, like EnterLong()
                            }
                            AustinNinjaTrader Customer Service

                            Comment


                              #15
                              Austin,
                              did you ever get a chance to find out what the problem was with using:
                              if (CrossAbove(SMA(10), SMA(20)[0] + TickSize, 1));
                              for requiring a crossover to be of a certain minimum amount?
                              thanks.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              630 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              566 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X