Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Counter crossing the horizontal line

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

    Counter crossing the horizontal line

    Hello All. I have a indicator on easylanguage. I want to implement it on ninjascript. In the picture of his project.



    Code:
    input: count(3);
    var: x(0), oldest(0), recycle(0), size(199);
    array: id[199,3](0);  // 0=id, 1=price, 2=count, 3=age
    
    once for x=0 to size begin
        id[x,0]=tl_new(d,t,0,d,t,0);
        tl_setextright (id[x,0], True);
    end;
    
    if barstatus(1)=2 then begin
        oldest=0;
        
        for x=0 to size begin
        
            if L<=id[x,1] and H>=id[x,1] then begin
            
                id[x,2]=id[x,2]+1;
                TL_SetColor(id[x,0],red);
                tl_setstyle(id[x,0],1);
                if id[x,2] = count-1 then 
                    begin 
                        TL_SetColor(id[x,0],blue);
                        tl_setstyle(id[x,0],3); 
                    end;
                if id[x,2]=count then begin
                
                    id[x,1]=0;  id[x,2]=0;  id[x,3]=9999999;  tl_setend(id[x,0],d,t,0);  tl_setbegin(id[x,0],d,t,0);  // reset price, count and age
                end;
                
            end;
            
            if id[x,1]>0 then tl_setend(id[x,0],d,t,id[x,1]);
            
            id[x,3]=id[x,3]+1;
            
            if id[x,3]>oldest then begin
            
            if id[x,2]= count-1 then TL_SetColor(id[x,0],blue);
                oldest=id[x,3];  recycle=x;
            end;
            
        end;
        
        id[recycle,1]=c;  id[recycle,2]=0;  id[recycle,3]=0;  tl_setend(id[recycle,0],d,t,c);  tl_setbegin(id[recycle,0],d,t,c);
    end;
    He draws a horizontal line on the closing price of each bar. The horizontal line is displayed until it intersects the price of a certain number of times.

    First, I tried to display a horizontal line at each price:
    Code:
    for (int i=1; i<777; i++)
                    {
                         DrawHorizontalLine("tag1"+CurrentBar,Close[i], Color.Red);
                    }
    I could not get.

    Please advise how I can do it, and how to work with the horizontal line tag, to appeal to her?

    Thank.
    Last edited by doitagainforme; 05-02-2012, 02:46 AM.

    #2
    doitagainforme,

    Are you trying to implement this in NinjaTrader? NinjaScript would be used here. Unfortunately easy language is quite a bit different here.

    This here should be all that is required in your OnBarUpdate() method :

    DrawHorizontalLine("tag1"+CurrentBar,Close[0], Color.Red);

    What you are currently doing with the for loop, is redrawing a different line with the same tag over and over. OnBarUpdate() is called for each historical bar on your chart, and for all future bars. CurrentBar would change each time OnBarUpdate() is called on historical and future bars.

    You may also want to add :

    if ( CurrentBar < 1 )
    {
    return;
    }

    ... to your OnBarUpdate().
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Adam. I realized I ninjascript another concept. In easylang zero bar on the right. In ninjascript zero bar on the left?

      Sorry if my questions are primitive. I am Russian-speaking, I have to work with the machine translator.

      Comment


        #4
        doitagainforme,

        Essentially, Close[0] means "the most current bars close price", but this may be accessed the same way on a historical bar. When NinjaTrader is generating indicators, it uses something called a data series which adds elements for each subsequent bar. When you initially put a indicator on a chart, it starts with the very first bar in the past and iterates through adding the next bar to the data series each time it goes onto the next bar.

        If you try this code :

        Print("Close price : "+Close[0]+" Current Bar : "+CurrentBar+" Time : "+ToTime(Time[0]));

        You can see what I mean in the Tools > Output window.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          At the moment my brain was able to generate the code. It compiles, but does not bring results, draws only one line. Maybe I need another array of lines? I will be happy with any prompts.

          Code:
          protected override void OnBarUpdate()
                  {
          
                  int[] count=new int[5000];
                  DrawHorizontalLine("tag1"+CurrentBar,Close[0], Color.Red);
                  for (int i=0; i<5000; i++)
                      {
                          
                          if ((Close[0]<=High[i]) || (Close[0]>=Low[i]))
                          {
                              count[CurrentBar]=count[CurrentBar]++;
                              if (count[CurrentBar] == 3)
                              {
                                  RemoveDrawObject("tag1"+CurrentBar);
                              }
                          }
                          
                          
                          
                      }
                      
                  }
          Last edited by doitagainforme; 05-02-2012, 02:16 AM.

          Comment


            #6
            Hello doitagainfrome,
            Thanks for your post and I am replying for Adam.

            You can use the below code to check if Close is above the horizontal line or not.

            Code:
            //draw a line at previous close
            IHorizontalLine hLine1 = DrawHorizontalLine("hLine", Close[1],  Color.Green);
            				
            int i  = MRO(delegate{return Close[0] > hLine1.Y ;}, 3, 20);
            
            if (i >= 0) //if close greater than horizontal line
            {
            	//do something
            }
            http://www.ninjatrader.com/support/h...urence_mro.htm

            Please let me know if I can assist you any further.
            Last edited by NinjaTrader_Joydeep; 05-02-2012, 05:08 AM.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              anahronist with bigmiketrading forum, made ​​me this indicator

              Code:
              #region Using declarations
              // add this
              using System.Collections.Generic; // needed for List class
              #endregion
              
              //...
              
                      #region Variables
                      // parameters
                      private int maxcount = 3; // Default setting for Count
                      // other
                      private class linedata {
                          public string id;
                          public int count, startbar;
                          public double value;
                          public linedata(int currentbar, double val) {
                              id = "ln"+currentbar.ToString();
                              startbar = currentbar - 1;
                              value = val;
                              count = 0;
                          }
                      }
                      private List<linedata> lines, to_remove;
                      #endregion
              
                      /// <summary>
                      /// This method is used to configure the indicator and is called once before any bar data is loaded.
                      /// </summary>
                      protected override void Initialize()
                      {
                          lines = new List<linedata>();
                          to_remove = new List<linedata>();
                          Overlay = true;
                          CalculateOnBarClose = true;
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                          if (CurrentBar == 0) return;
                          lines.Add(new linedata(CurrentBar, Close[1]));
                          to_remove.Clear();
                          foreach(linedata d in lines) {
                              if (d.value >= Low[0] && d.value <= High[0])
                                  ++d.count;
                              if (d.count <= maxcount)
                                  DrawLine(d.id, false, CurrentBar-d.startbar, d.value, 0, d.value, Color.Red, DashStyle.Solid, 1);
                              if (d.count >= maxcount) // we can stop extending this line
                                  to_remove.Add(d);    // add line to removal queue
                          }
                          foreach(linedata d in to_remove) // empty the removal queue
                              lines.Remove(d);
                      }  
               

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Frank1000, Today, 03:05 AM
              0 responses
              3 views
              0 likes
              Last Post Frank1000  
              Started by ntdev, Today, 01:14 AM
              4 responses
              15 views
              0 likes
              Last Post ntdev
              by ntdev
               
              Started by ct, Today, 02:22 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by yodaler, Yesterday, 06:12 PM
              4 responses
              12 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by sinpeople, 05-07-2021, 04:38 AM
              2 responses
              21 views
              0 likes
              Last Post hedgeplay  
              Working...
              X