Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Setup indicator

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

    Setup indicator

    Hi guys, I'm developing a new indicator, it's an average HILO crossover crossover, when the retr occours (on the lower avg) with close>previous bar then setup is confirmed. As you can see in the attached image, setup is marked with a "lime" bar, but it's wrong. I did many tests, but nothing to do. May someone help me coding better this indicator?

    Attached Files

    #2
    imported post

    To debug, have you tried sending data to the Output Window (Print) and traced the following information:

    CurrentBar
    BarTime
    Data points used to trigger the condition

    This is what I do to give me an idea what the conditions are when the bar is changing to lime.

    Is this chart you provided real-time or historical? Meaning, does the indicator behave correctly on historical data but the error only shows up in real time?

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Thank Ray, I'm trying nt6beta (demo) with globalfutures, realtime eminis (the same occours with historical data). Sorry for the past message, I forgot to attach the code! attached datawindow image. Thanks

      Code:
       
       {
       #region Variables
       // Wizard generated variables
       private int leng = 89; // Default setting for Leng
       private DataSeries diff;
       private int brk = 0;
       private bool retr ;
        private bool retr2 ;
        private bool HiLo ; 
        private bool HiLo2 ; 
        #endregion
      
       /// <summary>
       /// This method is used to configure the strategy and is called once before any strategy method is called.
       /// </summary>
       protected override void Initialize()
       {
       CalculateOnBarClose = true;
       diff = new DataSeries(this);
           
        }
      
       /// <summary>
       /// Called on each bar update event (incoming tick)
       /// </summary>
       protected override void OnBarUpdate()
       {
       diff.Set (TickSize);
       // double diff = High[0] - Low[0];
         double MaCl = Low[0];
         double MaCl2 = High[0];
         double MaCl3 = Close[0];
         double MaHi = HMA(High,Leng)[0];
         double MaLo = HMA(Low,Leng)[0];
       double offset = HMA(diff, Leng)[0];
       double tlrnH = MaHi + offset;
         double tlrnHH = MaHi - offset;
       double tlrnL = MaLo - offset;
       double tlrnLL = MaLo + offset;
       
         
         if (CrossBelow(Close, MaLo, 1))
            HiLo = false;
            retr = false;
         
          if(HiLo == true ){
         if ((MaCl >= (tlrnL) && MaCl <= (tlrnLL)) && MaCl3 > MaLo)
           retr = true;
          else
            retr = false;
          //} 
           if (retr == true && (Close[1] <= Open[1] && Close[0] >= Open[0]))
             BarColor = Color.Lime;
          }
           if (CrossAbove(Close, MaHi,1))
          HiLo = true;
      Attached Files

      Comment


        #4
        imported post

        Mauro60,

        I can't easily tell why the lime bar is incorrect in your image? What condition is not true below:

        if (retr == true && (Close[1] <= Open[1] && Close[0] >= Open[0]))
        BarColor = Color.Lime;

        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          I hope you could understand what I'm meaning and what I would obtain. On the chart I reported conditions for setup.
          Attached Files

          Comment


            #6
            imported post

            Thanks. So looks like the "retr" variableisnot being set based on your expectations.

            What I suggest is adding a Print Statements such as:

            Print(Time[0].ToString() + " 1" + retr)

            Print(Time[0].ToString() + " 2" + retr)

            Print(Time[0].ToString() + " 3" + retr)

            Print(Time[0].ToString() + " Final" + retr)

            Place the first three at the exact spots where you set the "retr" variable and the last one at the very end of the OnBarUpdate() method. Then look in the OutPut window to determine why the "retr" is not set to false at the lime bar is incorrect.

            Ray
            RayNinjaTrader Customer Service

            Comment


              #7
              imported post

              Ok!

              Comment


                #8
                imported post

                The variable HiLo result always true instead result false, where is the mistake?

                23/01/2007 20.39.33 1 False -- True
                23/01/2007 20.39.33 2 True -- True
                23/01/2007 20.39.33 3 True -- True
                23/01/2007 20.39.33 Final True -- True

                Comment


                  #9
                  imported post

                  I can't tell you where its wrong but its obvious then that the condition should be false when it is true. What I would do next is determine visuallly what bar on the chart should trigger the condition to be false and write and place more print statements to see what the logic flow is for that bar, print out value to see where you have a logic flaw in your code.


                  Ray
                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by DavidHP, Today, 07:56 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by kujista, Today, 06:23 AM
                  3 responses
                  8 views
                  0 likes
                  Last Post kujista
                  by kujista
                   
                  Started by Mindset, Yesterday, 02:04 AM
                  2 responses
                  18 views
                  0 likes
                  Last Post NinjaTrader_RyanS  
                  Started by f.saeidi, Today, 08:03 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by samish18, 04-17-2024, 08:57 AM
                  15 responses
                  53 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X