Download MetaTrader 5

Can't get the right value from a TrendChannel with iCustom

To add comments, please log in or register
Franzkekko
41
Franzkekko  

Hi everyone!
I'm trying to merge some indicators using iCustom.
An indicator which I have problem with is TrendChannel.mq4

 

Parts of the code are these: 

extern int  degree = 1;
extern double kstd = 2.0;
extern int  bars = 48;
extern int  shift = 0;
extern int  AlertPipRange = 5;
extern string AlertText = "";

input bool     EnableNativeAlerts = true;
input bool     EnableSoundAlerts  = true;
input string   SoundFileName    = "alert.wav";

datetime LastAlertTime = D'01.01.1970';

//-----
double fxl[],fxh[],sqh[],sql[];

double ai[10,10],b[10],c[10],x[10],y[10],sx[20];
double sum,suml,sumh;
int ip,p,n,f;
double qq,mm,tt;
int ii,jj,kk,ll,nn;

int i0 = 0;

Then there are buffers...

int init()
{
  SetIndexBuffer(0, fxl);
  SetIndexBuffer(1, fxh);
  SetIndexBuffer(2, sql);
  SetIndexBuffer(3, sqh);

  SetIndexStyle(0, DRAW_LINE);
  SetIndexStyle(1, DRAW_LINE);
  SetIndexStyle(2, DRAW_LINE);
  SetIndexStyle(3, DRAW_LINE);

[...........]

 And to the end:

[...]

  for(n=i0;n<=i0+p;n++)
  {
    sqh[n]=fxh[n]+sumh;
    sql[n]=fxl[n]-suml;
  }

[...]

 

sql[n] and sqh[n] are exactly what i need to get with my iCustom function. They are the Lower line and the Higher line of the trendchannel.

i need to create an alert when they cross with an other indicator for n=0 ( sqh[0] or sql[0].

I created an indicator (mq4) not an EA because I don't need to open any trades, just run an Alert. 

That's the code:


//----

double channel_sqh=iCustom(NULL, 0, "TrendChannel.mq4", 3, 0);
double channel_sql=iCustom(NULL, 0, "TrendChannel.mq4", 2, 0);

input bool     EnableNativeAlerts = true;
input bool     EnableSoundAlerts  = true;
input string   SoundFileName    = "alert.wav";

//----

extern int  AlertPipRange = 5;
extern string AlertText = "";

//----

datetime LastAlertTime = D'01.01.1970';

//-----

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
  return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
//--- Show data from 3 file TrendChannel.mq4
Comment(StringFormat("TrendChannel sqh: %G\nTrendChannel sql: %G", channel_sqh, channel_sql));

return(0);
}


however the string on the left-top corner of MT4 report a "0" value for both channel sql and sqh =(

in iCustom funcion i wrote (...3, 0) and (...2, 0) because if I use Data Window it shows this:

trendchannel output


I'm not a super programmer, I just enjoy editing existing code but this time I'm getting stuck.

What's the problem on this code? =( 

Hope someone can help me =)

Thanks in advance!!

whroeder1
15917
whroeder1  
  1. double channel_sqh=iCustom(NULL, 0, "TrendChannel.mq4", 3, 0);
    double channel_sql=iCustom(NULL, 0, "TrendChannel.mq4", 2, 0);
    These are not changing, assign them in start.
  2. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum
Franzkekko
41
Franzkekko  
Wooo thank you I'm trying as soon as I get at home. 
Thanks for the link, I was missing that thread.
I'll keep you updated ;)
Franzkekko
41
Franzkekko  
You did it!!

iCustom works if positioned into int Start() section and the source indicator has to be without extension... 

Thanks fot the help!
To add comments, please log in or register