INDICATOR that displays retracement and expansion levels on chart

Hi,

I’m trying to create a custom indicator that displays certain levels on a chart. Based on a few custom indicators I’ve created.

The idea (picture below):

when price moves above HighLine (the green line) and forms a newHIGH (red dotted horizontal line), it needs to display three levels based on the LEG (red dotted diagonal line) between the last LOW (green dotted horizontal line) and the newHIGH. LEVEL1(lowest blue line) at LOW-0.5LEG, LEVEL2 (middle blue line) at LOW+0.5LEG and LEVEL3 (highest blue line) at LOW+2*LEG. These levels need to be displayed until the next break of HighLine indicator.

I will add in the code for the HighLine indicator and the code for LEVELS (that doesn’t work).

//±-----------------------------------------------------------------+
//| |
//| 1HighLine |
//| |
//±-----------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Green
input int BRKR =50;
input int PER =50; //period
input int history =3000;

double high[];
double LowestHigh;
double HighLine[];
int i;
int cnt;

void init()
{

SetIndexBuffer(0,HighLine);
SetIndexStyle(0,DRAW_LINE,2,2);
SetIndexEmptyValue(0,0.0);

return;
}

int start()
{
int cnt, i=history-PER;
double price_high;

while(i>=0)
{
LowestHigh=EMPTY_VALUE;

  for(cnt=1;cnt<PER;cnt++)
    {
     price_high=iCustom(NULL,0,"MS_SR",0,i+cnt);
     
     if(LowestHigh>price_high)
        LowestHigh=price_high;
            
    }
    
  HighLine[i]=LowestHigh+BRKR*Point;
  
  i--;
 }

return(0);
}

//±-----------------------------------------------------------------+
//±-----------------------------------------------------------------+
//| |
//| 1LEVELS |
//| |
//±-----------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Green

input int History = 3000;

double LEVEL1[];
double LEVEL2[];
double LEVEL3[];
double newHIGH[];
double oldHIGH[];
double LOW[];
double HighLine[];

double LEG;
int i;

int init()
{
SetIndexArrow(0, 119);
SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,3,Blue);
SetIndexDrawBegin(0,i-1);
SetIndexBuffer(0, LEVEL1);

SetIndexArrow(1, 119);
SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,3,Blue);
SetIndexDrawBegin(1,i-1);
SetIndexBuffer(1, LEVEL2);

SetIndexArrow(2, 119);
SetIndexStyle(2,DRAW_ARROW,STYLE_DOT,3,Blue);
SetIndexDrawBegin(2,i-1);
SetIndexBuffer(2, LEVEL3);

SetIndexBuffer(3, newHIGH);
SetIndexStyle(3,EMPTY,EMPTY,EMPTY,clrNONE);
SetIndexBuffer(4, oldHIGH);
SetIndexStyle(4,EMPTY,EMPTY,EMPTY,clrNONE);
SetIndexBuffer(5, LOW);
SetIndexStyle(5,EMPTY,EMPTY,EMPTY,clrNONE);
SetIndexBuffer(6, HighLine);
SetIndexStyle(6,EMPTY,EMPTY,EMPTY,clrNONE);

return(0);
}

int start()
{ i=History;
while(i>=0)
{ newHIGH[i]=iCustom(NULL,0,“MS_SR”,2,i); // custom indicator that shows high/ressistance and low/support
oldHIGH[i]=iCustom(NULL,0,“MS_SR”,2,i+1);
LOW[i]=iCustom(NULL,0,“MS_SR”,3,i);
HighLine[i]=iCustom(NULL,0,“4BRKR”,0,i); //CUSTOM INDICATOR HighLine

  if (oldHIGH[i]<HighLine[i]&&newHIGH[i]>HighLine[i]) 
  {  LEG=newHIGH[i]-LOW[i];
     LEVEL1[i]=LOW[i]-LEG*0.5;
     LEVEL2[i]=LOW[i]+LEG*0.5;
     LEVEL3[i]=LOW[i]+LEG*2.0;
  }
  else 
  {    LEVEL1[i]=LEVEL1[i+1];
       LEVEL2[i]=LEVEL2[i+1];
       LEVEL3[i]=LEVEL3[i+1];
  }     

i–;
}
return(0);
}

//±-----------------------------------------------------------------

Please help me!! And if there is something that needs further explanation let me know…

Thanks

I’m not sure that pasting the code like this is helpful. Perhaps attach it as a separate file or put it on GitHub and link it?