MQL4 Learning - page 45

 

How to close open positions at Friday market close

How can I know when the market is say an hour from the Friday closing or right at market close? I use demo accounts with two different brokers and they are on different server times and I would like to code my EA to close all open positions before the Friday market close. This is just for testing puposes but it is something I would like to know regardless. I don't want to hard code a time due to the fact that different brokers use different server times. Is this possible? I know I can detect market opening but due to the gap behavior seen at times on market openings I would be more comfortable closing positions before the Friday market close.

Thanks!

 

How to pass a variable from indicator to EA

Hi ,

Is any way to pass one indicator variable to an expert advisor?

For example if I have 2 moving averages and one cross the other or one is greater than other and store them in 2 variables in my indicator as MA1 and MA2.

Is it possible to call these variables to expert advisor?

Note: I don't want to put the code of Moving averages in the expert advisor , generally I want to take some variables from indicator and put in an expert advisor. (Something like read the variable from memory).

Thank you very much.

 
takis76:
Hi ,

Is any way to pass one indicator variable to an expert advisor?

For example if I have 2 moving averages and one cross the other or one is greater than other and store them in 2 variables in my indicator as MA1 and MA2.

Is it possible to call these variables to expert advisor?

Note: I don't want to put the code of Moving averages in the expert advisor , generally I want to take some variables from indicator and put in an expert advisor. (Something like read the variable from memory).

Thank you very much.

You must use the iCustom() function in your EA to call the different indicator buffers.

Or for the standard indicators, use their standard functions. Example for MA: iMA(......);

FerruFx

 

How to remove text from Custom Indicators

Hi,

Just a quick question, does anyone know if there is a piece of code I can use so the text and values do not appear on the custom indicator window, as in the pic below.

thanks

Files:
question.jpg  46 kb
 
TLBreak:
values do not appear on the custom indicator window, as in the pic below.

By giving a NULL value to the desired buffer: SetIndexLabel(X,NULL);

 

Thanks for your very fast reply, you have just made an old man very happy, and made my life at least 10 times easier

 

EA question

I'm writing an EA. I have a couple indicators I want to use that I would like to trade if they change colors. For instance, if the indicator is green, buy. If the indicator is yellow, sell. Any help would be appreciated.

 

Use iCustom statement such as:

Note: PM1 or PM2 is variable name - can be changed.

int BuyValue=0, SellValue=0;

PM1=iCustom(NULL,60,"SSL_fast_mtf",0,0);// "SSL . . " is name of custom indicator file name - Buffer 0.

PM1_1=iCustom(NULL,60,"SSL_fast_mtf",0,1);//Buffer 0, 1-Back.[/PHP]

[PHP] PM2=iCustom(NULL,60,"SSL_fast_mtf",1,0);//Buffer 1.

PM2_1=iCustom(NULL,60,"SSL_fast_mtf",1,1);//Buffer 1, 1-Back.

Then logic statement:

if(PM1>PM2 && PM1_1<PM2_1) {

BuyValue=1;

}

if(PM1PM2_1){

SellValue=1;

}

When Buy or Sell Value=1, then Buy or Sell Statement to open ticket.

Dave

P.S. Up is normally Buffer 0, Dwn is normally Buffer 1!

 

Perfect. Thanks for your help Dave!

 

Ok, I've been trying to get my EA to work. I just want it to trade when the indicator changes from one color to another. I don't think it should be that hard but I make everything difficult. Does anyone have a simple EA that trades based on only one indicator changing color? For an example, so I can see how horrible my programming skills really are.

Reason: