MACD HELP

 

Will any1 be able to help me code the signal line as soon as it crosses over the MACD under the 0 line, trigger buy order.

I know it sounds simple but really struggling with this for a few days now. Would appreciate any help! 


double sellPrice = Bid;
double buyPrice = Ask;

double macd = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);


double signalLine = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);



if (macd<signalLine)
{
signal="sell";
}

if (macd<signalLine)
{
signal="buy"
;}

if (signal=="buy" && OrdersTotal()<=10)

OrderSend (_Symbol,OP_BUY,0.10,Ask,3,0,Ask+350*_Point,NULL,0,0,Green);


if (signal=="sell" && OrdersTotal()<=10)

Comment ("The current signal is: ", signal);
 
kamran1020:

Will any1 be able to help me code the signal line as soon as it crosses over the MACD under the 0 line, trigger buy order.

I know it sounds simple but really struggling with this for a few days now. Would appreciate any help! 


Hello,

well I would like to, but what are these parameters, you pass the iMACD() ??

According to the doc, I can only find 6 parameters being taken by the function.

You need to use the CopyBuffer() function to get access to the values of the indicator.

double main[];
double signal[];
const int macd = iMACD(NULL,0,12,26,9,PRICE_CLOSE);
int error_code = ERR_SUCCESS;

if(CopyBuffer(macd, MAIN_LINE, 0, 1, main) == -1)
{ 
    error_code = GetLastError();
}

if(CopyBuffer(macd, SIGNAL_LINE, 0, 1, signal) == -1)
{ 
    error_code = GetLastError();
}


// Now you can compare values
if(main[0] < signal[0])
{
    /* some action */
}

https://www.mql5.com/en/docs/indicators/imacd 

https://www.mql5.com/en/docs/series/copybuffer 

Documentation on MQL5: Technical Indicators / iMACD
Documentation on MQL5: Technical Indicators / iMACD
  • www.mql5.com
iMACD - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
kamran1020: Would appreciate any help! 
OrderSend (_Symbol,OP_BUY,0.10,Ask,3,0,Ask+350*_Point,NULL,0,0,Green);
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Dominik Egert:

Hello,

well I would like to, but what are these parameters, you pass the iMACD() ??

According to the doc, I can only find 6 parameters being taken by the function.

You need to use the CopyBuffer() function to get access to the values of the indicator.

https://www.mql5.com/en/docs/indicators/imacd 

https://www.mql5.com/en/docs/series/copybuffer 

I would like to buy when the macd main line crosses over the signal line, Under the 0 line of the indicator. That is all, just trying to keep it as simple as possible!


Thank you! 

 
Dominik Egert:

Hello,

well I would like to, but what are these parameters, you pass the iMACD() ??

The code is MQL4 not 5.

The OP posted in the wrong section and I have since moved the topic.

 
kamran1020:

Will any1 be able to help me code the signal line as soon as it crosses over the MACD under the 0 line, trigger buy order.

I know it sounds simple but really struggling with this for a few days now. Would appreciate any help! 


if (macd<signalLine)
{
signal="sell";
}

if (macd<signalLine)
{
signal="buy"
;}

You don't check for a cross and you don't check if it is below the 0 level.

Your condition for a buy signal is the same as for a sell signal.