Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT marks crossovvers when its too tight incorrectly

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

    NT marks crossovvers when its too tight incorrectly

    I have noticed that when the moving averages are too tight, NT marks the crossovers even though the lines show that they dont cross. i dont know the algorithem you use for crossovers but the data that i pulled to check dont match up. the only reason that i could identify this is because i use both ninjatrader and amibroker to plot the crossover. amibroker plots it accurately but ninjatrader reports tight moves as crossovers if i used the crossabove or crossbelow formula.
    attached is also the code segment that i use. when i check the printed data. you can clearly see there is no crossover. the printed data is eur.jpy which shows upto 5 decimal places. you will notice that the 9 ema was lower for the last bar and the bar previous to it. so how can there be a crossover? its also confirmed by the lines in the chart that there is no crossover!!!

    2016-02-02 12:15:01 AMEURJPYEURJPYCcrossed above
    2016-02-02 12:15:01 AM EURJPYDirectionLong
    last EMA 22 131.64439 lastprev EMA 22 131.64439
    last EMA 9 131.64240 lastprev EMA 9 131.64240
    last 9 ema lower than last 22 emaTrue current9emahigherFalse
    2016-02-02 12:20:00 AM****WARNING **** IT WAS NOT A CLEAN CROSSOVER

    Code:
     Value.Reset();
                        if (CrossAbove(EMA(9), EMA(22), 1) && IsFirstTickOfBar)
                        {
                            Draw.Text(this, "crossabove" + CurrentBar, "look for long", 1, Low[1]);
                            look4long = true;
                            look4short = false;
    					
    						
                            
    						Print(now.ToString() + " "  + Bars.Instrument.FullName +  "Direction" + "Long");
    						Print(string.Format("last EMA 22 {0:0.00000}  lastprev EMA 22 {0:0.00000} ",EMA(22)[1],EMA(22)[2]));
    						Print(string.Format("last EMA 9   {0:0.00000}  lastprev EMA   9 {0:0.00000} ",EMA(9)[1],EMA(9)[2]));
    						
    							bool last9emalower=EMA(9)[2]<EMA(22)[2]?true:false;
    						bool current9emahigher=EMA(9)[1]>EMA(22)[1]?true:false;
    						Print("last 9 ema lower than last 22 ema" +last9emalower.ToString() + " "  + "current9emahigher" + current9emahigher);
    						
    						
                            if(!(EMA(9)[1]>EMA(22)[1] && EMA(9)[2]<EMA(22)[2])){
    							Print(Time[0].ToString() + "****WARNING **** IT WAS NOT A CLEAN CROSSOVER");
    						}
    						
    
                        }
                        else
    for eg.

    #2
    ignore the sample data. i originally was logging it incorrectly. based on the revised samples, it looks like the crossabove will return true in the following sample. The indicator code seems to look at the decimals that matches the tick resolution ie it chops off the all the trailing decimals past 2 digits for EURJPY.
    EMA(9)[2]<EMA(22)[1) && EMA(9)[2]=EMA(22)[1)

    The only issue here is that the EMA(9) is yet to post above EMA(22) but the crossabove returns true. Mind you, i am checking for crossover only at the end of the bar using firsttickofbar.

    Can you validate if my findings are right. if it is, i will call it a defect as you cannot return crossabove until the moving average moves above the comparive average

    Comment


      #3
      Hello junkone,

      Thanks for your posts.

      I am confused and would ask that you clarify what it is that you would like us to check. The code sample shown in your post: EMA(9)[2]<EMA(22)[1) && EMA(9)[2]=EMA(22)[1) contains typos so please review if this is indeed what you want tested.

      My guess here is that you are testing this in an indicator and in the OnBarUpdate() method, is that correct?

      Are you testing with Calculate OnEachBar or OnPriceChange or OnEachTick?
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        I had to cleanup my code yesterday. the issue still remains as it is.
        Calculate = Calculate.OnEachTick;


        if(!(EMA(9)[1]>EMA(22)[1] && EMA(9)[2]<EMA(22)[2])){
        Print(Time[0].ToString() + "****WARNING **** IT WAS NOT A CLEAN CROSSOVER");
        }
        and
        if(!(EMA(9)[1]<EMA(22)[1] && EMA(9)[2]>EMA(22)[2])){
        Print(Time[0].ToString() + "****WARNING **** IT WAS NOT A CLEAN CROSSOVER");
        }

        Comment


          #5
          Hello junkone,

          Thanks for your reply.

          I changed your code and would ask that you test with this:

          Code:
          if (IsFirstTickOfBar)
          			{
          				if((EMA(9)[0]>EMA(22)[0] && EMA(9)[1]<EMA(22)[1]))
          				{
          					Draw.Dot(this, "test1"+CurrentBar, true, 0, EMA(9)[0], Brushes.Yellow);
          				}
          			
          				if((EMA(9)[0]<EMA(22)[0] && EMA(9)[1]>EMA(22)[1]))
          				{
          					Draw.Dot(this, "test2"+CurrentBar, true, 0, EMA(9)[0], Brushes.Blue);
          				}
          			}
          I find it easier to visualize on the chart with dots representing where the condition is true. One thing to keep in mind is that moving average lines are made up of data points that are connected via straight lines between two consecutive points and while visually you may see one thing, in reality the evaluation is of the actual data points and not the interpreted straight line between points.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            here is a code that double checks the crossabove and crossbelow and flags it if it does not really go from below to above. in the screenshot you will see a diamond posted at teh end which is realtime screnshot,

            Code:
             if (CrossAbove(EMA(9), EMA(22), 1) && IsFirstTickOfBar)
                                {
            						bool customcrossabove=(EMA(9)[1]>EMA(22)[1] && EMA(9)[2]<EMA(22)[2]);
            						
            						if(!customcrossabove)
            						{
            							Draw.Diamond(this, "test1"+CurrentBar, true, 0, EMA(9)[1], Brushes.Red);
            						}
            						
            }
            Code:
            if (CrossBelow(EMA(9), EMA(22), 1) && IsFirstTickOfBar)
                                    {
            							
            							//
            							bool customcrossbelow=(EMA(9)[1]<EMA(22)[1] && EMA(9)[2]>EMA(22)[2]);
            			
            				 
            				if(!customcrossbelow   )
            				{
            					 
            						Draw.Diamond(this, "test1"+CurrentBar, true, 0, EMA(9)[1], Brushes.Pink);
            					 
            					
            				}

            Comment


              #7
              see how can it do crossabove 2 bars in a row. this makes no sense. see 2 diamonds in a row
              same code as below

              Comment


                #8
                Hello junkone,

                Thanks for your reply.

                You may want to change the calculate mode on the moving averages so that they are the same as one is clearly 1 bar behind the other.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Look at panel 2 where the diamond is plotted. my settings is @ every tick
                  my code is part of panel 2 and not panel 1 so the moving average trailing behind in panel 1 should not count.


                  i can duplicate this issue daily. infact, i am going to replacce the builtin crossabove and crossbelow with my code as the crossabove and crossbelow do not calculate it @ end of the bar even though i am using firstick and (CrossAbove(EMA(9), EMA(22), 1) which should not calculate intrabar and only at the end of the bar.
                  if you dont want to fix it, its your own prerogative
                  if you want to duplicate it, just use the following code and you can easily duplicate it for eurusd or any primary forex crosses during the 3 am to 11 am EST
                  if (CrossAbove(EMA(9), EMA(22), 1) && IsFirstTickOfBar)
                  {
                  bool customcrossabove=(EMA(9)[1]>EMA(22)[1] && EMA(9)[2]<EMA(22)[2]);

                  if(!customcrossabove)
                  {
                  Draw.Diamond(this, "test1"+CurrentBar, true, 0, EMA(9)[1], Brushes.Red);
                  }

                  }


                  Originally posted by NinjaTrader_Paul View Post
                  Hello junkone,

                  Thanks for your reply.

                  You may want to change the calculate mode on the moving averages so that they are the same as one is clearly 1 bar behind the other.

                  Comment


                    #10
                    Hello junkone,

                    Thanks for your reply.

                    if you change your code from:

                    (EMA(9)[1]>EMA(22)[1] && EMA(9)[2]<EMA(22)[2])

                    to:

                    (EMA(9)[0]>EMA(22)[0] && EMA(9)[1]<EMA(22)[1])

                    You will no longer see the Diamonds as you will be evaluating the same conditions as the crossabove. The IsFirstTickOfBar being true means you are on the currently forming bar and the references of [1] would be the previous bar and [2] would be the bar before that whilst the CrossAbove evaluates the current bar[0] to [1].
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      i want to evaluate crossabove or crossbelow only on a completed bar. so i was told to use this
                      if (CrossAbove(EMA(9), EMA(22), 1) && IsFirstTickOfBar)

                      Here is the timeline

                      Bar(2) Bar(1) Bar(0=currentbar)

                      I want to find out if Bar(1) did a crossover at the close of the bar.
                      So i check @FirstTickBar(Bar0) if i had a crossover at end of the last bar.


                      It is my firm belief that if i use

                      if (CrossAbove(EMA(9), EMA(22), 1) && IsFirstTickOfBar) it will evaluate when Bar(0) has crossed over and only once.

                      is that right?

                      Comment


                        #12
                        Hello junkone,

                        Thanks for your reply.

                        The bool (IsFirstTickOfBar) is only true once per bar, on the first tick of the bar[0] (when using Calculate.OneachTick or Calculate.OnPriceChange) so yes the conditional statement, "if (CrossAbove(EMA(9), EMA(22), 1) && IsFirstTickOfBar)
                        " would then only execute once per bar.
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          this is where i feel that if i spoke to someone, we could have resolved the matter in 1 minute instead of 12 ping pongs.
                          i want to check for crossovers at the end of the completed bar. my custom code does it now. so my solution satisfies my requirement.
                          However . if i were to use the built in crossover code, CrossAbove(EMA(9), EMA(22), 1), i find that it checks for Bar[0] crossover and not if the crossover occured in Bar[1]

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by zstheorist, Today, 07:52 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post zstheorist  
                          Started by pmachiraju, 11-01-2023, 04:46 AM
                          8 responses
                          149 views
                          0 likes
                          Last Post rehmans
                          by rehmans
                           
                          Started by mattbsea, Today, 05:44 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post mattbsea  
                          Started by RideMe, 04-07-2024, 04:54 PM
                          6 responses
                          33 views
                          0 likes
                          Last Post RideMe
                          by RideMe
                           
                          Started by tkaboris, Today, 05:13 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post tkaboris  
                          Working...
                          X