Can you at least say what the problem is?
It's not creating the file? It's giving wrong values? It's giving 0 values? blank values?
Did you try using Alert or Print to find out if 'getrsi' is calling the right number?
Hello,
I am trying to export data from MT4 to excel for a list of date recorded in the input file.
The High, low, close and Sto is exported correct to the output file but I cannot get the RSI information out.
This code return the value of RSI of the last date on chart instead of the date in the input file.
Could you please look at the short code below and correct my error?
How to use the SRC button. Click the link How to use the SRC button.
To post code use SRC button makes it more readable see other topics how code looks like using it
your problem..... might be
//+--------define function----------------------------------------------------------+ double GetStoch(int mode, int shift) { double x = iStochastic(NULL, 0, StochKPeriod, StochDPeriod, StochSlowing, MODE_SMA, 0, mode, shift); //Sto exported correct return (x); } //+------------------------------------------------------------------+ double getrsi(int period, int shift) { double x= iRSI(NULL,0,rsiperiod,PRICE_CLOSE,0); // RSI of the last date on chart instead of the date in the input file return (x); } //+------------------------------------------------------------------+
![]() Play video | Please edit your post. For large amounts of code, attach it. |
Thank you.
It is the bug.
:-)
Have a nice weekend.
HHC
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am trying to export data from MT4 to excel for a list of date recorded in the input file.
The High, low, close and Sto is exported correct to the output file but I cannot get the RSI information out.
This code return the value of RSI of the last date on chart instead of the date in the input file.
Could you please look at the short code below and correct my error?
Any help is very much appreciated.
Thank you,
HHC
//+------------------------------------------------------------------+
//| ExportData.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, tidicofx"
#property link "tidicofx@yahoo.com"
#property show_inputs
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#include <stderror.mqh>
//+------------------------------------------------------------------+
extern string datefeed = "date.txt";
extern int StochKPeriod = 5;
extern int StochDPeriod = 3;
extern int StochSlowing = 3;
extern int rsiperiod = 14;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//------------------------------------------------------------------
string file = Symbol() + "_" + GetTimeFrameName(0) + ".csv";
int log = FileOpen(file, FILE_CSV|FILE_WRITE, ";");
int log2 = FileOpen(datefeed, FILE_CSV|FILE_READ, ";");
if (log < 0 || log2 < 0) return (0);
string buffer, buff;
buffer = "Rate;TimeFrame;Date;Hour_Minute;Open;Close;High;Low;Up/Down";
buffer = buffer + ";Sto_fast5;Sto_slow3;RSI14";
FileWrite(log, buffer);
buff = "";
int i = 0;
while (!FileIsEnding(log2))
{
i++;
buff = FileReadString(log2);
if (buff == "") continue;
datetime time = StrToTime(buff);
int bar = iBarShift(NULL, 0, time);
buffer = Symbol() + ";" + GetTimeFrameName(0) + ";" + TimeToStr(Time[bar], TIME_DATE) + ";" + TimeToStr(Time[bar], TIME_MINUTES)
+ ";" + DoubleToStr(Open[bar], Digits) + ";" + DoubleToStr(Close[bar], Digits) + ";" + DoubleToStr(High[bar], Digits) + ";" + DoubleToStr(Low[bar], Digits);
if (Close[bar] > Open[bar]) buffer = buffer + ";1";
else if (Close[bar] < Open[bar]) buffer = buffer + ";2";
else buffer = buffer + ";0";
buffer = buffer + ";" + DoubleToStr(GetStoch(MODE_MAIN, bar), Digits-1);
buffer = buffer + ";" + DoubleToStr(GetStoch(MODE_SIGNAL, bar), Digits-1);
buffer = buffer + ";" + DoubleToStr(getrsi(rsiperiod, bar), Digits-1);
FileWrite(log, buffer);
}
FileClose(log);
FileClose(log2);
MessageBox("Finished writing " + i + " rows into " + TerminalPath() + "\\experts\\files\\" + file);
//------------------------------------------------------------------
return(0);
}
//+--------define function----------------------------------------------------------+
double GetStoch(int mode, int shift)
{
double x = iStochastic(NULL, 0, StochKPeriod, StochDPeriod, StochSlowing, MODE_SMA, 0, mode, shift);
return (x);
}
//+------------------------------------------------------------------+
double getrsi(int period, int shift)
{
double x= iRSI(NULL,0,rsiperiod,PRICE_CLOSE,0);
return (x);
}
//+------------------------------------------------------------------+
string GetTimeFrameName(int TimeFrame)
{
switch (TimeFrame)
{
case PERIOD_M1: return("M1");
case PERIOD_M5: return("M5");
case PERIOD_M15: return("M15");
case PERIOD_M30: return("M30");
case PERIOD_H1: return("H1");
case PERIOD_H4: return("H4");
case PERIOD_D1: return("D1");
case PERIOD_W1: return("W1");
case PERIOD_MN1: return("MN1");
case 0: return(GetTimeFrameName(Period()));
}
}
//+------------------------------------------------------------------+