Pls, i need help with adding a custom (iCustom) MACD indicator in my MQL5 code.

 
I am trying to code a strategy with a custom MACD indicator,

Buy Condition:
where if the MACD value is above the zero (0) line the EA should open a buy  position and close the existing buy position on a reverse signal.

Sell Condition:
 if the MACD value is below the zero (0) line the EA should open a sell position and close the existing buy position on a reverse signal.

I think it`s a very simple strategy.
 

There are two MACD indicators that are standard that can be used.  You should not need to do a iCustom function.

Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5


I use the iMACD and see if the main line is above or below zero. 

   double price_arraym[];

   double price_arrays[];

   int MACD = iMACD(Symbol(),Period(),12,26,9,PRICE_CLOSE);

   CopyBuffer(MACD,0,0,4,price_arraym);     // main line

   CopyBuffer(MACD,1,0,4,price_arrays);     // signal line

   if (price_arraym[0] > 0){ // do something}

   if (price_arraym[0] > 0){ // do something else}


The  iOsMA   can be used to look at the MACD histogram

if you must use iCUSTOM then you should look at this page. 

iCustom - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Hope this helps,

Chris

Documentation on MQL5: Technical Indicators
Documentation on MQL5: Technical Indicators
  • www.mql5.com
Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Dere_D:
I am trying to code a strategy with a custom MACD indicator,

Buy Condition:
where if the MACD value is above the zero (0) line the EA should open a buy  position and close the existing buy position on a reverse signal.

Sell Condition:
 if the MACD value is below the zero (0) line the EA should open a sell position and close the existing buy position on a reverse signal.

I think it`s a very simple strategy.

Do you know there is already a MACD-EA on your pc? Look into: ...\Experts\Examples\MACD\

And if you search (https://www.mql5.com/en/search#!keyword=MACD) and then select (left side) Articles or CodeBase you'll find a hell lot of other examples ....

Bear in mind there's almost nothing that hasn't already been programmed for MT4/MT5 and is ready even for you.
You can be much faster when you copy, paste, and modify than when you check out all the rookie mistakes. :)


 
Chris Pinter #:
   double price_arraym[];

   double price_arrays[];

   int MACD = iMACD(Symbol(),Period(),12,26,9,PRICE_CLOSE);

   CopyBuffer(MACD,0,0,4,price_arraym);     // main line

   CopyBuffer(MACD,1,0,4,price_arrays);     // signal line

   if (price_arraym[0] > 0){ // do something}

   if (price_arraym[0] > 0){ // do something else}

Hi,

Miss "ArraySetAsSeries(price_arraym, true);" and " ArraySetAsSeries(price_arrays, true);" before CopyBuffer I think ...