Not possible to display Volume correctly

 

I'm trying to use Volume information to sneak trading signal info to MT4. Here is my code

//---- indicator settings

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_maximum 12

#property indicator_buffers 2

#property indicator_color1 Silver

#property indicator_color2 Red

#property indicator_width1 2

//---- indicator parameters

extern int period=9;

//---- indicator buffers

double Signal[];

double SignalMA[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- drawing settings

SetIndexStyle(0,DRAW_LINE);

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,period);

//---- indicator buffers mapping

SetIndexBuffer(0,Signal);

SetIndexBuffer(1,SignalMA);

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("Signal");

SetIndexLabel(0,"Signal");

SetIndexLabel(1,"SignalMA");

//---- initialization done

return(0);

}

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

//| |

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

int start()

{

int limit, i;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

ArrayResize(Signal, limit); //resize the array to the number of bars

ArraySetAsSeries(Volume,true);

// ArraySetAsSeries(Signal,true);

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

Signal=Volume;

Print(Signal[0],Signal[1],Signal[2],Signal[3],Signal[4],Signal[5]);

//---- done

return(0);

}

The Volume info is not displayed. When i replace Volume with Close, Close is properly displayed.

Volume is only displayed when ArraySetAsSeries(Signal,false) but in this case is displayed in reverse order.

Volume data is put to signal array in proper order (when ArraySetAsSeries(Signal,true) but not displayed.

I was also trying to set ArraySetAsSeries(Signal,false) and put data words to signal array in proper order by

Signal=Volume[limit-i];

but still it is displayed in reverse order or not at all.

Any ideas ??

Another observation. It is possible to import volume data when it it 2 digits long. One digit long value is sometimes good and sometimes wrong imported.

Krzysztof

 
fajst_k:
I'm trying to use Volume information to sneak trading signal info to MT4. Here is my code

//---- indicator settings

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_maximum 12

#property indicator_buffers 2

#property indicator_color1 Silver

#property indicator_color2 Red

#property indicator_width1 2

//---- indicator parameters

extern int period=9;

//---- indicator buffers

double Signal[];

double SignalMA[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- drawing settings

SetIndexStyle(0,DRAW_LINE);

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,period);

//---- indicator buffers mapping

SetIndexBuffer(0,Signal);

SetIndexBuffer(1,SignalMA);

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("Signal");

SetIndexLabel(0,"Signal");

SetIndexLabel(1,"SignalMA");

//---- initialization done

return(0);

}

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

//| |

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

int start()

{

int limit, i;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

ArrayResize(Signal, limit); //resize the array to the number of bars

ArraySetAsSeries(Volume,true);

// ArraySetAsSeries(Signal,true);

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

Signal=Volume;

Print(Signal[0],Signal[1],Signal[2],Signal[3],Signal[4],Signal[5]);

//---- done

return(0);

}

The Volume info is not displayed. When i replace Volume with Close, Close is properly displayed.

Volume is only displayed when ArraySetAsSeries(Signal,false) but in this case is displayed in reverse order.

Volume data is put to signal array in proper order (when ArraySetAsSeries(Signal,true) but not displayed.

I was also trying to set ArraySetAsSeries(Signal,false) and put data words to signal array in proper order by

Signal=Volume[limit-i];

but still it is displayed in reverse order or not at all.

Any ideas ??

Another observation. It is possible to import volume data when it it 2 digits long. One digit long value is sometimes good and sometimes wrong imported.

Krzysztof

Krzysztof

Try it like in the one attached

Files:
 

it doesn't display. After adding ArraySetAsSeries(Volume,false) it displays in reverse order. After changing false to true it don't display again.

It looks for me that during import indexing of all data is reversed (to have bar 0 as latest) except volume. Build of MT4 is 610.

For me is a not big deal, I can always reverse it in MATLAB....

 
fajst_k:
it doesn't display. After adding ArraySetAsSeries(Volume,false) it displays in reverse order. After changing false to true it don't display again.

It looks for me that during import indexing of all data is reversed (to have bar 0 as latest) except volume. Build of MT4 is 610.

For me is a not big deal, I can always reverse it in MATLAB....

Krzysztof

Don't change anything in the code - no need to change anything

You can not try to set a buffer as series (since it is already a series metatrader 4 considers it as a run-time error if you try to do that - especially in new builds of metatrader 4). Attaching an example how it looks like on chart when it is simply attached to the chart (any chart) without any changes in that code.

And yes, buffers in metatrader are inversed (if you compare them to C/C++ like arrays)

If you want to use arrays for that and if you want the order to be the same as in C/C++ arrays, then the code has to be different - but you can not display an array using metatrader 4 - only drawing buffers can be displayed in metatrader, nor can you access arrays from some external code (like with using iCustom() calls)

Files:
volumes.gif  33 kb
 

Yes but you don't make csv import and don't display on 1 min chart. Try to import this file to unused symbol and display. Just have MT4 offline not to get updated. I bet it will fail.

It should look like this but unfortunatelly i had to inverse order in volumebuffer to be able to display otherwise (for correct order) it doesn't display. So it only displays in reverse order

Krzysztof

Files:
usdsek1.rar  204 kb
picture.jpg  310 kb
 

Or maybe TF is a problem here ?? Is MT4 able to display volume on 1 min chart ??

 
fajst_k:
Or maybe TF is a problem here ?? Is MT4 able to display volume on 1 min chart ??

Krzysztof

Try out this one (you can use any 1 minute chart for test)

Scroll back (since the last bar time exported to the csv file is 28.02.2013 at 16:39) and you will see the volume data imported from the csv file. Volume data is exported to csv as integer values hence the integer values in the imported buffer values too

PS: csv file must be in the "files" sub-folder. Also, set the "Max bars in chart " to some bigger value (50.000 in this example is OK) in order to see the dates imported

 

Now is OK, magic import code Thanks a lot

Krzysztof

 
fajst_k:
Now is OK, magic import code Thanks a lot Krzysztof

Glad that it is solved

Have a nice weekend

Reason: