Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Divergence logic

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

    Divergence logic

    Hi, if I was going to write the logic for divergence, let’s say it’s RSI divergence, I need to identify two peaks and second one is lower peak , how do I calculate those peaks? Or best approach?

    #2
    Hello tkaboris,

    If those peaks are high or low prices you can use the HighestBar and LowestBar methods.


    Comment


      #3
      thank you. If i want to find highest number of stochasticsFast in the last 5 bars, Do i use Min() or Max() function then? ​

      Comment


        #4
        I have found max price using
        double maxHigh = MAX(StochasticsFast(3, 14).D, 5)[0];

        But i dont know how to identify higher and lower peak of the last 5 bars. For first peak stoch reading has to move upwards then downwards and for second peak is the same process

        Comment


          #5
          I created seriesmaxHigh1 to track

          maxHigh1[0] = MAX(StochasticsFast(3, 14).D, 5)[0];
          maxHigh2[0] = MAX(StochasticsFast(3, 14).D, 5)[0];
          and i am stuck with the condition.. dont know how to proceed to identify rising and lowering peak. I need to look back 2 periods and to look forward 2 periods

          if (maxHigh1[1] > 80 && maxHigh1[2] < maxHigh1[1] && maxHigh1[3] < maxHigh1[2])
          Last edited by tkaboris; 06-23-2023, 09:34 AM.

          Comment


            #6
            All i am doing is collecting highest in the last 5 bars when its above 80. I now need to collect those values and determine the highest peak.
            region Find Peak

            if (maxHigh1[1] > 80 && maxHigh1[0] > maxHigh1[2] )

            {
            pivotHigh = true;

            Print("maxHigh1[1]" + maxHigh1[1] );
            }
            else if (maxHigh1[1] < 80)
            {
            pivotHigh = false;
            }
            Print(pivotHigh + " Currentbar: " + CurrentBar);
            #endregion​

            Comment


              #7
              What would be the approach to code divergence on this stoch indicator? There are two highs and second high is less then previous high.

              Click image for larger version

Name:	image.png
Views:	212
Size:	36.8 KB
ID:	1258792

              Comment


                #8
                Hello tkaboris,

                You would have to come up with your own logic to look for that based on some criteria. If both of those highs are within the same period and the second high is less than the first that wouldn't be considered a high, that would be an ignored lesser value when using any of the existing methods to check for highest bars/max values. If the indicator has a fixed scale value you could potentially check if the price is greater than X and store those prices in a list or array. Because that is infrequent and not on every bar you wouldn't be able to store those values in a Series<double> and then pass that to an indicator, indicators work based on continuous input data. You would have to do your own math logic based on your list or array of values.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                56 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                133 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X