Metatrader 5 coding questions / issues

 

A thread for metatrader 5 coding related questions : coding questions and general code development issues questions (and answers if there is an answer)

 

Ok, I got 1 question...

in the iCustom function if you need to declare the right index buffer, now is not longer possible inside the function...then what should we do?

example:

I have an indicator "CCI super mega trend" with 2 buffers upCCI[] (index buffer 0) and downCCI[] (index buffer 1), how could I declare them in mt5?

like this (ok, but where I supposed to specify them?):

upCCI=iCustom(Symbol(),0,"CCI super mega trend",...);

...

ArrayInitialize(upCCI, 0);

ArraySetAsSeries(upCCI, true);

ArrayResize(upCCI, 2, 1);

if(CopyBuffer(handle_upCCI, 0, 0, 2, upCCI) < 0)

return(0);

ArrayInitialize(downCCI, 0);

ArraySetAsSeries(downCCI, true);

ArrayResize(downCCI, 2, 1);

if(CopyBuffer(handle_downCCI, 0, 0, 2, downCCI) < 0)

return(0);

Thanks for help

 
dr.house7:
Ok, I got 1 question...

in the iCustom function if you need to declare the right index buffer, now is not longer possible inside the function...then what should we do?

example:

I have an indicator "CCI super mega trend" with 2 buffers upCCI[] (index buffer 0) and downCCI[] (index buffer 1), how could I declare them in mt5?

like this (ok, but where I supposed to specify them?):

upCCI=iCustom(Symbol(),0,"CCI super mega trend",...);

...

ArrayInitialize(upCCI, 0);

ArraySetAsSeries(upCCI, true);

ArrayResize(upCCI, 2, 1);

if(CopyBuffer(handle_upCCI, 0, 0, 2, upCCI) < 0)

return(0);

ArrayInitialize(downCCI, 0);

ArraySetAsSeries(downCCI, true);

ArrayResize(downCCI, 2, 1);

if(CopyBuffer(handle_downCCI, 0, 0, 2, downCCI) < 0)

return(0);

Thanks for help

Doc

try like this :

double upCCI[];

ArrayResize(upCCI, 2, 1);

ArrayInitialize(upCCI, 0);

ArraySetAsSeries(upCCI, true);

if(CopyBuffer(handle_upCCI, 0, 0, 2, upCCI) < 0) return(0);

double downCCI[];

ArrayResize(downCCI, 2, 1);

ArrayInitialize(downCCI, 0);

ArraySetAsSeries(downCCI, true);

if(CopyBuffer(handle_downCCI, 0, 0, 2, downCCI) < 0) return(0);

 
mladen:
Doc

try like this :

double upCCI[];

ArrayResize(upCCI, 2, 1);

ArrayInitialize(upCCI, 0);

ArraySetAsSeries(upCCI, true);

if(CopyBuffer(handle_upCCI, 0, 0, 2, upCCI) < 0) return(0);

double downCCI[];

ArrayResize(downCCI, 2, 1);

ArrayInitialize(downCCI, 0);

ArraySetAsSeries(downCCI, true);

if(CopyBuffer(handle_downCCI, 0, 0, 2, downCCI) < 0) return(0);

sorry but where I declare the index buffer?

 

previous indicator (just an example):

name: "CCI super mega trend"

...

int OnInit()

{

SetIndexBuffer(0,upCCI, INDICATOR_DATA);

SetIndexBuffer(1,downCCI,INDICATOR_DATA);

return(0);

}

...

[/CODE]

now, in mt4 it's easy, if I wish to call those buffers I use:

[CODE]new_up_CCI=iCustom(NULL, 0, "CCI super mega trend",inputs...,0,0)

new_dn_CCI=iCustom(NULL, 0, "CCI super mega trend",inputs...,1,0)

and in mt5, how could I make the same? How could I call those specific buffers?

 
dr.house7:
sorry but where I declare the index buffer?

You don't declare index buffer

You declare two arrays (double upCCU[] and double downCCI[]) that are then used as index buffers (with ArraySetAsSeries(name,true))

 
mladen:
You don't declare index buffer You declare two arrays (double upCCU[] and double downCCI[]) that are then used as index buffers (with ArraySetAsSeries(name,true))

of course, but could you please read and reply to my post #5?

Thanks

 
dr.house7:
of course, but could you please read and reply to my post #5? Thanks

Doc

There is no simple answer to the second question and I think you already know that

If you wish to use classical buffers and iCustom() like way of doing things, you have to declare a buffer in the init first (and in the number of buffers of course). Then you have to get a handle to a custom indicator and only then you can use it in CopyBuffer() function. There is no easy way any more to call a custom indicator (try, for example, to change parameters "on-the-fly" in metatrader 5) and that is why I keep repeating that metatrader 5 is s step backwards compared to metatrader 4 : custom indicators are not functions any more and you have to do 10 time more code writing just to get one simple iCustom() call from metatrader 4, and that is why I write my own functions instead of using that "handle" managing of custom indicators

 

I'm going crazy

I'm not able to import (using icustom function) these 2 buffers (the 2 trendlines).

I tried also on mt4, but nothing. Why I cannot take data from upperband[]; and lowerband[];

In the picture, what I like to obtain, the signal of cross of those trendlines.

Any suggestion?

Files:
eurusdm1_3.png  27 kb
zz_signal.mq5  12 kb
 
dr.house7:
I'm going crazy

I'm not able to import (using icustom function) these 2 buffers (the 2 trendlines).

I tried also on mt4, but nothing. Why I cannot take data from upperband[]; and lowerband[];

In the picture, what I like to obtain, the signal of cross of those trendlines.

Any suggestion?

Doc

Those are objects, not buffers

You can not access objects using buffers, you can access them using ObjectGet...() functions

 
mladen:
Doc

Those are objects, not buffers

You can not access objects using buffers, you can access them using ObjectGet...() functions

Thanks, but how could I use objectget function if I call the indicator using iCustom?

Reason: