Download MetaTrader 5
To add comments, please log in or register
Format text in the messages editor. It is convenient!
strathmoreraven
169
strathmoreraven 2014.11.24 15:53 

I would like to add something to an indicator that I wrote but have not been able to work out how to do it.

The indicator currently does two things

1. first, it marks bars with a green or red x that form a swing high or swing low. (It uses a while loop so that swings that have equal highs or equal lows will also be included). This is code for swing high
//SPIKE HIGH
// if there is a lower high then look for a spike high
//
//  I    OR   II   ETC.
// I I       I  I


//A. loop back to find first bar of pattern
   if(High[i+1] < High[i+2])
   {
      int ShiftOfFirstBarOfSH = 3; // i.e. the bar furthest from the right edge of the chart
      while
      (   
         i+ShiftOfFirstBarOfSH < Bars // check for running out of bars
         && High[i+ShiftOfFirstBarOfSH] >= High[i+(ShiftOfFirstBarOfSH-1)]
      )
         {
              ShiftOfFirstBarOfSH++;
         }
   }

// B. then loop forward to find 2nd to last bar of pattern - which is bar marked by indicator   
   if(High[i+1] < High[i+2])
   {
      int ShiftOfSHmarker = ShiftOfFirstBarOfSH-1;
      while
      (
         i+ShiftOfSHmarker < Bars
         && High[i+ShiftOfSHmarker] == High[i+(ShiftOfSHmarker-1)]
      )
         {
            ShiftOfSHmarker++;
         }
   }

// C.  
   if(High[i+1] < High[i+2] && High[i+ShiftOfFirstBarOfSH] < High[i+(ShiftOfFirstBarOfSH-1)])
   {
      SpikeHi[i+ShiftOfSHmarker] = High[i+ShiftOfSHmarker] + Point();
   }


Then, it marks with lime or magenta arrows the bars where the high breaks the high of the the most recent swing high (uptrend) or where the low breaks the low of the most recent swing low (down trend). This is the code for uptrend.

//HIGH OF BAR IS ABOVE MOST RECENT SPIKE HIGH
//1. loop back until you find a lower high

   int ShiftEndSpHi = 2;
   while(i+ShiftEndSpHi < Bars && High[i+ShiftEndSpHi] <= High[i+(ShiftEndSpHi-1)])
   {
      ShiftEndSpHi++;
   }
   
//2. loop back from high bar of the lower high until you find a higher high
   int ShiftStartSpHi = ShiftEndSpHi;
   while(i+(ShiftEndSpHi+1) < Bars && High[i+(ShiftEndSpHi+1)] >= High[i+ShiftEndSpHi])
   {
      ShiftEndSpHi++;
   }

//3. find highest high between i+1 and most recent spike high
   int BarsBetweenBarOneAndSpHi = 2 - (ShiftOfSHmarker - 1);
   int ShiftHHBetweenBarOneAndSpHi = iHighest(NULL,0,2,BarsBetweenBarOneAndSpHi,2);
   double HHBetweenBarOneAndSpHi = iHigh(NULL,0,ShiftHHBetweenBarOneAndSpHi);


   if(High[i+1] > High[i+ShiftEndSpHi])
   {
      SpikeTrendUp[i+1] = High[i+1] + Range*0.5;;
   }


I would like to be able to mark EVERY bar with a lime or magenta arrow

- lime if there has been an up trend more recently than a down trend

- magenta if there has been a down trend more recently than an uptrend


I have not been able to work out a way to do this - any suggestions or pointers? Thanks

/
To add comments, please log in or register