How to use Support and Resistance Effectively - page 64

 

Indicator

Here is a picture of the indicator. Blue lines are daily, orange lines are 4hr. I would like to be able to use the parameter tabs to define the style, type and color of the line, just like any horizontal line you would draw manually. The one function that needs to be removed is the delete all objects function. This makes using this indicator just about useless because it deletes all other objects on the chart when the time frame is changed.

Dave

Files:
 

hi

thx for sharing , but when i attached it to my platform, i see only one color,

deep pink only.

but if we could get it right, it would be a very useful indicator.

thx mason

 

Support & Resistance Indicator

Dave;

I know exactly what your saying. I have no fix for your indicator, but I understand what you want. I will PM someone that can. If he's not busy

he will have the answer.

Regards

Bill

 

Indicator Color

mason:
thx for sharing , but when i attached it to my platform, i see only one color,

deep pink only.

but if we could get it right, it would be a very useful indicator.

thx mason

Hi Mason,

Each time frame has one color. The color that shows up on the chart is determined by the time frame you use in the input tab. Change the number of minutes in the Time Frame field to 15,30,60,240,1440 and you will see a different color for each time frame. What I am attempting to do is to load the indicator onto the platform mutilple times with each one defined for that particular time frame. So I want to load it onto the 60, 240 and 1440 charts. So I would have 3 sets of colored lines. The problem with that is you get alot of solid lines which makes the chart hard to see. I want to be able to define the lines just like you would define any manually applied horizontal line on the chart. The other thing the indicator does is erase all the other manually applied objects to the chart when you change time frames. This feature is not helpful at all. The indicator does a good job of identifying the S&R lines on each TF it's just difficult to use in it's current format.

Dave

 

Code

I think I found the code to the indicator. Maybe some one can work with the code and make the changes.

//+------------------------------------------------------------------+

//| SUPRESMultiFrame.mq4 |

//| |

//| RD |

//+------------------------------------------------------------------+

#property copyright "RD"

#property link "marynarz15@wp.pl"

#property indicator_chart_window

#define MaxObject 1000

//---- indicator parameters

extern int TimeFrame=5;

extern int BarsMax=144;

extern int ExtDepth=13;

extern int ExtDeviation=1;

extern int ExtBackstep=5;

extern bool DeleteObjectsOnExit=true;

extern color LineColor1=RosyBrown;

extern color LineColor5=Aqua;

extern color LineColor15=DeepPink;

extern color LineColor30=PaleVioletRed;

extern color LineColor60=Red;

extern color LineColor240=DarkOrange;

extern color LineColor1440=DeepSkyBlue;

extern color LineColor10080=Lime;

//-----------------------

double ExtMapBuffer[];

double ExtMapBuffer2[];

int SUPRESCount=0;

int linewidth;

string NamePattern;

color LineColor;

//+------------------------------------------------------------------+

//| Delete objects |

//+------------------------------------------------------------------+

int DeleteSupRes()

{

int ObjectCount=ObjectsTotal();

string names[MaxObject];

for (int i=0; i<ObjectCount;i++)

names=ObjectName(i);

for (i=0; i<ObjectCount;i++)

{

string objname=names;

objname=StringSubstr(objname,0,StringLen(NamePattern));

if (objname!=NamePattern || ObjectType(names)!=OBJ_TREND)

names="";

}

for (i=0; i<ObjectCount;i++)

{

if (names!="") {

ObjectDelete(names);}

}

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorBuffers(2);

SetIndexBuffer(0,ExtMapBuffer);

SetIndexBuffer(1,ExtMapBuffer2);

SetIndexEmptyValue(0,0.0);

ArraySetAsSeries(ExtMapBuffer,true);

ArraySetAsSeries(ExtMapBuffer2,true);

switch (TimeFrame)

{

case 1: linewidth=1; LineColor=LineColor1; break;

case 5: linewidth=1; LineColor=LineColor5; break;

case 15: linewidth=1; LineColor=LineColor15; break;

case 30: linewidth=1; LineColor=LineColor30; break;

case 60: linewidth=1; LineColor=LineColor60; break;

case 240: linewidth=1; LineColor=LineColor240; break;

case 1440: linewidth=1; LineColor=LineColor1440; break;

case 10080: linewidth=1; LineColor=LineColor10080; break;

default: linewidth=1; TimeFrame=Period(); break;

}

NamePattern=DoubleToStr(TimeFrame,0)+" SUPRES ";

if (BarsMax<55) BarsMax=55;

DeleteSupRes();

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

if (DeleteObjectsOnExit) DeleteSupRes();

return(0);

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

int start()

{

int shift, back,lasthighpos,lastlowpos;

double val,res;

double curlow,curhigh,lasthigh,lastlow;

string objectname;

if(BarsMax==0) {BarsMax=Bars/2;}// return(0);

for(shift=iBars(NULL,TimeFrame)-ExtDepth; shift>=0; shift--)

{

val=iLow(NULL,TimeFrame,Lowest(NULL,TimeFrame,MODE_LOW,ExtDepth,shift));

if(val==lastlow) val=0.0;

else

{

lastlow=val;

if((iLow(NULL,TimeFrame,shift)-val)>(ExtDeviation*Point)) val=0.0;

else

{

for(back=1; back<=ExtBackstep; back++)

{

res=ExtMapBuffer[shift+back];

if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0;

}

}

}

ExtMapBuffer[shift]=val;

//--- high

val=iHigh(NULL,TimeFrame,Highest(NULL,TimeFrame,MODE_HIGH,ExtDepth,shift));

if(val==lasthigh) val=0.0;

else

{

lasthigh=val;

if((val-iHigh(NULL,TimeFrame,shift))>(ExtDeviation*Point)) val=0.0;

else

{

for(back=1; back<=ExtBackstep; back++)

{

res=ExtMapBuffer2[shift+back];

if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0;

}

}

}

ExtMapBuffer2[shift]=val;

}

// final cutting

lasthigh=-1; lasthighpos=-1;

lastlow=-1; lastlowpos=-1;

for(shift=iBars(NULL,TimeFrame)-ExtDepth; shift>=0; shift--)

{

curlow=ExtMapBuffer[shift];

curhigh=ExtMapBuffer2[shift];

if((curlow==0)&&(curhigh==0)) continue;

//---

if(curhigh!=0)

{

if(lasthigh>0)

{

if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;

else ExtMapBuffer2[shift]=0;

}

//---

if(lasthigh<curhigh || lasthigh<0)

{

lasthigh=curhigh;

lasthighpos=shift;

}

lastlow=-1;

}

//----

if(curlow!=0)

{

if(lastlow>0)

{

if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;

else ExtMapBuffer[shift]=0;

}

//---

if((curlow<lastlow)||(lastlow<0))

{

lastlow=curlow;

lastlowpos=shift;

}

lasthigh=-1;

}

}

for(shift=iBars(NULL,TimeFrame)-1; shift>=0; shift--)

{

if(shift>=iBars(NULL,TimeFrame)-ExtDepth) ExtMapBuffer[shift]=0.0;

else

{

res=ExtMapBuffer2[shift];

if(res!=0.0) ExtMapBuffer[shift]=res;

}

}

///////////////////////// Lines creation /////////////////

int count=0;

double TempBufferPrice[MaxObject];

int TempBufferBar[MaxObject];

string ObjectNames[MaxObject];

//////////////////////// lists of lines //////////////////

for(shift=BarsMax; shift>0; shift--)

if (ExtMapBuffer[shift]>0)

{

count++;

TempBufferPrice[count-1]=ExtMapBuffer[shift];

TempBufferBar[count-1]=shift;

}

for(int i=0; i<count; i++)

ObjectNames=TimeFrame+"m S/R("+i+")"/*DoubleToStr(TempBufferPrice,Digits)+" "+

TimeToStr(iTime(NULL,TimeFrame,TempBufferBar),TIME_DATE|TIME_MINUTES)*/;

/////// deleting pending objects ///////////////

int ObjectForDeleteCount=0;

string ObjectsForDelete[MaxObject];

for(i=0; i<ObjectsTotal(); i++)

{

objectname=ObjectName(i);

if (StringSubstr(objectname,0,StringLen(NamePattern))==NamePattern)

{

ObjectForDeleteCount++;

ObjectsForDelete[ObjectForDeleteCount-1]=objectname;

}

}

for(i=0; i<count-2; i++)

{

objectname=ObjectNames;

for(int j=0; j<ObjectForDeleteCount; j++)

if(ObjectsForDelete[j]==objectname)

{

ObjectsForDelete[j]="";

break;

}

}

for(j=0; j<ObjectForDeleteCount; j++)

if (ObjectsForDelete[j]!="")

{

ObjectDelete(ObjectsForDelete[j]);

}

////////////// objects plotting /////////////////

for(i=0; i<count; i++)

{

if (ObjectFind(ObjectNames)==-1)

{

ObjectCreate(ObjectNames,OBJ_TREND,0,iTime(NULL,TimeFrame,TempBufferBar),TempBufferPrice,

iTime(NULL,TimeFrame,TempBufferBar)+10080*60,TempBufferPrice);

ObjectSet(ObjectNames,OBJPROP_WIDTH,linewidth);

ObjectSet(ObjectNames,OBJPROP_COLOR,LineColor);

ObjectSet(ObjectNames,OBJPROP_RAY,True);

ObjectSetText(ObjectNames,ObjectNames+" "+DoubleToStr(TempBufferPrice,Digits),8,"Courier",LightSteelBlue);

}

}

}

Dave

Files:
 

Sup & Res

downunderdave40:
Hi All,

I found this S&R indicator and it appears to be a very good indicator at identifying the S&R levels. The problem I have is that I can't use color or input tabs to change the width, style or color of the S&R lines. I find that all of the solid lines tend to clutter up the chart. I've looked at the code and I don't see anything that would allow me to change those 3 parameters. Is it possible that some kind soul could modify either the input or color tabs so the user can define the width, style and color of the lines. The other thing this indicator does is erase any other horizontal line the the user manually places on the chart. Can that function be deleted or turned off.

Thanks in advance

Dave

I have altered the indicator so that you can now alter the width, color or style of the lines, however each timeframe must be loaded separately, set each timeframe and line atributes as you load them, if you need to change a color or style or timeframe from an already loaded indicator just delete the lines using the object delete select the indicator on the chart in the normal manner then alter the inputs and then change timeframes and the colors styles etc will update.

it no longer appears to affect any text or extra lines put on the chart and the only side issue is that when you remove the indicator from the chart it does not delete the lines you have to delete them manually thru the objects function. I have tested it on the Strategy tester and everything seems to update correctly. This is all i could do without recoding the whole indicator but it seems to work OK.

support_resistance_v1.mq4

Files:
 

Thank You

cja:
I have altered the indicator so that you can now alter the width, color or style of the lines, however each timeframe must be loaded separately, set each timeframe and line atributes as you load them, if you need to change a color or style or timeframe from an already loaded indicator just delete the lines using the object delete select the indicator on the chart in the normal manner then alter the inputs and then change timeframes and the colors styles etc will update.

it no longer appears to affect any text or extra lines put on the chart and the only side issue is that when you remove the indicator from the chart it does not delete the lines you have to delete them manually thru the objects function. I have tested it on the Strategy tester and everything seems to update correctly. This is all i could do without recoding the whole indicator but it seems to work OK.

support_resistance_v1.mq4

Hi CJA,

Thanks so much for doing that change. This is just what I was looking for. If I may, would it require alot of additional work to have the indicator remove the lines when you delete and reload the indicator? One of the reasons I wanted to use this indicator is because it would save me time drawing the lines manually. If it's not an easy fix I can live with it. The other thing I noticed is when you try to apply the indicator to only one time frame using the visualization tab it still places the lines on all time frames. Is it possible to fix that? My intent was to load the indicator on the platform to 3 time frames, 60, 240 and 1440. What I would like to do is apply say the 60 min S&R lines to the 15 and 60 minute charts, the 240 min S&R to the 60 and 240 minute charts. It would be great if you or some one else could make that change. Again, thank you for your efforts. I think this will be a really useful indicator for alot of people once all of the parameters are user definable.

Dave

 
downunderdave40:
Hi CJA,

Thanks so much for doing that change. This is just what I was looking for. If I may, would it require alot of additional work to have the indicator remove the lines when you delete and reload the indicator? One of the reasons I wanted to use this indicator is because it would save me time drawing the lines manually. If it's not an easy fix I can live with it. The other thing I noticed is when you try to apply the indicator to only one time frame using the visualization tab it still places the lines on all time frames. Is it possible to fix that? My intent was to load the indicator on the platform to 3 time frames, 60, 240 and 1440. What I would like to do is apply say the 60 min S&R lines to the 15 and 60 minute charts, the 240 min S&R to the 60 and 240 minute charts. It would be great if you or some one else could make that change. Again, thank you for your efforts. I think this will be a really useful indicator for alot of people once all of the parameters are user definable.

Dave

I think if the delete function can be fixed then the visulization will as well, i will have another look as time permits

cja

 

Thanks

cja:
I think if the delete function can be fixed then the visulization will as well, i will have another look as time permits cja

Hi Cja,

Thanks a heap. I think that alot of people on this forum will like this indicator, once it's user definable.

Dave

 
Reason: