How to Plot volume in a loop

trash

Well-Known Member
#11
I read it multiple times and I tried to do it with arrays. I already have the code that I tried with Arrays but I am definitely missing something. Back to the drawing board but thanks a lot for showing me that it works that way :thumb:
Write down in your own words what the mt4 code is calculating. It is pointless to proceed if you dont understand what the mt4 code is doing. Then translate to AFl and look for inbuilt functions in the afl functions reference guide instead of reinventing the wheel. Look at example codes for each function.
 

trash

Well-Known Member
#12
As aside I seem to have found a quite funny bug in Metatrader .

See the volume of 1-minute sample data center of MT4.


The summed up volume of 15 minute from 13:15 to 13:29 bar is 2135. That is the same one you see in AB if importing MT4 1min data.

Now take a look at 15min data center data of MT4.
There MT4 shows 2498 for that 15-min bar.


Now you may ask: "Where is the difference of 363 coming from?".
It is simple. MT4 wrongly adds the 13:13, 13:14 and 13:30 bar's volumes (110+125+128 = 363).

Does that make any sense?

No!

That is why in the two pictures on previous page you see slight difference in colors here and there.

As for proof of MT4 15-minute volume data being wrong and inconsistent to 1-min data -> as you can see Open and Close do fit. The Open of 1-min at 13:15:00 is 1.08995. The same one is shown on 15-min bar data. The close of 1-min at 13:29:59 is 1.09067. The same close is shown on 15-min bar data.

Does that inconsistency/bug(s) make MT4 software more trustworthy? IMO, absolutely not. MT4 is a platform for the naive ones. A toy.

EDIT: volume is pointless on spot FX. But that's not the point here since Metaquotes also offer their softwares to futures brokers. You can't trust their software's output. That's the point.
 
Last edited:
#13
Some of the bars matching (May be Luck ?) . Still missing something.

Code:
_SECTION_BEGIN("EMA");
P=V;
Periods = Param("PeriodsEMA", 100);
Plot( EMA( P, Periods ), _DEFAULT_NAME(), colorBlack, styleLine | styleThick );
_SECTION_END();

// Param( ''name'', defaultval, min, max, step, sincr = 0 )  
lookback = Param("Period", 2);

range = H - L;
Value2 = V*range;
Value21= Ref(V,1)*(Ref(H,1)-Ref(L,1));
Value3 = V/range;
Value31= Ref(V,1)/(Ref(H,1)-Ref(L,1));
hival2=Max(Value2,Value21);
hival3=Max(Value3,Value31);
//hival2=HHV(Value21,lookback);
//hival3=HHV(Value31,lookback);

val2cond = (H + L)/2;
Value1=LLV(V,20);

BarColor = IIf((Value1==V), colorGrey50,
IIf( (Value2 == hival2) && (C > val2cond), colorBlue,
IIf( (Value3 == hival3), colorGreen,
IIf( (Value2 == hival2) && (Value3 == hival3), colorPaleTurquoise,
IIf( (Value2 == hival2) && (C <= val2cond), colorRed, colorGrey50)))));

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), BarColor, ParamStyle( "Style", styleHistogram | styleThick, maskHistogram ), 2 );
_SECTION_END();
 

trash

Well-Known Member
#14
You are on the right track as far as using HHV and LLV is concerned.
Remove all Ref() and Max() (So remove Value21 & Value31, hival2, hival3 completely). Those are not correct. Using nested IIf is not correct also.
 
#15
First I tried it without REF, MAX but that also did not produce correct results.
How can one assign color to volume bars without IIF or any form of looping :confused:
Code:
 _SECTION_BEGIN("EMA");
P=V;
Periods = Param("PeriodsEMA", 100);
Plot( EMA( P, Periods ), _DEFAULT_NAME(), colorBlack, styleLine | styleThick );
_SECTION_END();

// Param( ''name'', defaultval, min, max, step, sincr = 0 )  
lookback = Param("Period", 2);

range = H - L;
Value2 = V*range;

Value3 = V/range;

hival2=HHV(Value2,lookback);
hival3=HHV(Value3,lookback);

val2cond = (H + L)/2;
Value1=LLV(V,20);

BarColor = IIf((Value1==V), colorGrey50,
IIf( (Value2 == hival2) && (C > val2cond), colorBlue,
IIf( (Value3 == hival3), colorGreen,
IIf( (Value2 == hival2) && (Value3 == hival3), colorPaleTurquoise,
IIf( (Value2 == hival2) && (C <= val2cond), colorRed, colorGrey50)))));

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), BarColor, ParamStyle( "Style", styleHistogram | styleThick, maskHistogram ), 2 );
_SECTION_END();
 
#17
I saw some online examples and did not find anyone doing it without nested IIf.
If I do it with simple IIF, it only colors the bars in the last line whichever it is. or I don't know how to do it without nested IIFs.

Also just for understanding, why Nested IIF is not correct here ?
(Apply criteria A => color them, Remaining Bars (Apply criteria B => color them), color all remaining ones)

Code:
//BarColor= IIf((Value1==V), colorYellow,colorGrey50);
BarColor= IIf( (Value2 == hival2) && (C > val2cond), colorBlue,colorGrey50);
BarColor= IIf( (Value3 == hival3), colorGreen,colorGrey50);
BarColor= IIf( (Value2 == hival2) && (Value3 == hival3), ColorPink,colorGrey50);
BarColor= IIf( (Value2 == hival2) && (C <= val2cond), colorRed, colorGrey50);
 

trash

Well-Known Member
#18
Why do beginners always want to argue with someone who has shown output being "same" one and who has more clue? Do you want to have "same" output as in MT4 version? Yes or no? If so then do not use nested iif.

Your non-nested IIF code lines are not applied correctly because there is no reference to previous line.

Alternatively to using IIf you may use iteration of visible chart area.
 
#20
Your non-nested IIF code lines are not applied correctly because there is no reference to previous line.
How can I reference previous line ? It is not mentioned in the documentation. I viewed many code examples but could not find one using it by referencing previous line.
 

Similar threads