How to use iMACD

Cromo
395
Cromo  

Hi, it is very strange.

I want to read MACD signal of TF M1 on TFM5.

I mean I used below code to read MACD of TFM1 and when I attach EA on TFM5, I can not read MACD signal of M1 from M5 chart.

On real chart, it shows the value, but when I do backtest it always shows zero.  DO you know why?



double iMACD(
string symbol,
int timeframe,
int fast_ema_period,
int slow_ema_period,
int signal_period,
int applied_price,
int mode,
int shift
);
Keith Watford
Moderator
29959
Keith Watford  

Read the documentation and look at the example.

What you have posted will not even compile.

Cromo
395
Cromo  
Keith Watford:

Read the documentation and look at the example.

What you have posted will not even compile.

Hi, Keith

Thank you.

This is a code.


void start()
{
   int TIME_FRAME=1;
     double RSI=iRSI(NULL,TIME_FRAME,14,PRICE_CLOSE,1);
     Comment(RSI);
     
         
        
}

When I use TIME FRAME=1 (M1),and backtest TF M5.

RSI value is alwasy zero.

Why?

I want to get M1 RSI data on the M5 chart.

Keith Watford
Moderator
29959
Keith Watford  

First of all get out of the habit of using

void start()

This was superseded 7 years ago and by now nobody should be using it any more.

When you start a new project simply click "New" top left of the Editor and then whatever you are doing, ie Expert advisor.

Then the template is there and you use OnTick() for an EA. Certainly do NOT add void start() as well as OnTick() as this may be ignored by the compiler.

Also get used to using the enum

input ENUM_TIMEFRAMES      TIME_FRAME=PERIOD_M1;

instead of an int for the time-frame. It makes the code simpler to read and also easier if you ever want to convert to MQL5.

This should work correctly.

//+------------------------------------------------------------------+
//|                                                     RSI Test.mq4 |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict
//--- input parameters
input ENUM_TIMEFRAMES      TIME_FRAME=PERIOD_M1;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
     double RSI=iRSI(NULL,TIME_FRAME,14,PRICE_CLOSE,1);
     Comment(RSI);
//---
  }
//+------------------------------------------------------------------+
Cromo
395
Cromo  

Thank you so much. I understand it.

I want to ask another topic.

If you have time please advice me.

https://www.mql5.com/en/forum/366758
How to avoid order modify error1?
How to avoid order modify error1?
  • 2021.04.08
  • www.mql5.com
Hi, I have already some orders with tp and sl. But I want to scan all orders and modify ONLY tp=0. Here is my code. But there is some issues...