Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

HighSwings

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

    HighSwings

    Hello,
    please look at the picture.
    I have some HighSwings and need to get the number of bars of each FIRST BAR if High >= HighSwing.

    HighA >= SwingA
    HighB >= SwingB etc.

    I would like to achieve that the line of HighSwing will appear in the meantime until create new High (blue arrow)

    The number of bars of each HighSwing I already have.

    thank you for help
    Attached Files
    Last edited by licovata; 10-23-2015, 06:36 AM.

    #2
    Originally posted by licovata View Post
    Hello,
    please look at the picture.
    I have some HighSwings and need to get the number of bars of each FIRST BAR if High >= HighSwing.

    HighA >= SwingA
    HighB >= SwingB etc.

    I would like to achieve that the line of HighSwing will appear in the meantime until create new High (blue arrow)

    The number of bars of each HighSwing I already have.

    thank you for help
    Exact question asked and answered here, with annotated code. You may have to write a line or two to get the number of contained bars into a variable and write it out as text on the chart.

    ref: http://ninjatrader.com/support/forum...78&postcount=6

    Comment


      #3
      Originally posted by koganam View Post
      Exact question asked and answered here, with annotated code. You may have to write a line or two to get the number of contained bars into a variable and write it out as text on the chart.

      ref: http://ninjatrader.com/support/forum...78&postcount=6
      Here is the code I had written

      #region Variables
      private int barcounter = 0;
      private float markersize = 10;
      private Color upcolor = Color.Green;
      private Color downcolor = Color.Red;
      private System.Drawing.Font textFont;
      #endregion

      protected override void Initialize()
      {
      CalculateOnBarClose = true;
      Overlay = true;
      PriceTypeSupported = false;
      }

      protected override void OnBarUpdate()
      {
      if(CurrentBar == 0)
      textFont = new Font("Arial",markersize);
      if(CurrentBar < 5)
      return;
      if(FirstTickOfBar)
      barcounter++;
      isHighPivot(2,upcolor);
      isLowPivot(2,downcolor);
      }

      private void isHighPivot(int period, Color color)
      {
      #region HighPivot
      int y = 0;
      int Lvls = 0;

      //Four Matching Highs
      if(High[period]==High[period+1] && High[period]==High[period+2] && High[period]==High[period+3])
      {
      y = 1;
      while(y<=period)
      {
      if(y!=period ? High[period+3]>High[period+3+y] : High[period+3]>High[period+3+y])
      Lvls++;
      if(y!=period ? High[period]>High[period-y] : High[period]>High[period-y])
      Lvls++;
      y++;
      }
      }
      //Three Matching Highs
      else if(High[period]==High[period+1] && High[period]==High[period+2])
      {
      y=1;
      while(y<=period)
      {
      if(y!=period ? High[period+2]>High[period+2+y] : High[period+2]>High[period+2+y])
      Lvls++;
      if(y!=period ? High[period]>High[period-y] : High[period]>High[period-y])
      Lvls++;
      y++;
      }
      }
      //Two Matching Highs
      else if(High[period]==High[period+1])
      {
      y=1;
      while(y<=period)
      {
      if(y!=period ? High[period+1]>High[period+1+y] : High[period+1]>High[period+1+y])
      Lvls++;
      if(y!=period ? High[period]>High[period-y] : High[period]>High[period-y])
      Lvls++;
      y++;
      }
      }
      //Regular Pivot
      else
      {
      y=1;
      while(y<=period)
      {
      if(y!=period ? High[period]>High[period+y] : High[period]>High[period+y])
      Lvls++;
      if(y!=period ? High[period]>High[period-y] : High[period]>High[period-y])
      Lvls++;
      y++;
      }
      }

      //Auxiliary Checks
      if(Lvls<period*2)
      {
      Lvls=0;
      //Four Highs - First and Last Matching - Middle 2 are lower
      if(High[period]>=High[period+1] && High[period]>=High[period+2] && High[period]==High[period+3])
      {
      y=1;
      while(y<=period)
      {
      if(y!=period ? High[period+3]>High[period+3+y] : High[period+3]>High[period+3+y])
      Lvls++;
      if(y!=period ? High[period]>High[period-y] : High[period]>High[period-y])
      Lvls++;
      y++;
      }
      }
      }
      if(Lvls<period*2)
      {
      Lvls=0;
      //Three Highs - Middle is lower than two outside
      if(High[period]>=High[period+1] && High[period]==High[period+2])
      {
      y=1;
      while(y<=period)
      {
      if(y!=period ? High[period+2]>High[period+2+y] : High[period+2]>High[period+2+y])
      Lvls++;
      if(y!=period ? High[period]>High[period-y] : High[period]>High[period-y])
      Lvls++;
      y++;
      }
      }
      }

      if(Lvls>=period*2)
      {

      int distance = lastBar - (CurrentBar - period);



      DrawLine("High"+barcounter.ToString(), true, period, High[period], period - distance, High[period], upcolor, DashStyle.Dash, 2);
      The result is shown in Figure
      Attached Files

      Comment


        #4
        Originally posted by licovata View Post
        Here is the code I had written



        The result is shown in Figure
        While I may sound critical, I am really not, but your code uses an awful lot of loops. I generally avoid loops unless they appear to be unavoidable, as for example when processing all DrawObjects on the chart, in order to find what we need to process. I generally avoid running a loop serially over past bars to actually just define a condition. Just my $0.02.

        As always with programming, there are many ways to achieve the objective, so you can certainly adjust your code to do as you want, by using the notes in my code.

        The code to which I pointed you requires you to define your initial drawing condition, thus
        Code:
        bool LongSetup = false;
                    LongSetup = High[0] <= Low[2] && Low[1] < Low[2];
                    if (LongSetup) {//...}
        then draws a ray and replaces the ray with a line when that ray is broken. It does not need to know anything about how many rays there are, or any other details. It will do the actions for any and all rays that the code itself draws, and will ignore any and all DrawObjects that are manually drawn by the user.

        You merely have to determine and write your LongSetup qualifying condition. You can even rename it throughout the code to make more semantic sense in your particular setup. After all, it is mentioned only thrice, and in close proximity, right at the beginning of the code.
        Last edited by koganam; 10-23-2015, 10:53 AM.

        Comment


          #5
          Well, I guess I'm ****ed. I'm not a programmer. However, I have some code I wrote.
          I basic idea was to write an indicator that would show me selected swings, that means creating HighSwing (High[0] < High[1] && High[2] < High[1]) and the line will display them in until the price again, this crosses the line, as shown on the original image. It would help me in my business.
          Original code that shows swings, I copied from another indicator that I found on the forum.
          In my neighborhood I know any programmer who could help me, so I wrote here on the forum.
          But I found that I do not write it myself, so I'm sorry that I robbed you of your time. thank you

          Comment


            #6
            Originally posted by licovata View Post
            Well, I guess I'm ****ed. I'm not a programmer. However, I have some code I wrote.
            I basic idea was to write an indicator that would show me selected swings, that means creating HighSwing (High[0] < High[1] && High[2] < High[1]) and the line will display them in until the price again, this crosses the line, as shown on the original image. It would help me in my business.
            Original code that shows swings, I copied from another indicator that I found on the forum.
            In my neighborhood I know any programmer who could help me, so I wrote here on the forum.
            But I found that I do not write it myself, so I'm sorry that I robbed you of your time. thank you
            You have written it right there. You would use:
            Code:
            LongSetup = High[0] < High[1] && High[2] < High[1];
            And if you want to make semantic sense in your context, just replace the word "LongSetup" with the word "HighSwing" everywhere. There are only 3 places that it occurs.

            This code:
            Code:
                        //process rays - draw line where there was a ray. Stop one bar ahead of CurrentBar.
                        foreach (IRay tempRay in this.RaysToBeDeleted)
                        {
                            string rayNumber = tempRay.Tag.Substring(3); //extract ray number
                           [COLOR="Blue"] int startBarsAgo = tempRay.Anchor1BarsAgo;[/COLOR]
                            int endBarsAgo = 1;
                            double lineLevel = tempRay.Anchor1Y;
                            DrawLine("line"+rayNumber, false, startBarsAgo, lineLevel, endBarsAgo, lineLevel, Color. Cyan, DashStyle.Solid, 2);
                        }
            allows you to know the number of bars in the line: it is obviously startBarsAgo, so all you need to do is use DrawText() to write that number at the CurrentBar location.

            To see what it looks like, you will have to actually write the code. Of course, you can hire anybody to do the work for you if you so wish. I opened the code because I really do not care if someone else uses it, even if they get paid to do so. You can always point whomever you hire to the code: it might save a little time.

            Comment


              #7
              Many thanks for your help. Your code helped me a lot, the indicator I have done and it works exactly as it should.
              Attached Files

              Comment


                #8
                Originally posted by licovata View Post
                Many thanks for your help. Your code helped me a lot, the indicator I have done and it works exactly as it should.
                I am glad that you were willing to accept my help and actually do the work yourself.

                Hopefully, soon you will be coding better than I do.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rocketman7, Today, 02:12 AM
                0 responses
                3 views
                0 likes
                Last Post rocketman7  
                Started by dustydbayer, Today, 01:59 AM
                0 responses
                1 view
                0 likes
                Last Post dustydbayer  
                Started by inanazsocial, Today, 01:15 AM
                0 responses
                4 views
                0 likes
                Last Post inanazsocial  
                Started by trilliantrader, 04-18-2024, 08:16 AM
                5 responses
                22 views
                0 likes
                Last Post trilliantrader  
                Started by Davidtowleii, Today, 12:15 AM
                0 responses
                3 views
                0 likes
                Last Post Davidtowleii  
                Working...
                X