modify script

 

I have this code:

/*----------------------------------------------------------------|
// Indicator Export Expert v1, by juanchoc & neo |
//----------------------------------------------------------------|
// |
// |
// This EA was made to easily export indicators results |
// to CSV files for further manipulation and/or analisis |
// of them. |
// |
// Instructions: |
// Modify the InitializeHeaderFile() function so that it |
// displays the CSV column headers in the same order |
// you set the indicators. |
// Modify the WriteHistoryData() function so that it |
// displays the indicators you want to export (remember |
// to place them on the same order you used on the |
// InitializeHeaderFile()). |
// Compile the expert. |
// Run the expert on the desired time range using the |
// Strategy Tester. |
// Results are saved at your MetaTrader/tester/files/ |
// folder. |
// |
// |
// ***PLEASE DONT MODIFY OR DELETE THIS HEADER** |
// Copyright 2006, by juanchoc & neo. |
// juan@forexproyect.com.ar |
//---------------------------------------------------------------*/
#property copyright "#copyright#"
#property link "#link#"

#include <WinUser32.mqh>

int CSVHandle = -1;


int OpenHistoryFile()
{
string name;

name = Symbol() + "_DATA";
CSVHandle = FileOpen(name + ".csv", FILE_CSV|FILE_WRITE, ',');
if (CSVHandle < 0) return(-1);
return (0);
}

int InitializeHeaderFile()
{
FileWrite(CSVHandle,
"DATE",
"TIME",
"OPEN",
"HIGH",
"LOW",
"CLOSE",
"VOLUME",
"SMA_CLOSE_20",
"EMA_CLOSE_20",
"SMMA_CLOSE_20",
"LWMA_CLOSE_20",
"ATR",
"CCFp"
);

}

static double d_open, d_low, d_high, d_close, d_volume;
static int i_time;

void WriteHistoryData()
{

if (CSVHandle >= 0) {
int i_digits = Digits;

FileWrite(CSVHandle,
TimeToStr(Time[0], TIME_DATE),
TimeToStr(Time[0], TIME_MINUTES),
DoubleToStr(Open[0], i_digits),
DoubleToStr(High[0], i_digits),
DoubleToStr(Low[0], i_digits),
DoubleToStr(Close[0], i_digits),
Volume[0],
iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0),
iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0),
iMA(NULL,0,20,0,MODE_SMMA,PRICE_CLOSE,0),
iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,0),
iATR(NULL,0,20,0),
iCCI(NULL,0,20,PRICE_CLOSE,0)
);
}
}

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
OpenHistoryFile();
InitializeHeaderFile();
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
if (CSVHandle >= 0) {
FileClose(CSVHandle);
CSVHandle = -1;
}

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
WriteHistoryData();
//----
return(0);
}
//+------------------------------------------------------------------+


It is supposed to save the data of the mentioned indicators aside from the standard open, high, low, close data. However I applied it to a chart but it did not work. Could anyone let me know what is wrong with it?


All I am trying to do is export the output from the CCFp indicator from this thread -> https://www.mql5.com/en/articles/1464


Thank you!

 
blank_jack:

I have this code:


blank_jack:

It is supposed to save the data of the mentioned indicators aside from the standard open, high, low, close data. However I applied it to a chart but it did not work. Could anyone let me know what is wrong with it?

As long as it's attached to a chart it'll keep writing bars - you can't read the file until you detach the EA. Yesterday the market was closed, no bars.

What do you mean 'it did not work'? No mind readers here.

 
WHRoeder:

As long as it's attached to a chart it'll keep writing bars - you can't read the file until you detach the EA. Yesterday the market was closed, no bars.

What do you mean 'it did not work'? No mind readers here.

Hello,

I apologize for not using the code button and for not being clear enough.

The reason why I thought it wasn't working was because I tried during the weekend and as the market was not open it did not write anything. I tried now and it does work.

Still in this shape the script has no value to me - can someone let me know how it should look so that it does not write the values of the indicators on every tick, but only when a bar closes as well as how to include it to export the indicator mentioned above,

thank you!

 
  1. can someone let me know how it should look so that it does not write the values of the indicators on every tick
    int start(){
        static datetime Time0;  bool    newBar  = Time0 < Time[0];
        if (!newBar) return(0);                   Time0 = Time[0];
        // write bar 1 data..

  2. how to include it to export the indicator mentioned above
    iCustom()
Reason: