I have just created a simple little indicator to mark the swing highs & lows on the chart. I am now adding bits to the code in order to automatically calculate the distance between the two but I am running into a slight issue.
The swings are properly calculating and plotting. It is also calculating the distance between the swings - and the calculations are, generally correct.
I have attached a screenshot of the AUDUSD. On the chart you will find green dots on the low of bars representing a swing low and yellow dots on the highs of other bars representing swing highs.
Within the box, you will also notice two consecutive green dots followed by 2 consecutive yellow dots.
As the code currently stands (which will be posted in a moment), it is calculating the distance between the swing high and both of the following swing lows (giving 2 calculations). The same is true with the following two consecutive swing highs - it is then calculating both of them with the previous swing low.
What I would like to see is that it calculates the swing high to the lowest swing low and vice versa. In other words, if there are two consecutive swing lows (without a swing high between them) then I would like it to effectively ignore the first swing low and only calculate the distance between the first swing high and the lowest swing low.
Attached is also the Output window showing the calculations so that you can see how it is calculating.
Here is my current code:
if ((High[0] < High[2] && High[1] < High[2] && High[2] > High[3] && High[2] > High[4]) || (High[0] < High[2] && High[1] == High[2] && High[2] > High[3] && High[2] > High[4])) { swingHigh = High[2]; SwingHigh.Set(2,High[2]); Print(Time[2] + " Range = " + (Math.Round((swingHigh - swingLow)*10000, 1))); } if ((Low[0] > Low[2] && Low[1] > Low[2] && Low[2] < Low[3] && Low[2] < Low[4]) || (Low[0] > Low[2] && Low[1] == Low[2] && Low[2] < Low[3] && Low[2] < Low[4])) { swingLow = Low[2]; SwingLow.Set(2,Low[2]); Print(Time[2] + " Range(s) = " + (Math.Round((Math.Abs(swingLow - swingHigh)*10000),1))); }
I hope that this makes sense what I am attempting to communicate.
Do you have any ideas on how I could accomplish this? Thank you very much for your help!!
Comment