Download MetaTrader 5

File Writing wrongly

To add comments, please log in or register
Mimi
507
Mimi  
Hi, With the following code, I am getting Open_DG , Symbol(), Date all correctly but in case of OPEN,HIGH,LOW,CLOSE, BAR all are writing same value all the time. I mean so OPEN= HIGH = LOW = CLOSE all showing same value for a day. The loop value printing is also wrong with e_P

I am back testing this EA on daily chart with Open price only.

double Open_DG = Calculation;
   int count = 0;
   
   double OPEN = iOpen(Symbol(),PERIOD_D1,0);
   double HIGH = iHigh(Symbol(),PERIOD_D1,0);
   double LOW = iLow(Symbol(),PERIOD_D1,0);
   double CLOSE = iClose(Symbol(),PERIOD_D1,0);
   string BAR;
   if(CLOSE > OPEN) BAR = "Bull";
   else if(CLOSE < OPEN) BAR = "Bear";
   else BAR = "Doji";
   
   for(int g=1 ; g <=10 ; g++)
    { 
       if(MathAbs(Open_DG - D[g]) <=2)
       {
       count++;
       if(count==1) e_P = PName[g];
       else 
       e_P = StringConcatenate(e_P,",",PName[g]); 
      
       }
    }

//----------------------- Writing------------------------------------------

 
  int file_handle=FileOpen("PCSV.csv",FILE_READ|FILE_WRITE|FILE_CSV,',');
  if(file_handle!=INVALID_HANDLE )
    {
     
      FileSeek(file_handle, 0, SEEK_END);

      FileWrite(file_handle,TimeToString(TimeCurrent(),TIME_DATE),Symbol(),DoubleToString(Open_DG,0),DoubleToString

(OPEN,5),DoubleToString(HIGH,5),DoubleToString(LOW,5),DoubleToString(CLOSE,5),BAR,e_P);
      FileFlush(file_handle);
      
      //--- close the file
     FileClose(file_handle);
  
     }
   else
    PrintFormat("Failed to open %s file, Error code = %d",File_Name,GetLastError());

 

Any idea?

Thank you in advance. 

peter.MT4Web
157
peter.MT4Web  

If you do this on the first tick of a day OHLC are equal.

And what does "The loop value printing is also wrong with e_P" mean ?

rod178
272
rod178  
change

   double OPEN = iOpen(Symbol(),PERIOD_D1,0);
   double HIGH = iHigh(Symbol(),PERIOD_D1,0);
   double LOW = iLow(Symbol(),PERIOD_D1,0);
   double CLOSE = iClose(Symbol(),PERIOD_D1,0);

to

   double OPEN = iOpen(Symbol(),PERIOD_D1,1);
   double HIGH = iHigh(Symbol(),PERIOD_D1,1);
   double LOW =   iLow(Symbol(),PERIOD_D1,1);
   double CLOSE = iClose(Symbol(),PERIOD_D1,1);
Mimi
507
Mimi  
rod178:

I applied your suggestion. But does shows different data but its shows last days data as it get changed from 0 to 1.

So I applied again with little customisation:

   double OPEN = iOpen(Symbol(),PERIOD_D1,0);
   double HIGH = iHigh(Symbol(),PERIOD_D1,1);
   double LOW = iLow(Symbol(),PERIOD_D1,1);
   double CLOSE = iClose(Symbol(),PERIOD_D1,1);

 Now it shows open price correct, but HIGH LOW is last day. Plus CLOSE Price is always wrong.

I tested the EA from 1st October, 2016 to 26th October, 2016. Today is 27th. So on the last row of CSV file it shows 26th October 2 times, on 2nd time it shows HIGH LOW correctly with 26th Data. But CLOSE Price is wrong again. (please see the picture)

I am totally clueless.

Mimi
507
Mimi  
eddie:

If you do this on the first tick of a day OHLC are equal.

And what does "The loop value printing is also wrong with e_P" mean ?

Currently I am using OnTick(), If I use Start() function then will it make any differences?

e_P variable contains string data either in this format

e_P = "A";

or

e_P = "A,B,C" as long as condition satisfies.

In current case e_P is printing wrongly see the picture please.

 

 

from  2016.10.13 to 2016.10.18 its e_P is showing F, but e_P is actually get calculated with Open_DG which is different. According to the calculation 17 to 18th October it should Not be printing F.

So its wrong. Hope I am clear. 

rod178
272
rod178  
cashcube:

I applied your suggestion. But does shows different data but its shows last days data as it get changed from 0 to 1.


that is what it is supposed to do.

Think of it this way, using 0 you are trying to read data which has not yet been produced, except for the Open, all are incomplete.

Fernando Carreiro
2202
Fernando Carreiro  

cashcube: I am back testing this EA on daily chart with Open price only.

... Currently I am using OnTick(), If I use Start() function then will it make any differences? ...

  • If you are only testing with "Open price only", you will only get Open=High=Low=Close for every emulated tick of data tested. However, as by "rod178" suggestion, previous bars will have the full OHLC values. The current bar however, will only have the Open Price, so consider using another method of testing, such as for every tick method.
  • Start() is the older format for the newer OnTick() event handler. So use the updated modern style!
Mimi
507
Mimi  

Thank you rod178 & FMIC for pointing out. I can not use every tick method because, it produces lots of data for each tick. Then I guess I have to part it, one part where Open price can flawlessly used & another part I download the .csv file of OHLC directly from Metatrader & merge two files.

Those job will be hectic, that's why gone out for coding, but that's ok now.

To add comments, please log in or register