Coding help..How do I get indicator to filter instead of alert?

 

This produces an alert when the price reaches an upper or lower line.

I want to allow trades to execute until they come close to these lines. When the price gets too close not allow trades to open.

how do I get that logic to happen on current bar closing(s) when all that are here are arrays?

for(int x=0; x<limit; x++) {

Xdown[x] = 0; Xup[x] = 0;

middle1[x] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_TYPICAL, x);// drawn line

middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

upper[x] = middle2 + (3.5*avg);

lower[x] = middle2 - (3.5*avg);

if (MathAbs(upper[x] - High[x]) < 2*Point)

{

Xdown[x] = upper[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower[x] - Low[x]) < 2*Point)

{

Xup[x] = lower[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach lower edge");

}

}

return(0);

}
 

I see you re trying hard, well done! At this stage I feel that what you need most is to know how to help yourself, so I would advise to use MQL's "NAvigator->Search" function _extensively_, you'll find answers to many of your questions (the only thing one can call from an indicator are the buffers, and this is done through iCustom(); Objects are not arrays etc. and much much more). For example, a search for "array" will teach that Current Bar's array index is 0, Last Bar's arrray index is 1 and so on.

If the search function entries are all overwhelming, you're probably trying to do stuff too difficult for you at this stage. I believe most of the examples above are touched on in codersguru's beginner's course, so I would recommend a second reading.

You might also take a simple EA, and try to simplify/modify it slightly, that will teach you how it works. Once it's done, you can try to complexify it.

Sorry if i m off the mark.

Now, in general, to work on Close price, you test for the Opening of a new bar and then write your conditions on arrays' index 1. A possible code to detect the Opening of a new bar:

bool NewBar()

{

static datetime dt = 0;

if (Time[0] != dt)

{

dt = Time[0];

return(true);

}

return(false);

}

Hope this helps, good luck.

 

Yes, you are on the right track.

I would halt all, and re-read c++ programming.

Unfortunately Object oriented is not that great for mq4, so you will have to compensate with the basics.

Keep it up mate, youll get there.

 
Aaragorn:
This produces an alert when the price reaches an upper or lower line.

I want to allow trades to execute until they come close to these lines. When the price gets too close not allow trades to open.

how do I get that logic to happen on current bar closing(s) when all that are here are arrays?

You can have this as an example. It close to what u want to get. As far as I can see, its the same indicator that u are using.

 
pipeline:
I see you re trying hard, well done! At this stage I feel that what you need most is to know how to help yourself, so I would advise to use MQL's "NAvigator->Search" function _extensively_, you'll find answers to many of your questions (the only thing one can call from an indicator are the buffers, and this is done through iCustom(); Objects are not arrays etc. and much much more). For example, a search for "array" will teach that Current Bar's array index is 0, Last Bar's arrray index is 1 and so on.

If the search function entries are all overwhelming, you're probably trying to do stuff too difficult for you at this stage. I believe most of the examples above are touched on in codersguru's beginner's course, so I would recommend a second reading.

You might also take a simple EA, and try to simplify/modify it slightly, that will teach you how it works. Once it's done, you can try to complexify it.

Sorry if i m off the mark.

Now, in general, to work on Close price, you test for the Opening of a new bar and then write your conditions on arrays' index 1. A possible code to detect the Opening of a new bar:

bool NewBar()

{

static datetime dt = 0;

if (Time[0] != dt)

{

dt = Time[0];

return(true);

}

return(false);

}

Hope this helps, good luck.

ok about that search function...it doesn't return anything. I have tried to use it several times in the metaeditor. I type in what I want and hit return and nothing happens, or I click that little go box next to the search string and nothing happens. I was just noticing what a lame searh it is because it doesn't work at all. I am referring to the search feature in the metaeditor navigator window...is there some protocol to make it work that I don't know about?

 
fx-programmer:
Yes, you are on the right track.

I would halt all, and re-read c++ programming.

Unfortunately Object oriented is not that great for mq4, so you will have to compensate with the basics.

Keep it up mate, youll get there.

thankyou for the encouragement. moral support counts. Do you see what my theoretical goal is here? Could you suggest a better method (the basics as you call it) to accomplish this goal?

 
pipeline:

Now, in general, to work on Close price, you test for the Opening of a new bar and then write your conditions on arrays' index 1. A possible code to detect the Opening of a new bar:

bool NewBar()

{

static datetime dt = 0;

if (Time[0] != dt)

{

dt = Time[0];

return(true);

}

return(false);

}

Hope this helps, good luck.

it almost helps if you know what I mean..assuming it returns true then what, how do you get the value of the indicator out of the array at the current close now that it's been detected that there is a new bar?

 
 
Aaragorn:

Last night I was googling around and found this...

http://www.gordago.com/?act=download

does anyone have any experience with this? is it for real?

Gordago does not handle or is still not capable of handling custom indicators. That is a major drawback.

The only way to learn programming is to slog it out, like you are doing now... learning from examples. Coders' Guru's stuff is great for learning.

Good luck,

Maji

 
I am thinking today of saying to hell with the indicators and just see if I can create something that will let me reference the highest high and the lowest low of the previous(x) bars.

The more I look at indicators the more attractive this seems....

ok i see the high() in predefined variables. how do i use it to get the highest high of the last 30 hours for example?

 

Writing an indicator is one thing, and writing an EA is another thing. Don't mix them. In indicators you have to deal with the history too to draw it correctly. When writing an EA u have only the current tick and u have to calculate the values every tick (if u don't want to loos a trade). So, to get the values of the upper and bottom edge of the CURRENT tick you can do 2 things

  1. Use the original indicator as a custome indicator
  2. write the logic of the indicator inside your EA

The 1st option is not hard. You have to find out first, what is the buffer index that use for the upper line and the bottom line.

do find it u have to look in the indicator code

SetIndexBuffer(0,upper);

SetIndexBuffer(1,middle1);

SetIndexBuffer(2,lower);

as u can see the upper line is index 0, the middle is index 1 and lower is index 2.

Now, that we have this information we have to know haw many parameters the indicator have. To get this information u have to look for lines that start with the word external

I found only 1 line

extern int period = 34;

Now, we can use the indicator as a custome one

double upLevel = iCustome(NULL,0, "Trend Bands", 34, 0, 0);

double LowLevel = iCustome(NULL,0, "Trend Bands", 34, 2, 0);

34 is the parameter to the indicator

0 is the buffer index (2 for the lower)

the last 0 is the bar shift (In EA we need the current, so we use 0)

now that u have the upper and lower values u can check them against the price

Hope it will make you progress

Eli

Reason: