KG Support & Resistance indicator - update help

 

I have been trying to get this indicator working with no luck. It attaches to the chart and only adds little red dots the all the candles.  I like the concept for swing trading and would like to try it out on my personal trading system I have been developing. I know nothing about code. I am pretty much looking at a foreign language. If anyone out there would be willing to take a look and possibly update the code for me , that would be great. Please let me know. Thanks




//+------------------------------------------------------------------+
//|                                      KG Support & Resistance.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Kang_Gun"
#property link      "http://www.free-knowledge.com"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Yellow
#property indicator_color2 Yellow
#property indicator_color3 LimeGreen
#property indicator_color4 LimeGreen
#property indicator_color5 Blue
#property indicator_color6 Blue
#property indicator_color7 Red
#property indicator_color8 Red
//---- input parameters

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
int KG;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,1,Yellow);
   SetIndexDrawBegin(0,KG-1);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"Resistance M15");
   SetIndexArrow(0, 158);
   SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,1,Yellow);
   SetIndexDrawBegin(1,KG-1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"Support M15");
   SetIndexArrow(1, 158);
   SetIndexStyle(2,DRAW_ARROW,STYLE_DOT,1,LimeGreen);
   SetIndexDrawBegin(2,KG-1);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexLabel(2,"Resistance H1");
   SetIndexArrow(2, 158);
   SetIndexStyle(3,DRAW_ARROW,STYLE_DOT,1,LimeGreen);
   SetIndexDrawBegin(3,KG-1);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexLabel(3,"Support H1");
   SetIndexArrow(3, 158);
   SetIndexStyle(4,DRAW_ARROW,STYLE_DOT,1,Blue);
   SetIndexDrawBegin(4,KG-1);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexLabel(4,"Resistance H4");
   SetIndexArrow(4, 158);
   SetIndexStyle(5,DRAW_ARROW,STYLE_DOT,1,Blue);
   SetIndexDrawBegin(5,KG-1);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexLabel(5,"Support H4");
   SetIndexArrow(5, 158);
   SetIndexStyle(6,DRAW_ARROW,STYLE_DOT,1,Red);
   SetIndexDrawBegin(6,KG-1);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexLabel(6,"Resistance D1");
   SetIndexArrow(6, 158);
   SetIndexStyle(7,DRAW_ARROW,STYLE_DOT,1,Red);
   SetIndexDrawBegin(7,KG-1);
   SetIndexBuffer(7,ExtMapBuffer8);
   SetIndexLabel(7,"Support D1");
   SetIndexArrow(7, 158);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//------------------------------------------------------------------ 
bool Fractal (string M,int P, int shift)
  {
   if (Period()>P) return(-1);
   P=P/Period()*2+MathCeil(P/Period()/2);
   if (shift<P)return(-1);
   if (shift>Bars-P)return(-1);
   for (int i=1;i<=P;i++)
     {
      if (M=="U")
        {
         if (High[shift+i]>High[shift])return(-1);
         if (High[shift-i]>=High[shift])return(-1);    
        }
      if (M=="L")
        {
         if (Low[shift+i]<Low[shift])return(-1);
         if (Low[shift-i]<=Low[shift])return(-1);
        }       
     }
   return(1);  
  } 
//------------------------------------------------------------------
int start()
  {
   int D1=1440, H4=240, H1=60, M15=15;
   KG=Bars;
      while(KG>=0)
      {
       if (Fractal("U",M15,KG)==1) ExtMapBuffer1[KG]=High[KG];
       else ExtMapBuffer1[KG]=ExtMapBuffer1[KG+1];
       if (Fractal("L",M15,KG)==1) ExtMapBuffer2[KG]=Low[KG];
       else ExtMapBuffer2[KG]=ExtMapBuffer2[KG+1];
       if (Fractal("U",H1,KG)==1) ExtMapBuffer3[KG]=High[KG];
       else ExtMapBuffer3[KG]=ExtMapBuffer3[KG+1];
       if (Fractal("L",H1,KG)==1) ExtMapBuffer4[KG]=Low[KG];
       else ExtMapBuffer4[KG]=ExtMapBuffer4[KG+1];
       if (Fractal("U",H4,KG)==1) ExtMapBuffer5[KG]=High[KG];
       else ExtMapBuffer5[KG]=ExtMapBuffer5[KG+1];
       if (Fractal("L",H4,KG)==1) ExtMapBuffer6[KG]=Low[KG];
       else ExtMapBuffer6[KG]=ExtMapBuffer6[KG+1];
       if (Fractal("U",D1,KG)==1) ExtMapBuffer7[KG]=High[KG];
       else ExtMapBuffer7[KG]=ExtMapBuffer7[KG+1];
       if (Fractal("L",D1,KG)==1) ExtMapBuffer8[KG]=Low[KG];
       else ExtMapBuffer8[KG]=ExtMapBuffer8[KG+1];
       KG--;
      }
 
 
   return(0);
  }
//+------------------------------------------------------------------+

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
MetaTrader 5 trading platform is a free Forex and stock trading tool.
 

1. in "Fractal()" you have to correct from -1 to false and from 1 to true.

bool Fractal (string M,int P, int shift)
  {
   if (Period()>P) return(false);
   P=P/Period()*2+MathCeil(P/Period()/2);
   if (shift<P)return(false);
   if (shift>Bars-P)return(false);
   for (int i=1;i<=P;i++)
     {
      if (M=="U")
        {
         if (High[shift+i]>High[shift])return(false);
         if (High[shift-i]>=High[shift])return(false);    
        }
      if (M=="L")
        {
         if (Low[shift+i]<Low[shift])return(false);
         if (Low[shift-i]<=Low[shift])return(false);
        }       
     }
   return(true);  
  } 

2. In "Start()"

line 113

//KG=Bars;
KG=Bars-1440;

line 116, 118, 120, 122, 124, 126, 128, 130 You have to correct from 1 to true

//if (Fractal("U",M15,KG)==1) ExtMapBuffer1[KG]=High[KG];
if (Fractal("U",M15,KG)==true) ExtMapBuffer1[KG]=High[KG];

3. line 37, 42, 47, 52, 57, 62, 67, 72  You should correct as following.

//SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,1,Yellow);
SetIndexStyle(0,DRAW_ARROW);
 
UnadaJapon:

1. in "Fractal()" you have to correct from -1 to false and from 1 to true.

2. In "Start()"

line 113

line 116, 118, 120, 122, 124, 126, 128, 130 You have to correct from 1 to true

3. line 37, 42, 47, 52, 57, 62, 67, 72  You should correct as following.

Thank you for the advice. I will try and see if I can get it worked out. :)

 
UnadaJapon:

1. in "Fractal()" you have to correct from -1 to false and from 1 to true.

2. In "Start()"

line 113

line 116, 118, 120, 122, 124, 126, 128, 130 You have to correct from 1 to true

3. line 37, 42, 47, 52, 57, 62, 67, 72  You should correct as following.

That seems to have done the trick. Thank you very much.

 

Here is the updated code if anyone would like to try it out with their system. If any of the S/R lines get too overwhelming on the screen , you can always go into setting colors and change color to none. As of this moment , I have only had a chance to use it for about 5 minutes but....The 15min S/R lines could make the chart a little congested for some. Always best to keep it simple. Have a good day



//+------------------------------------------------------------------+
//|                                      KG Support & Resistance.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Kang_Gun"
#property link      "http://www.free-knowledge.com"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Yellow
#property indicator_color2 Yellow
#property indicator_color3 LimeGreen
#property indicator_color4 LimeGreen
#property indicator_color5 Blue
#property indicator_color6 Blue
#property indicator_color7 Red
#property indicator_color8 Red
//---- input parameters

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
int KG;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexDrawBegin(0,KG-1);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"Resistance M15");
   SetIndexArrow(0, 158);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexDrawBegin(1,KG-1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"Support M15");
   SetIndexArrow(1, 158);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexDrawBegin(2,KG-1);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexLabel(2,"Resistance H1");
   SetIndexArrow(2, 158);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexDrawBegin(3,KG-1);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexLabel(3,"Support H1");
   SetIndexArrow(3, 158);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexDrawBegin(4,KG-1);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexLabel(4,"Resistance H4");
   SetIndexArrow(4, 158);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexDrawBegin(5,KG-1);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexLabel(5,"Support H4");
   SetIndexArrow(5, 158);
   SetIndexStyle(6,DRAW_ARROW);
   SetIndexDrawBegin(6,KG-1);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexLabel(6,"Resistance D1");
   SetIndexArrow(6, 158);
   SetIndexStyle(7,DRAW_ARROW);
   SetIndexDrawBegin(7,KG-1);
   SetIndexBuffer(7,ExtMapBuffer8);
   SetIndexLabel(7,"Support D1");
   SetIndexArrow(7, 158);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//------------------------------------------------------------------ 
bool Fractal (string M,int P, int shift)
  {
   if (Period()>P) return(false);
   P=P/Period()*2+MathCeil(P/Period()/2);
   if (shift<P)return(false);
   if (shift>Bars-P)return(false);
   for (int i=1;i<=P;i++)
     {
      if (M=="U")
        {
         if (High[shift+i]>High[shift])return(false);
         if (High[shift-i]>=High[shift])return(false);    
        }
      if (M=="L")
        {
         if (Low[shift+i]<Low[shift])return(false);
         if (Low[shift-i]<=Low[shift])return(false);
        }       
     }
   return(true);  
  } 
//------------------------------------------------------------------
int start()
  {
   int D1=1440, H4=240, H1=60, M15=15;
   KG=Bars-1440;
      while(KG>=0)
      {
       if (Fractal("U",M15,KG)==true) ExtMapBuffer1[KG]=High[KG];
       else ExtMapBuffer1[KG]=ExtMapBuffer1[KG+1];
       if (Fractal("L",M15,KG)==true) ExtMapBuffer2[KG]=Low[KG];
       else ExtMapBuffer2[KG]=ExtMapBuffer2[KG+1];
       if (Fractal("U",H1,KG)==true) ExtMapBuffer3[KG]=High[KG];
       else ExtMapBuffer3[KG]=ExtMapBuffer3[KG+1];
       if (Fractal("L",H1,KG)==true) ExtMapBuffer4[KG]=Low[KG];
       else ExtMapBuffer4[KG]=ExtMapBuffer4[KG+1];
       if (Fractal("U",H4,KG)==true) ExtMapBuffer5[KG]=High[KG];
       else ExtMapBuffer5[KG]=ExtMapBuffer5[KG+1];
       if (Fractal("L",H4,KG)==true) ExtMapBuffer6[KG]=Low[KG];
       else ExtMapBuffer6[KG]=ExtMapBuffer6[KG+1];
       if (Fractal("U",D1,KG)==true) ExtMapBuffer7[KG]=High[KG];
       else ExtMapBuffer7[KG]=ExtMapBuffer7[KG+1];
       if (Fractal("L",D1,KG)==true) ExtMapBuffer8[KG]=Low[KG];
       else ExtMapBuffer8[KG]=ExtMapBuffer8[KG+1];
       KG--;
      }
 
 
   return(0);
  }
//+------------------------------------------------------------------+

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
MetaTrader 5 trading platform is a free Forex and stock trading tool.
 

is there any way to code this indicator to mq5 ?

 
r40s:

is there any way to code this indicator to mq5 ?

I am not sure. You could probably find a multi time frame fractal indicator and add it to the chart a few times.
 
Naguisa Unada:

1. in "Fractal()" you have to correct from -1 to false and from 1 to true.

2. In "Start()"

line 113

line 116, 118, 120, 122, 124, 126, 128, 130 You have to correct from 1 to true

3. line 37, 42, 47, 52, 57, 62, 67, 72  You should correct as following.

I was hoping you could help me with another issue. I am trying to extend daily open line until break. Trying to add the code in but , it is beyond me. Would indicator need to be totally rewritten in order to have an extend line function ? Or would you be able to show me what to add ? I would like to have it act similar to this MTF Fractal indicator.

 
Joseph Dragon :

I was hoping you could help me with another issue. I am trying to extend daily open line until break. Trying to add the code in but , it is beyond me. Would indicator need to be totally rewritten in order to have an extend line function ? Or would you be able to show me what to add ? I would like to have it act similar to this MTF Fractal indicator.

It is impossible to realize it with the way of this daily_open_line_mod-x.mq4. In order to extend it, it is necessary to add as many buffers as the number of lines displayed on the screen. But that is not practical.

 On the other hand MTF_Fractal.mq4 realizes it using objects.

TodayOpenBuffer[shift]= Open[shift];  
I think that it is better to create an object with this as a starting point, and extend it in "for loop" until the current price breaks the above price.
 
Naguisa Unada:

It is impossible to realize it with the way of this daily_open_line_mod-x.mq4. In order to extend it, it is necessary to add as many buffers as the number of lines displayed on the screen. But that is not practical.

 On the other hand MTF_Fractal.mq4 realizes it using objects.

I think that it is better to create an object with this as a starting point, and extend it in "for loop" until the current price breaks the above price.

That is a shame that the indicator would have to be totally rewritten. It makes sense now that you explain as you have. Thank you for the reply. I will always appreciate your help.

 
Naguisa Unada:

It is impossible to realize it with the way of this daily_open_line_mod-x.mq4. In order to extend it, it is necessary to add as many buffers as the number of lines displayed on the screen. But that is not practical.

 On the other hand MTF_Fractal.mq4 realizes it using objects.

I think that it is better to create an object with this as a starting point, and extend it in "for loop" until the current price breaks the above price.

Do you do freelance work ? I have an indicator that I would like to have made. I want to be able to have the mq4 code so it will always be up to date. I don't think it would be that complicated. Would not be along the lines of what I am asking you in the above post. But it would have to do with daily open.

Reason: