Indicator MACD modification

 

Hello,

I'm working on the MACD script for the Expert Advisor, that I would like to run every minute and receive an alert when conditions apply for 1M, 3M, 5M and 15M charts. I have following script 'Forum MACDcrossAUDD1.txt' attached for which nothing happens when I run it/ put it on a chart.

Thank you for your help.  

Files:
 
zeno1:

Hello,

I'm working on the MACD script for the Expert Advisor, that I would like to run every minute and receive an alert when conditions apply for 1M, 3M, 5M and 15M charts. I have following script 'Forum MACDcrossAUDD1.txt' attached for which nothing happens when I run it/ put it on a chart.

Why don't you want to know if your OrderSend fails ?  wouldn't you like to know the error if it does fail ?

 

 What are Function return values ? How do I use them ?

 
zeno1:

I have following script 'Forum MACDcrossAUDD1.txt' attached for which nothing happens when I run it/ put it on a chart.

It's not going to do anything if you attach it as a Script . . . .  it is an EA isn't it ?

 

Did you run it in the Strategy tester ?  I did . . .  I ran it from Sept 2007 to End Jan 2010

 

 

Thank you RaptorUK.

Regarding the error you mention, I have added following line, that I believe will give me an alert:

...

int start()

... 

        Alert ("Error ", GetLastError());                      // Error message, if e.g. OrderSend fails, etc.

       // return

      return(0);              

}

 

the error message is the last line of the int start() section. 

I also changed the location of this compiled .mq4 file under /expert advisors/ folder, so that it gets recognized as EA.

Last, when I run the Strategy Tester, I did not receive the graph you get though. Instead, my 'graph' tab in tester remains blank? 

I read on internet that there is a 'set' file to communicate here, but my search does not see it under any corresponding folder ... 

My final objective is to run MACD on multiple time frames and from there decide when to enter into a trade.  

 
zeno1:

Thank you RaptorUK.

Regarding the error you mention, I have added following line, that I believe will give me an alert:

<SNIP>

the error message is the last line of the int start() section. 

I also changed the MT4 code to immediately under /experts/ folder, so that it gets recognized as EA.

Last, when I run the Strategy Tester, I did not receive the graph you get. Instead, my 'graph' tab in tester remains blank? 

I read on internet that there is a 'set' file, but my search does not see it under any corresponding folder ... 

My final objective is to run MACD on multiple time frames and from there decide when to enter into a trade.  

Please use this to post code . . . it makes it easier to read.

 
RaptorUK:
Please use this to post code . . . it makes it easier to read.



I modified the code format in my previous comment.
 
zeno1:

Thank you RaptorUK.

Regarding the error you mention, I have added following line, that I believe will give me an alert:

1.  the error message is the last line of the int start() section. 

I also changed the MT4 code to immediately under /experts/ folder, so that it gets recognized as EA.

2.  Last, when I run the Strategy Tester, I did not receive the graph you get. Instead, my 'graph' tab in tester remains blank? 

3.  I read on internet that there is a 'set' file, but my search does not see it under any corresponding folder ... 

4.  My final objective is to run MACD on multiple time frames and from there decide when to enter into a trade.  

1.  why use Alert ?  it does not output anything under the Strategy Tester,  from :  https://www.mql5.com/en/articles/1512

"Some functions are processed/passed without output

These are Sleep(), Alert(), SendMail(), PlaySound(), MessageBox(), WindowFind(), WindowHandle(), WindowIsVisible() "

If you must use Alert also use print()  so you can see what is going on in the Journal/Experts tab and the logs . . .

Do you send the Alert always or only IF there is a problem with the OrderSend() ?


2.   are you running the Strategy Tester on AUDUSD D1 ?  or some other timeframe ?  how much D1 AUDUSD data do you have,  as I said,  I ran it for over 2 years worth of data . . .

3.   you don't need to use a set file unless you want to save your settings . . . your EA doesn't have any settings to save.

4.  your EA is currently hard coded to only run on AUDUSD D1 . . . 

 
RaptorUK:

1.  why use Alert ?  it does not output anything under the Strategy Tester,  from :  https://www.mql5.com/en/articles/1512

"Some functions are processed/passed without output

These are Sleep(), Alert(), SendMail(), PlaySound(), MessageBox(), WindowFind(), WindowHandle(), WindowIsVisible() "

If you must use Alert also use print()  so you can see what is going on in the Journal/Experts tab and the logs . . .

Do you send the Alert always or only IF there is a problem with the OrderSend() ?


2.   are you running the Strategy Tester on AUDUSD D1 ?  or some other timeframe ?  how much D1 AUDUSD data do you have,  as I said,  I ran it for over 2 years worth of data . . .

3.   you don't need to use a set file unless you want to save your settings . . . your EA doesn't have any settings to save.

4.  your EA is currently hard coded to only run on AUDUSD D1 . . . 

 

RaptorUK, thanks again for your advice.

1. When opening MT4 today I received alerts with multiple error messages '0' to the extend that I grayed out the line 'Alert ("Error ", GetLastError());' that I had added. But added to that, how can I get the corresponding error constant for the error value so that I can understand its meaning?

If I understand your remark about OrderSend(), should I add the following line as well? 

int OrderSend (string symbol, int cmd, double volume, double price, int slippage, double stoploss,
double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

2. I have historic data for AUDUSD D1 going back to July 2006. 

3. It seems that I would have to write code in the EA to create a setting file, if I would need to?

4. AUDUSD is a testing pair, and I may modify that later. 

 
zeno1:

RaptorUK, thanks again for your advice.

1. When opening MT4 today I received alerts with multiple error messages '0' to the extend that I grayed out the line 'Alert ("Error ", GetLastError());' that I had added. But added to that, how can I get the corresponding error constant for the error value so that I can understand its meaning?

If I understand your remark about OrderSend(), should I add the following line as well?  

There are examples in the thread I gave a link to,  read it,  understand it,  implement it:  What are Function return values ? How do I use them ?
 
RaptorUK:

1.  why use Alert ?  it does not output anything under the Strategy Tester,  from :  https://www.mql5.com/en/articles/1512

"Some functions are processed/passed without output

These are Sleep(), Alert(), SendMail(), PlaySound(), MessageBox(), WindowFind(), WindowHandle(), WindowIsVisible() "

If you must use Alert also use print()  so you can see what is going on in the Journal/Experts tab and the logs . . .

During optimization both Alert and Print do nothing

During visual mode Alert become a Print (and logged in the Journal tab.) Not necessary to do both.

Only during live (non-visual mode) trading (demo or real) does Alert do a pop up.

 

I would like to define my objective with this EA I'm trying to build. At this point, I'm looking for alerts/messages/indications, both visual on the chart and per new 'alert' window, of MACD:

This is step 1: 

* MACD indications on 1M chart, also indicating on this chart for MACD calculation of other time frames (5M, 10M) as they appear (e.g. with arrows for buy and sell indication). This will be calculated every 30s or 1M, so on an almost permanent basis.

I'm trying to reach this point now. In later steps more will be added, such as entering an order, but I'm not there yet I believe. I'm trying to handle my approach in steps, so that it remains workable for me. 

Thank you for your help. 

Reason: