volume scan afl

#2
Try this -

Conditions
1) Current day volume should be 10 times greater than the previous day volume
2) Also Volume should be greater than 1,00,000 in order to filter low volume stocks
3) One can vary the number of times a stock should be greater than the previous days
and the minimum amount of volume to be scanned




Here are the Filter conditions that has been converted into the afl code:

Code:
Plot( Volume, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorGreen ), ParamColor("Down Color", colorRed ) ), ParamStyle( "Style", styleHistogram | styleThick, maskHistogram  ) );
Filter = V > 10*Ref(V,-1) AND V>100000;
AddColumn(V, "Volume", 1);
_SECTION_END();
 
Last edited:
#3
I need help in this Volume afl .. when i hit explore.. It is giving error..
(Variables missing mesg i m getting)

Help would be greatly appreciated.


Code:
//Shows if intraday volume is greater than average volume of last 5 days (customizable) with moving average //line.
Plot(V,"Volume",ParamColor("Color",colorBlueGrey), styleHistogram|styleThick);
Avgvol=0;
if (Interval()<inDaily) {
n = round(3600*6.75/Interval()); //number of bars in the day
d = Param("Lookback days",5,1,30,1); //averaging period
barnum = BarsSince(Day()!=Ref(Day(),-1)); //bar number from start of the day
for (i=0; i<n; i++) {
VarSet("vol"+i,IIf(i==barnum,V,0));
}
for (i=0; i<n; i++) { 
Avgvol=IIf(barnum==i,Sum(VarGet("vol"+i),n*d)/d,Avgvol);
}
Plot(Avgvol,"Average Volume",colorWhite,styleLine);
}
/*
AddColumn(V,"V",1.0,colorDefault,colorDefault,50);
AddColumn(barnum,"bar",1.0);
AddColumn(n,"n",1.0);
AddColumn(d,"d",1.0);
AddColumn(Avgvol,"avg",1.0,colorDefault,colorDefau lt,50);
for( i=0; i <n; i++ ) AddColumn(VarGet("vol"+i),"vol"+i,1.0);
Filter=1;
*/


Thanx you
 
#5
Hi any body can correct this code below not working. thanks a lot.

//+------------------------------------------------------------------+
//| VOLUME SWINGS & SR LEVELS.mq4 |
//| Copyright © 2008, FOREXflash. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, FOREXflash"
#property link "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue


extern color TrendUpColor=Blue;
extern color TrendDownColor=Red;
extern bool SnapExtremumsToLevelOnChar=True;
extern int FractalBarsOnEachSide=5;
extern int ProceedMaxHistoryBars=1000;
extern int LevelActuality=160;
extern bool RestDefaultTimeframeValues=1;
extern int ExtremumToLevelMaxGap=100;
extern double PriceDeltaFor1Bar=20;

int LevelLength[];
int LevelWidth[];
int PriceCrossedLevel;
double long[];
double short[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
ObjectsDeleteAll();
IndicatorBuffers(2);
SetIndexBuffer(0,long);
SetIndexBuffer(1,short);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
int i=0;

for (i=Bars-1;i>=0;i--)
if (ObjectFind("Level_"+i)!=-1)
ObjectDelete("Level_"+i);
for (i=Bars-1;i>=0;i--)
if (ObjectFind("Trend_"+i)!=-1)
ObjectDelete("Trend_"+i);
return(0);
}
//+-------------------------------------------+
int LastBarWasHighLow(int LELB, int LEHB)
{
if (LELB==-1 && LEHB!=-1)
return(1);
if (LELB!=-1 && LEHB==-1)
return(-1);
if (LELB!=-1 && LEHB!=-1 && LELB>LEHB)
return(1);
if (LELB!=-1 && LEHB!=-1 && LELB<LEHB)
return(-1);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,j;
int BarsToCheck;
int Stop;
int CurrState;
int LastExtremumHighBar=-1;
int LastExtremumLowBar=-1;
int LastExtremumBar=-1;
double iFractalValue=0,jFractalValue=0;

SetIndexStyle(0,DRAW_ARROW,0,3);
SetIndexArrow(0,159);
SetIndexStyle(1,DRAW_ARROW,0,3);
SetIndexArrow(1,159);
ArrayInitialize(long,0);
ArrayInitialize(short,0);

if (RestDefaultTimeframeValues==1)
{
switch (Period())
{
case 1:
{
ExtremumToLevelMaxGap=2;
PriceDeltaFor1Bar=0.2;
break;
}
case 5:
{
ExtremumToLevelMaxGap=5;
PriceDeltaFor1Bar=0.2;
break;
}
case 15:
{
ExtremumToLevelMaxGap=8;
PriceDeltaFor1Bar=0.2;
break;
}
case 30:
{
ExtremumToLevelMaxGap=10;
PriceDeltaFor1Bar=0.3;
break;
}
case 60:
{
ExtremumToLevelMaxGap=15;
PriceDeltaFor1Bar=0.4;
break;
}
case 240:
{
ExtremumToLevelMaxGap=25;
PriceDeltaFor1Bar=0.4;
break;
}
case 1440:
{
ExtremumToLevelMaxGap=75;
PriceDeltaFor1Bar=1.5;
break;
}
case 10080:
{
ExtremumToLevelMaxGap=150;
PriceDeltaFor1Bar=5;
break;
}
case 43200:
{
ExtremumToLevelMaxGap=300;
PriceDeltaFor1Bar=24;
break;
}
}
}
//+------------------------------------------------------------------+
PriceCrossedLevel=ExtremumToLevelMaxGap*2;

ArrayResize(LevelLength,Bars);
ArrayInitialize(LevelLength,0);
ArrayResize(LevelWidth,Bars);
ArrayInitialize(LevelWidth,1);

if (FractalBarsOnEachSide<=0)
FractalBarsOnEachSide=1;


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{

if (i==Lowest(Symbol(),Period(),MODE_LOW,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide))
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case -1:
{
if (Low<Low[LastExtremumLowBar])
{
long=Low;
long[LastExtremumLowBar]=0;
LastExtremumLowBar=i;
}
break;
}
case 1:
{
if (Low<High[LastExtremumHighBar])
{
long=Low;
LastExtremumLowBar=i;
}
break;
}
case 0:
{
long=Low;
LastExtremumLowBar=i;
break;
}
}
}

if (i==Highest(Symbol(),Period(),MODE_HIGH,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide) && long==0)
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case 1:
{
if (High>High[LastExtremumHighBar])
{
short=High;
short[LastExtremumHighBar]=0;
LastExtremumHighBar=i;
}
break;
}
case -1:
{
if (High>Low[LastExtremumLowBar])
{
short=High;
LastExtremumHighBar=i;
}
break;
}
case 0:
{
short=High;
LastExtremumHighBar=i;
break;
}
}
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (long==Low)
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==-1)
if (High[j]>Low+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
Stop=j;
if (CurrState==0)
if (Low[j]<Low+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
CurrState=-1;
}
if (Stop!=-1)
LevelLength=i-Stop;
else
LevelLength=i;
}

if (short==High)
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==1)
if (Low[j]<High+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
Stop=j;
if (CurrState==0)
if (High[j]>High+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
CurrState=1;
}
if (Stop!=-1)
LevelLength=i-Stop;
else
LevelLength=i;
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (LevelLength>0)
{
if (long!=0)
iFractalValue=long;
if (short!=0)
iFractalValue=short;
BarsToCheck=MathMin(LevelActuality,LevelLength);
j=i-1;
LevelLength=BarsToCheck;
while (BarsToCheck>0)
{
if (LevelLength[j]>0)
{
if (long[j]!=0)
jFractalValue=long[j];
if (short[j]!=0)
jFractalValue=short[j];

if (MathAbs(iFractalValue+(i-j)*PriceDeltaFor1Bar*Point-jFractalValue)<ExtremumToLevelMaxGap*Point)
{
BarsToCheck=MathMin(LevelActuality,LevelLength[j]);
LevelLength=i-j+BarsToCheck;
LevelLength[j]=0;
LevelWidth++;
if (SnapExtremumsToLevelOnChar==1)
{
if (long[j]!=0)
{
long[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
if (short[j]!=0)
{
short[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
}
}
}
BarsToCheck--;
j--;
}
}
}

//+------------------------------------------------------------------+
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (long!=0 || short!=0)
{
if (LastExtremumBar!=-1)
{
if (long!=0)
{
ObjectCreate(StringConcatenate("Trend_",i),OBJ_TREND,0,
Time[LastExtremumBar],short[LastExtremumBar],Time,long);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_COLOR,TrendDownColor);

//+---------+
int barshift1 = iBarShift( NULL, 0, Time[LastExtremumBar], false) ;
int barshift2 = iBarShift( NULL, 0, short[LastExtremumBar], false) ;
double volumeSum = 0.0;
for (int i2 = barshift1; i2 <= barshift2; i2++)
{
volumeSum = volumeSum + Volume;
}
string label = TimeToStr(Time[LastExtremumBar]) + TimeToStr(short[LastExtremumBar]) + MathRand();
double ordVolume = volumeSum/((barshift2 - barshift1) + 1);

if(ObjectCreate(label,OBJ_TEXT,0,Time[LastExtremumBar],Open[barshift1],0,0,0,0))
ObjectSetText(label,DoubleToStr(ordVolume,0),19,"Tahoma",Yellow);


}
if (short!=0)
{
ObjectCreate(StringConcatenate("Trend_",i),OBJ_TREND,0,
Time[LastExtremumBar],long[LastExtremumBar],Time,short);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_COLOR,TrendUpColor);
}
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_RAY,0);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_WIDTH,1);

//+---------+
int barshift1a = iBarShift( NULL, 0, Time[LastExtremumBar], false) ;
int barshift2a = iBarShift( NULL, 0, long[LastExtremumBar], false) ;
double volumeSum2 = 0.0;
for (int i3 = barshift1a; i3 <= barshift2a; i3++)
{
volumeSum2 = volumeSum2 + Volume;
}
string labela = TimeToStr(Time[LastExtremumBar]) + TimeToStr(long[LastExtremumBar]) + MathRand();
double ordVolume2 = volumeSum2/((barshift2a - barshift1a) + 1);

if(ObjectCreate(labela,OBJ_TEXT,0,Time[LastExtremumBar],Open[barshift1a],0,0,0,0))
ObjectSetText(labela,DoubleToStr(ordVolume2,0),19,"Tahoma",Yellow);

}
LastExtremumBar=i;
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (LevelLength!=0)
{
if (long!=0)
iFractalValue=long;
if (short!=0)
iFractalValue=short;

ObjectCreate(StringConcatenate("Level_",i),OBJ_TREND,0,
Time,iFractalValue,Time[i-LevelLength],iFractalValue+LevelLength*PriceDeltaFor1Bar*Point);
ObjectSet(StringConcatenate("Level_",i),OBJPROP_RAY,0);
if (LevelWidth>1)
{
ObjectSet(StringConcatenate("Level_",i),OBJPROP_WIDTH,MathMin(LevelWidth,5));
if (LevelWidth==2)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,LightGray);
if (LevelWidth==3)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,Silver);
if (LevelWidth==4)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,DarkGray);
if (LevelWidth>=5)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,Gray);
}
else
{
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,LightGray);
ObjectSet(StringConcatenate("Level_",i),OBJPROP_STYLE,STYLE_DOT);
}
}
}

return(0);
}

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

KelvinHand

Well-Known Member
#7
Hi any body can correct this code below not working. thanks a lot.

//+------------------------------------------------------------------+
//| VOLUME SWINGS & SR LEVELS.mq4 |
//| Copyright © 2008, FOREXflash. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, FOREXflash"
#property link "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue


extern color TrendUpColor=Blue;
extern color TrendDownColor=Red;
extern bool SnapExtremumsToLevelOnChar=True;
extern int FractalBarsOnEachSide=5;
extern int ProceedMaxHistoryBars=1000;
extern int LevelActuality=160;
extern bool RestDefaultTimeframeValues=1;
extern int ExtremumToLevelMaxGap=100;
extern double PriceDeltaFor1Bar=20;

int LevelLength[];
int LevelWidth[];
int PriceCrossedLevel;
double long[];
double short[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
ObjectsDeleteAll();
IndicatorBuffers(2);
SetIndexBuffer(0,long);
SetIndexBuffer(1,short);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
int i=0;

for (i=Bars-1;i>=0;i--)
if (ObjectFind("Level_"+i)!=-1)
ObjectDelete("Level_"+i);
for (i=Bars-1;i>=0;i--)
if (ObjectFind("Trend_"+i)!=-1)
ObjectDelete("Trend_"+i);
return(0);
}
//+-------------------------------------------+
int LastBarWasHighLow(int LELB, int LEHB)
{
if (LELB==-1 && LEHB!=-1)
return(1);
if (LELB!=-1 && LEHB==-1)
return(-1);
if (LELB!=-1 && LEHB!=-1 && LELB>LEHB)
return(1);
if (LELB!=-1 && LEHB!=-1 && LELB<LEHB)
return(-1);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,j;
int BarsToCheck;
int Stop;
int CurrState;
int LastExtremumHighBar=-1;
int LastExtremumLowBar=-1;
int LastExtremumBar=-1;
double iFractalValue=0,jFractalValue=0;

SetIndexStyle(0,DRAW_ARROW,0,3);
SetIndexArrow(0,159);
SetIndexStyle(1,DRAW_ARROW,0,3);
SetIndexArrow(1,159);
ArrayInitialize(long,0);
ArrayInitialize(short,0);

if (RestDefaultTimeframeValues==1)
{
switch (Period())
{
case 1:
{
ExtremumToLevelMaxGap=2;
PriceDeltaFor1Bar=0.2;
break;
}
case 5:
{
ExtremumToLevelMaxGap=5;
PriceDeltaFor1Bar=0.2;
break;
}
case 15:
{
ExtremumToLevelMaxGap=8;
PriceDeltaFor1Bar=0.2;
break;
}
case 30:
{
ExtremumToLevelMaxGap=10;
PriceDeltaFor1Bar=0.3;
break;
}
case 60:
{
ExtremumToLevelMaxGap=15;
PriceDeltaFor1Bar=0.4;
break;
}
case 240:
{
ExtremumToLevelMaxGap=25;
PriceDeltaFor1Bar=0.4;
break;
}
case 1440:
{
ExtremumToLevelMaxGap=75;
PriceDeltaFor1Bar=1.5;
break;
}
case 10080:
{
ExtremumToLevelMaxGap=150;
PriceDeltaFor1Bar=5;
break;
}
case 43200:
{
ExtremumToLevelMaxGap=300;
PriceDeltaFor1Bar=24;
break;
}
}
}
//+------------------------------------------------------------------+
PriceCrossedLevel=ExtremumToLevelMaxGap*2;

ArrayResize(LevelLength,Bars);
ArrayInitialize(LevelLength,0);
ArrayResize(LevelWidth,Bars);
ArrayInitialize(LevelWidth,1);

if (FractalBarsOnEachSide<=0)
FractalBarsOnEachSide=1;


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{

if (i==Lowest(Symbol(),Period(),MODE_LOW,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide))
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case -1:
{
if (Low<Low[LastExtremumLowBar])
{
long=Low;
long[LastExtremumLowBar]=0;
LastExtremumLowBar=i;
}
break;
}
case 1:
{
if (Low<High[LastExtremumHighBar])
{
long=Low;
LastExtremumLowBar=i;
}
break;
}
case 0:
{
long=Low;
LastExtremumLowBar=i;
break;
}
}
}

if (i==Highest(Symbol(),Period(),MODE_HIGH,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide) && long==0)
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case 1:
{
if (High>High[LastExtremumHighBar])
{
short=High;
short[LastExtremumHighBar]=0;
LastExtremumHighBar=i;
}
break;
}
case -1:
{
if (High>Low[LastExtremumLowBar])
{
short=High;
LastExtremumHighBar=i;
}
break;
}
case 0:
{
short=High;
LastExtremumHighBar=i;
break;
}
}
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (long==Low)
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==-1)
if (High[j]>Low+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
Stop=j;
if (CurrState==0)
if (Low[j]<Low+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
CurrState=-1;
}
if (Stop!=-1)
LevelLength=i-Stop;
else
LevelLength=i;
}

if (short==High)
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==1)
if (Low[j]<High+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
Stop=j;
if (CurrState==0)
if (High[j]>High+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
CurrState=1;
}
if (Stop!=-1)
LevelLength=i-Stop;
else
LevelLength=i;
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (LevelLength>0)
{
if (long!=0)
iFractalValue=long;
if (short!=0)
iFractalValue=short;
BarsToCheck=MathMin(LevelActuality,LevelLength);
j=i-1;
LevelLength=BarsToCheck;
while (BarsToCheck>0)
{
if (LevelLength[j]>0)
{
if (long[j]!=0)
jFractalValue=long[j];
if (short[j]!=0)
jFractalValue=short[j];

if (MathAbs(iFractalValue+(i-j)*PriceDeltaFor1Bar*Point-jFractalValue)<ExtremumToLevelMaxGap*Point)
{
BarsToCheck=MathMin(LevelActuality,LevelLength[j]);
LevelLength=i-j+BarsToCheck;
LevelLength[j]=0;
LevelWidth++;
if (SnapExtremumsToLevelOnChar==1)
{
if (long[j]!=0)
{
long[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
if (short[j]!=0)
{
short[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
}
}
}
BarsToCheck--;
j--;
}
}
}

//+------------------------------------------------------------------+
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (long!=0 || short!=0)
{
if (LastExtremumBar!=-1)
{
if (long!=0)
{
ObjectCreate(StringConcatenate("Trend_",i),OBJ_TREND,0,
Time[LastExtremumBar],short[LastExtremumBar],Time,long);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_COLOR,TrendDownColor);

//+---------+
int barshift1 = iBarShift( NULL, 0, Time[LastExtremumBar], false) ;
int barshift2 = iBarShift( NULL, 0, short[LastExtremumBar], false) ;
double volumeSum = 0.0;
for (int i2 = barshift1; i2 <= barshift2; i2++)
{
volumeSum = volumeSum + Volume;
}
string label = TimeToStr(Time[LastExtremumBar]) + TimeToStr(short[LastExtremumBar]) + MathRand();
double ordVolume = volumeSum/((barshift2 - barshift1) + 1);

if(ObjectCreate(label,OBJ_TEXT,0,Time[LastExtremumBar],Open[barshift1],0,0,0,0))
ObjectSetText(label,DoubleToStr(ordVolume,0),19,"Tahoma",Yellow);


}
if (short!=0)
{
ObjectCreate(StringConcatenate("Trend_",i),OBJ_TREND,0,
Time[LastExtremumBar],long[LastExtremumBar],Time,short);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_COLOR,TrendUpColor);
}
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_RAY,0);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_WIDTH,1);

//+---------+
int barshift1a = iBarShift( NULL, 0, Time[LastExtremumBar], false) ;
int barshift2a = iBarShift( NULL, 0, long[LastExtremumBar], false) ;
double volumeSum2 = 0.0;
for (int i3 = barshift1a; i3 <= barshift2a; i3++)
{
volumeSum2 = volumeSum2 + Volume;
}
string labela = TimeToStr(Time[LastExtremumBar]) + TimeToStr(long[LastExtremumBar]) + MathRand();
double ordVolume2 = volumeSum2/((barshift2a - barshift1a) + 1);

if(ObjectCreate(labela,OBJ_TEXT,0,Time[LastExtremumBar],Open[barshift1a],0,0,0,0))
ObjectSetText(labela,DoubleToStr(ordVolume2,0),19,"Tahoma",Yellow);

}
LastExtremumBar=i;
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (LevelLength!=0)
{
if (long!=0)
iFractalValue=long;
if (short!=0)
iFractalValue=short;

ObjectCreate(StringConcatenate("Level_",i),OBJ_TREND,0,
Time,iFractalValue,Time[i-LevelLength],iFractalValue+LevelLength*PriceDeltaFor1Bar*Point);
ObjectSet(StringConcatenate("Level_",i),OBJPROP_RAY,0);
if (LevelWidth>1)
{
ObjectSet(StringConcatenate("Level_",i),OBJPROP_WIDTH,MathMin(LevelWidth,5));
if (LevelWidth==2)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,LightGray);
if (LevelWidth==3)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,Silver);
if (LevelWidth==4)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,DarkGray);
if (LevelWidth>=5)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,Gray);
}
else
{
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,LightGray);
ObjectSet(StringConcatenate("Level_",i),OBJPROP_STYLE,STYLE_DOT);
}
}
}

return(0);
}

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


This problem very easy to solve. I cannot help you nowaday.
 
Last edited:
#8
Hi any body can correct this code below not working. thanks a lot.


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

HTML:
//+------------------------------------------------------------------+
//| VOLUME SWINGS & SR LEVELS.mq4 |
//| Copyright © 2008, FOREXflash. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, FOREXflash"
#property link "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue


extern color TrendUpColor=Blue;
extern color TrendDownColor=Red;
extern bool SnapExtremumsToLevelOnChar=True;
extern int FractalBarsOnEachSide=5;
extern int ProceedMaxHistoryBars=1000;
extern int LevelActuality=160;
extern bool RestDefaultTimeframeValues=1;
extern int ExtremumToLevelMaxGap=100;
extern double PriceDeltaFor1Bar=20;

int LevelLength[];
int LevelWidth[];
int PriceCrossedLevel;
double _Long[];
double _Short[];
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function | 
//+------------------------------------------------------------------+
int init()
{
ObjectsDeleteAll();
IndicatorBuffers(2);
SetIndexBuffer(0,_Long);
SetIndexBuffer(1,_Short);
return(0);
}
//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function | 
//+------------------------------------------------------------------+
int deinit()
{
int i=0;

for (i=Bars-1;i>=0;i--)
if (ObjectFind("Level_"+i)!=-1)
ObjectDelete("Level_"+i);
for (i=Bars-1;i>=0;i--)
if (ObjectFind("Trend_"+i)!=-1)
ObjectDelete("Trend_"+i);
return(0);
}
//+-------------------------------------------+ 
int LastBarWasHighLow(int LELB, int LEHB)
{
if (LELB==-1 && LEHB!=-1)
return(1); 
if (LELB!=-1 && LEHB==-1)
return(-1); 
if (LELB!=-1 && LEHB!=-1 && LELB>LEHB) 
return(1);
if (LELB!=-1 && LEHB!=-1 && LELB<LEHB) 
return(-1);
return(0);
}
//+------------------------------------------------------------------+ 
//| Custom indicator iteration function | 
//+------------------------------------------------------------------+
int start()
{
int i,j;
int BarsToCheck;
int Stop;
int CurrState; 
int LastExtremumHighBar=-1;
int LastExtremumLowBar=-1;
int LastExtremumBar=-1;
double iFractalValue=0,jFractalValue=0;

SetIndexStyle(0,DRAW_ARROW,0,3);
SetIndexArrow(0,159);
SetIndexStyle(1,DRAW_ARROW,0,3);
SetIndexArrow(1,159);
ArrayInitialize(_Long,0);
ArrayInitialize(_Short,0);

if (RestDefaultTimeframeValues==1)
{
switch (Period())
{
case 1:
{
ExtremumToLevelMaxGap=2;
PriceDeltaFor1Bar=0.2;
break;
} 
case 5:
{
ExtremumToLevelMaxGap=5;
PriceDeltaFor1Bar=0.2;
break;
}
case 15:
{
ExtremumToLevelMaxGap=8;
PriceDeltaFor1Bar=0.2;
break;
}
case 30:
{
ExtremumToLevelMaxGap=10;
PriceDeltaFor1Bar=0.3;
break;
}
case 60:
{
ExtremumToLevelMaxGap=15;
PriceDeltaFor1Bar=0.4;
break;
}
case 240:
{
ExtremumToLevelMaxGap=25;
PriceDeltaFor1Bar=0.4;
break;
}
case 1440:
{
ExtremumToLevelMaxGap=75;
PriceDeltaFor1Bar=1.5;
break;
}
case 10080:
{
ExtremumToLevelMaxGap=150;
PriceDeltaFor1Bar=5;
break;
} 
case 43200:
{
ExtremumToLevelMaxGap=300;
PriceDeltaFor1Bar=24;
break;
}
}
}
//+------------------------------------------------------------------+ 
PriceCrossedLevel=ExtremumToLevelMaxGap*2;

ArrayResize(LevelLength,Bars);
ArrayInitialize(LevelLength,0);
ArrayResize(LevelWidth,Bars);
ArrayInitialize(LevelWidth,1);

if (FractalBarsOnEachSide<=0)
FractalBarsOnEachSide=1;


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{

if (i==Lowest(Symbol(),Period(),MODE_LOW,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide))
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case -1:
{
if (Low[i]<Low[LastExtremumLowBar])
{
_Long[i]=Low[i];
_Long[LastExtremumLowBar]=0;
LastExtremumLowBar=i;
}
break;
}
case 1:
{
if (Low[i]<High[LastExtremumHighBar])
{
_Long[i]=Low[i];
LastExtremumLowBar=i;
}
break;
}
case 0:
{
_Long[i]=Low[i];
LastExtremumLowBar=i;
break;
}
}
}

if (i==Highest(Symbol(),Period(),MODE_HIGH,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide) && _Long[i]==0)
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case 1:
{
if (High[i]>High[LastExtremumHighBar])
{
_Short[i]=High[i];
_Short[LastExtremumHighBar]=0;
LastExtremumHighBar=i;
}
break;
}
case -1:
{
if (High[i]>Low[LastExtremumLowBar])
{
_Short[i]=High[i];
LastExtremumHighBar=i;
}
break;
}
case 0:
{
_Short[i]=High[i];
LastExtremumHighBar=i;
break;
}
}
}
} 


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (_Long[i]==Low[i])
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==-1)
if (High[j]>Low[i]+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point )
Stop=j;
if (CurrState==0)
if (Low[j]<Low[i]+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
CurrState=-1;
}
if (Stop!=-1)
LevelLength[i]=i-Stop;
else
LevelLength[i]=i;
}

if (_Short[i]==High[i])
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==1)
if (Low[j]<High[i]+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
Stop=j;
if (CurrState==0)
if (High[j]>High[i]+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point )
CurrState=1;
}
if (Stop!=-1)
LevelLength[i]=i-Stop;
else
LevelLength[i]=i;
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{ 
if (LevelLength[i]>0)
{
if (_Long[i]!=0)
iFractalValue=_Long[i];
if (_Short[i]!=0)
iFractalValue=_Short[i];
BarsToCheck=MathMin(LevelActuality,LevelLength[i]);
j=i-1;
LevelLength[i]=BarsToCheck;
while (BarsToCheck>0)
{ 
if (LevelLength[j]>0)
{
if (_Long[j]!=0)
jFractalValue=_Long[j];
if (_Short[j]!=0)
jFractalValue=_Short[j];

if (MathAbs(iFractalValue+(i-j)*PriceDeltaFor1Bar*Point-jFractalValue)<ExtremumToLevelMaxGap*Point)
{
BarsToCheck=MathMin(LevelActuality,LevelLength[j]);
LevelLength[i]=i-j+BarsToCheck;
LevelLength[j]=0;
LevelWidth[i]++;
if (SnapExtremumsToLevelOnChar==1)
{
if (_Long[j]!=0)
{
_Long[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
if (_Short[j]!=0)
{
_Short[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
}
}
}
BarsToCheck--;
j--;
}
}
}

//+------------------------------------------------------------------+
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (_Long[i]!=0 || _Short[i]!=0)
{
if (LastExtremumBar!=-1)
{
if (_Long[i]!=0)
{
ObjectCreate(StringConcatenate("Trend_",i),OBJ_TREND,0,
Time[LastExtremumBar],_Short[LastExtremumBar],Time[i],_Long[i]);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_COLOR,TrendDownColor);

//+---------+ 
int barshift1 = iBarShift( NULL, 0, Time[LastExtremumBar], false) ;
int barshift2 = iBarShift( NULL, 0, _Short[LastExtremumBar], false) ;
double volumeSum = 0.0;
for (int i2 = barshift1; i2 <= barshift2; i2++)
{
volumeSum = volumeSum + Volume[i];
}
string label = TimeToStr(Time[LastExtremumBar]) + TimeToStr(_Short[LastExtremumBar]) + MathRand();
double ordVolume = volumeSum/((barshift2 - barshift1) + 1);

if(ObjectCreate(label,OBJ_TEXT,0,Time[LastExtremumBar],Open[barshift1],0,0,0,0))
ObjectSetText(label,DoubleToStr(ordVolume,0),19,"T ahoma",Yellow);


}
if (_Short[i]!=0)
{
ObjectCreate(StringConcatenate("Trend_",i),OBJ_TREND,0,
Time[LastExtremumBar],_Long[LastExtremumBar],Time[i],_Short[i]);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_COLOR,TrendUpColor);
}
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_RAY,0);
ObjectSet(StringConcatenate("Trend_",i),OBJPROP_WIDTH,1);

//+---------+ 
int barshift1a = iBarShift( NULL, 0, Time[LastExtremumBar], false) ;
int barshift2a = iBarShift( NULL, 0, _Long[LastExtremumBar], false) ;
double volumeSum2 = 0.0;
for (int i3 = barshift1a; i3 <= barshift2a; i3++)
{
volumeSum2 = volumeSum2 + Volume[i];
}
string labela = TimeToStr(Time[LastExtremumBar]) + TimeToStr(_Long[LastExtremumBar]) + MathRand();
double ordVolume2 = volumeSum2/((barshift2a - barshift1a) + 1);

if(ObjectCreate(labela,OBJ_TEXT,0,Time[LastExtremumBar],Open[barshift1a],0,0,0,0))
ObjectSetText(labela,DoubleToStr(ordVolume2,0),19, "Tahoma",Yellow);

}
LastExtremumBar=i;
}
}


for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{ 
if (LevelLength[i]!=0)
{
if (_Long[i]!=0)
iFractalValue=_Long[i];
if (_Short[i]!=0)
iFractalValue=_Short[i];

ObjectCreate(StringConcatenate("Level_",i),OBJ_TREND,0,
Time[i],iFractalValue,Time[i-LevelLength[i]],iFractalValue+LevelLength[i]*PriceDeltaFor1Bar*Point);
ObjectSet(StringConcatenate("Level_",i),OBJPROP_RAY,0);
if (LevelWidth[i]>1)
{
ObjectSet(StringConcatenate("Level_",i),OBJPROP_WIDTH,MathMin(LevelWidth[i],5));
if (LevelWidth[i]==2)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,LightGray);
if (LevelWidth[i]==3)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,Silver);
if (LevelWidth[i]==4)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,DarkGray);
if (LevelWidth[i]>=5)
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,Gray);
}
else
{
ObjectSet(StringConcatenate("Level_",i),OBJPROP_COLOR,LightGray);
ObjectSet(StringConcatenate("Level_",i),OBJPROP_STYLE,STYLE_DOT);
}
}
}

return(0);
}
 
Last edited:

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?