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 ...

 
  1. Set as series.

  2. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

Reason: