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

 
Aaragorn:
can i do that? just write bufferindexes into the indicator and use the upper and lower words like that and have it return the values of the upper and lower lines?

Not into the indicator. In the EA. (U can do it with an indicator, but not use the same indicator inside its own code!!!!!)

 
elihayun:
Not into the indicator. In the EA. (U can do it with an indicator, but not use the same indicator inside its own code!!!!!)

so I can write a buffer index in the EA but how does it get the value from the indicator? I didn't mean use the indicator inside it's own code that would be kinda silly. forgive my communication breakdown. it's not easy to communicate sometimes specifically enough what the trouble is. That's the trouble both with coding AND with talking about coding to others.

 

let me apologize to those who may be trying to help me but find my posts are information overload. I have posted alot of code basically because I can then put two windows open next to each other, one window being this thread and the other being the metaeditor and look at one part of the code in one window and another part of it in the other window and I do that to help me think my way thru the problem I'm looking at. I'm quite visual that way and it helps me think about what I'm doing and wanting to do. I don't mean to overwhelm anyone with alot of code that they have to look thru all of it. Sometimes I've tried to single out snippets after posting the whole EA or the whole indicator as I try to zero in on WHERE and WHAT needs to be done. I appreciate everyone who takes the time to look at what I'm doing and offer constructive input. If the volume of what I post is too much just filter down to look for what I'm trying to do and don't get bogged down in the rest which is only there as a context to what I'm doing. i am basically thinking out loud.

 
Aaragorn:
so I can write a buffer index in the EA but how does it get the value from the indicator? I didn't mean use the indicator inside it's own code that would be kinda silly. forgive my communication breakdown. it's not easy to communicate sometimes specifically enough what the trouble is. That's the trouble both with coding AND with talking about coding to others.

Dont bother about HOW. Let the Metatrader do that for u. U just use the code to get the information u like.

Hint: When u run the EA u will see : "Trend Bands loaded succesfully", that means that it does what u want

 
elihayun:
Dont bother about HOW. Let the Metatrader do that for u. U just use the code to get the information u like. Hint: When u run the EA u will see : "Trend Bands loaded succesfully", that means that it does what u want

I like the sound of using the code to get the information I like, that's what I'm trying to learn. HOW to use the code to get the information I like.

So you think the best way to get the tick value for the trend bands is to use the iCustome()? and NOT write the code inside the EA like I have already done?

For instructional purposes..since I have the code already written in the EA is there a way to get the values from it there?

 
elihayun:
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

wait a minute it DOES have buffers! how could I have missed them?

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

//| Trend Bands.mq4 |

//| Dwt5 and adoleh2000 |

//| Copyright © 2005, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

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

#property copyright "Copyright © 2005, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"

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

//| Custom indicator initialization function |

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

#property indicator_chart_window

#property indicator_buffers 5

#property indicator_color1 Red

#property indicator_color2 Black

#property indicator_color3 Blue

#property indicator_color4 Red

#property indicator_color5 Blue

double upper[], middle1[], middle2, lower[];

double Xup[], Xdown[];

extern int period = 34;

int init()

{

SetIndexStyle(0,DRAW_LINE,EMPTY,2);

SetIndexShift(0,0);

SetIndexDrawBegin(0,0);

SetIndexBuffer(0,upper);

SetIndexStyle(1,DRAW_LINE,EMPTY,2);

SetIndexShift(1,0);

SetIndexDrawBegin(1,0);

SetIndexBuffer(1,middle1);

SetIndexStyle(2,DRAW_LINE,EMPTY,2);

SetIndexShift(2,0);

SetIndexDrawBegin(2,0);

SetIndexBuffer(2,lower);

SetIndexStyle(3,DRAW_ARROW,EMPTY,2);

SetIndexArrow(3, 162);

SetIndexShift(3,0);

SetIndexDrawBegin(3,0);

SetIndexBuffer(3,Xdown);

SetIndexStyle(4,DRAW_ARROW,EMPTY,2);

SetIndexArrow(4, 162);

SetIndexShift(4,0);

SetIndexDrawBegin(4,0);

SetIndexBuffer(4,Xup);

//---- indicators

//----

return(0);

}

so....I see 5 buffers...an upper, middle, lower and up and down ...

I suppose the information I want is from the upper and lower buffer...

 
 
Aaragorn:
I meant this to be a new post not an edit of a previous one, the site operation sometimes still mixes me up..

I think the best way to do it is NOT using the indicator. It is just the simplest way. For a start it is good enough.

U are looking at the changes that I made to the indicator. If u want to use this one make sure u are writing the correct name inside your code.

as long as u know in what buffer lies the information u want, it dosen't matter haw many indicators there in the code

 
elihayun:
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

hey so this will work to pull the current value of the top and bottom lines into the EA..

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

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

I think I'm beginning to understand this thanks to the tutoring...

so I don't have to write the indicator code inside the EA just call it like this from the EA....and it will return the current bar values of the lines which I can then use...that's perfect! ....see I knew SOMEONE knew how to do this! (it just wasn't me) ...

so if I want to be able to change the number of periods I use for the indicator I would do this...

extern double back = 300 //--which I could change as desired

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

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

assuming I want to call the value of the indicator off of a longer time period than the time period I'm using on the chart...would I do this?...

extern double back = 300 //--which I could change as desired

extern double TF = 30 //--which I could change as desired

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

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

where NULL uses the current symbol,

TF uses the chart bar period I specify

Trend Bands calls the indicator

back is the user defined number of bars to use for the indicator averaging

0 or 2 tells it which buffer to access

and the last 0 tells it to use the current bar

would that work?

 
Aaragorn:
would that work?

Great!!! You got the idea!!!!

It will work perfect. and if u want to check that 5M and 15M reach the edge at the same time u can get the values from each TF and test it together.

But leave that for latter....

Reason: