Request SnR Indicator Based On Volume - page 2

 
mladen:
Is that the whole code?

If yes, metatrader is treating it as an EA or a script (since none of the indicator properties is stated in the code). Neiter in the EA nor in the script, IndicatorCounted() is not going to work (that is a function specific to indicators)

If no (if that is not the complete code), please post the complete code

No, is not complete code. I'm sorry for that.

Here's the complete code:

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

//| MVC-Highest.mq4 |

//| Copyright © 2015, pije76. |

//| https://www.forex-tsd.com/members/pije76.html |

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

#property copyright "Copyright © 2015, pije76"

#property link "https://www.forex-tsd.com/members/pije76.html"

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_buffers 1

#property indicator_color1 Blue

#property indicator_width1 2

extern int NumberOfBars = 100;

extern int ControlOfBars = 24;

extern int NumberOfHighs = 3;

//1st step: Define a two dimensional array

//double ArrayVolume[];

double ArrayVolume[][2];

double HighestColor[];

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

//| Custom indicator initialization function |

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

int init()

{

SetIndexBuffer(0, UpColor);

SetIndexStyle(0, DRAW_HISTOGRAM);

SetIndexLabel(0, NULL);

SetIndexEmptyValue(0, 0.0);

IndicatorShortName("MVC-Highest");

IndicatorDigits(0);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int tahun = 0;

int bulan = 0;

int hari = 0;

int menit = 0;

int jam = 0;

int shift = 0;

int tjam=0, tmenit=0;

int timeframe = 1440;

string tanggal = "";

datetime currentbartime = 0;

double tVolume;

int Limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--; //always count the previous bar

if ( NumberOfBars == 0 )

NumberOfBars = Bars-counted_bars;

Limit=NumberOfBars;

//2nd step: Inside main loop, add condition here to check for Hour == 0

while(Limit>=0)

{

tahun=TimeYear(Time[Limit]);

bulan=TimeMonth(Time[Limit]);

hari=TimeDay(Time[Limit]);

jam = TimeHour(Time[Limit]);

menit = TimeMinute(Time[Limit]);

tanggal = tahun + "." + bulan + "." + hari + " " + jam + ":" + menit;

currentbartime = StrToTime(tanggal);

shift = iBarShift(NULL,timeframe,currentbartime);

tjam = TimeHour(iTime(NULL,60,iBarShift(NULL,60,currentbartime)));

tmenit = TimeMinute(iTime(NULL,Period(),Limit));

//start at hour ==0

if(tjam == 0 && tmenit == 0)

{

ArrayResize(ArrayVolume, Limit, 0);

tVolume=Volume[Limit];

//3rd step: Set up another "for loop" length = 24 as there are 24 candles in a day for H1

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

{

// 4th step: Populate the Array with volume and candle index

jVolume = Volume[j];

//we will need a counter to keep track of where we are in the candle array going right to left so IndexCount=i+j

//also we will need and int to populate the array Count

//HighestVolume[Count][0] = Volume;

//HighestVolume[Count][1] = IndexCount;

//then increment after each element

//Count++;

}//end of "j for" loop

//5th step: Sort the Array

ArraySort(ArrayVolume, WHOLE_ARRAY, 0, MODE_DESCEND);

}//end of "if"

Limit--;

//6th step: Define a function to draw a trend line

}//end of "while"

//7th step: Set up a second "for loop" with the length equal to the number of highs to display on the chart with lines

for (int k=0; k<NumberOfHighs; k++)

{

//if (kVolume == 0);

//{

//then read the array elements

// Price1 = HighestVolume[k][0];

// Index1 = HighestVolume[k][1];

//8th step: call the draw trend line function using price and candle index as parameters to draw the trend line

Print("BarIndex",Limit," Volume: ",tVolume);

HighestColor[Limit]=tVolume;

//}

}//end of "k for" loop

return(0);

}

 
pije76:
No, is not complete code. I'm sorry for that.

Here's the complete code:

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

//| MVC-Highest.mq4 |

//| Copyright © 2015, pije76. |

//| https://www.forex-tsd.com/members/pije76.html |

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

#property copyright "Copyright © 2015, pije76"

#property link "https://www.forex-tsd.com/members/pije76.html"

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_buffers 1

#property indicator_color1 Blue

#property indicator_width1 2

extern int NumberOfBars = 100;

extern int ControlOfBars = 24;

extern int NumberOfHighs = 3;

//1st step: Define a two dimensional array

//double ArrayVolume[];

double ArrayVolume[][2];

double HighestColor[];

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

//| Custom indicator initialization function |

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

int init()

{

SetIndexBuffer(0, UpColor);

SetIndexStyle(0, DRAW_HISTOGRAM);

SetIndexLabel(0, NULL);

SetIndexEmptyValue(0, 0.0);

IndicatorShortName("MVC-Highest");

IndicatorDigits(0);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int tahun = 0;

int bulan = 0;

int hari = 0;

int menit = 0;

int jam = 0;

int shift = 0;

int tjam=0, tmenit=0;

int timeframe = 1440;

string tanggal = "";

datetime currentbartime = 0;

double tVolume;

int Limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--; //always count the previous bar

if ( NumberOfBars == 0 )

NumberOfBars = Bars-counted_bars;

Limit=NumberOfBars;

//2nd step: Inside main loop, add condition here to check for Hour == 0

while(Limit>=0)

{

tahun=TimeYear(Time[Limit]);

bulan=TimeMonth(Time[Limit]);

hari=TimeDay(Time[Limit]);

jam = TimeHour(Time[Limit]);

menit = TimeMinute(Time[Limit]);

tanggal = tahun + "." + bulan + "." + hari + " " + jam + ":" + menit;

currentbartime = StrToTime(tanggal);

shift = iBarShift(NULL,timeframe,currentbartime);

tjam = TimeHour(iTime(NULL,60,iBarShift(NULL,60,currentbartime)));

tmenit = TimeMinute(iTime(NULL,Period(),Limit));

//start at hour ==0

if(tjam == 0 && tmenit == 0)

{

ArrayResize(ArrayVolume, Limit, 0);

tVolume=Volume[Limit];

//3rd step: Set up another "for loop" length = 24 as there are 24 candles in a day for H1

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

{

// 4th step: Populate the Array with volume and candle index

jVolume = Volume[j];

//we will need a counter to keep track of where we are in the candle array going right to left so IndexCount=i+j

//also we will need and int to populate the array Count

//HighestVolume[Count][0] = Volume;

//HighestVolume[Count][1] = IndexCount;

//then increment after each element

//Count++;

}//end of "j for" loop

//5th step: Sort the Array

ArraySort(ArrayVolume, WHOLE_ARRAY, 0, MODE_DESCEND);

}//end of "if"

Limit--;

//6th step: Define a function to draw a trend line

}//end of "while"

//7th step: Set up a second "for loop" with the length equal to the number of highs to display on the chart with lines

for (int k=0; k<NumberOfHighs; k++)

{

//if (kVolume == 0);

//{

//then read the array elements

// Price1 = HighestVolume[k][0];

// Index1 = HighestVolume[k][1];

//8th step: call the draw trend line function using price and candle index as parameters to draw the trend line

Print("BarIndex",Limit," Volume: ",tVolume);

HighestColor[Limit]=tVolume;

//}

}//end of "k for" loop

return(0);

}

OK

Will check it and will get back with a conclusion (and a solution, if I find one). OK?

 
mladen:
OK Will check it and will get back with a conclusion (and a solution, if I find one). OK?

Okay,

And thank you so much for your help Mladen...

 

Current condition, I can get the 3 highest volume histogram but it always display that histogram on 3 last histogram only (it's not right position on the right histograms, as we can see on the image that show: Bar index: 0, Volume: 12761).

How to draw all of highest volume bars for previous days on the right position?

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

//| MVC-Highest.mq4 |

//| Copyright © 2015, pije76. |

//| https://www.forex-tsd.com/members/pije76.html |

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

#property copyright "Copyright © 2015, pije76"

#property link "https://www.forex-tsd.com/members/pije76.html"

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_buffers 1

#property indicator_color1 Blue

#property indicator_width1 2

extern int NumberOfBars = 100;

extern int ControlOfBars = 25;

extern int NumberOfHighs = 3;

//1st step: Define a two dimensional array

double ArrayVolume[];

//double ArrayVolume[][2]; //[0] contains the volume index & [1] contains the candle index

double iVolume, jVolume, kVolume;

double HighestColor[];

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

//| Custom indicator initialization function |

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

int init()

{

SetIndexBuffer(0, HighestColor);

SetIndexStyle(0, DRAW_HISTOGRAM);

SetIndexLabel(0, NULL);

SetIndexEmptyValue(0, 0.0);

IndicatorShortName("MVC-Highest");

IndicatorDigits(0);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

double iVolume, jVolume, kVolume;

int bulan = 0;

int hari = 0;

int tahun = 0;

string tanggal = "";

// datetime thisbartime = 0;

datetime thisbartime[];

int shift = 0;

int time_frame = 1440;

int min = 0;

int jam = 0;

int thour=0, tmin=0;

int Limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--; //always count the previous bar

if ( NumberOfBars == 0 )

NumberOfBars = Bars-counted_bars;

Limit=NumberOfBars;

bulan=TimeMonth(Time[NumberOfBars]);

hari=TimeDay(Time[NumberOfBars]);

tahun=TimeYear(Time[NumberOfBars]);

min = TimeMinute(Time[NumberOfBars]);

jam = TimeHour(Time[NumberOfBars]);

tanggal = tahun + "." + bulan + "." + hari + " " + jam + ":" + min;

// thisbartime = StrToTime(tanggal);

// shift = iBarShift(NULL,time_frame,thisbartime); //returns the correct shift of the current daily bar

// thour = TimeHour(iTime(NULL,60,iBarShift(NULL,60,thisbartime)));

tmin = TimeMinute(iTime(NULL,Period(),NumberOfBars));

ArrayCopySeries(thisbartime,MODE_TIME,Symbol(),1440);

for(int i=0, t=0; i<Limit; i++)

// for(int i=0; i<Limit; i++)

{

//2nd step: Inside main loop, add condition here to check for Hour == 0

if (Time<thisbartime[t]) t++;

//if(thour == 0 && tmin == 0)

{

ArrayResize(ArrayVolume, Limit, 0);

//3rd step: Set up another "for loop" length = 24 as there are 24 candles in a day for H1

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

{

// 4th step: Populate the Array with volume index

ArrayVolume[j] = Volume[j];

//ArrayVolume[j] = Volume[j];

//j++;

} // end of "j for" loop

} // end of "if" condition for hour == 0

//5th step: Sort the Array

ArraySort(ArrayVolume, WHOLE_ARRAY, 0, MODE_DESCEND);

//jVolume = ArrayVolume[j];

}// end of "i for" loop

//6th step: Define a function to draw a trend line

//7th step: Set up a second "for loop" with the length equal to the number of highs to display on the chart with lines

for (int k=0; k<NumberOfHighs; k++)

{

//if (ArrayResize(ArrayVolume) > 0) ArraySort(ArrayVolume, WHOLE_ARRAY, 0, MODE_DESCEND);

//{

kVolume = ArrayVolume[k];

//8th step: call the draw trend line function using price and candle index as parameters to draw the trend line

Print("BarIndex: ", k, ", Value: ", kVolume);

HighestColor[k]=kVolume;

//} //end of "if" condition

}//end of "k for" loop

return(0);

}

 

Hi Mladen,

Now the 1st step almost finish, but I can't draw the lowest volume histogram and fill in with Red color. And also it's not draw the highest volume histogram on current/last day.

How to draw the lowest histogram on all of previous days? And how to draw the highest volume histogram on the current/last day?

Here's the current code:

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

//| MVC-Highest.mq4 |

//| Copyright 2015, pije76. |

//| https://www.forex-tsd.com/members/pije76.html |

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

#property copyright "Copyright 2015, pije76"

#property link "https://www.forex-tsd.com/members/pije76.html"

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_width1 2

#property indicator_color2 Red

#property indicator_width2 2

extern int NumberOfBars = 200;

extern int ControlOfBars = 25;

extern int NumberOfHighs = 3;

double ArrayVolume[][2]; //[0] contains the volume index & [1] contains the bar index

double HighestColor[], LowestColor[];

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

//| Custom indicator initialization function |

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

int init()

{

SetIndexBuffer(0, HighestColor);

SetIndexStyle(0, DRAW_HISTOGRAM);

SetIndexLabel(0, NULL);

SetIndexEmptyValue(0, 0.0);

SetIndexBuffer(1, LowestColor);

SetIndexStyle(1, DRAW_HISTOGRAM);

SetIndexLabel(1, NULL);

SetIndexEmptyValue(0, 0.0);

IndicatorShortName("MVC-Highest");

IndicatorDigits(0);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

double iVolume, jVolume, kVolume;

int kIndex;

//-----//define 2 counters

int cnt=0;

int ij=0;

int Limit;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--; //always count the previous bar

if ( NumberOfBars == 0 )

NumberOfBars = Bars-counted_bars;

Limit=NumberOfBars;

// Limit=100;

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

{

if(TimeHour(Time) == 0)

{

ArrayResize(ArrayVolume, Limit, 0);

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

{

ij=i+j;

ArrayVolume[cnt][0] = Volume;

ArrayVolume[cnt][1] = ij;

cnt++;

} // end of "j for" loop

ArraySort(ArrayVolume, WHOLE_ARRAY, 0, MODE_DESCEND);

for (int k=0; k<NumberOfHighs; k++)

{

kVolume = ArrayVolume[k][0];

kIndex = ArrayVolume[k][1];

Print("Highest_BarIndex: ", kIndex, ", Value: ", kVolume);

HighestColor[kIndex]=kVolume;

}//end of "k for" loop

} // end of "if" condition for hour == 0

ArrayResize(ArrayVolume,0,0);

}// end of "i for" loop

return(0);

}

Reason: