waiting for update of offline charts

 

Hi guys,

I have created some .hst files from .csv for single pairs. All single pairs can be loaded and permanently updated as offline charts (equally to 'period converter'). I have no problems, all is visible and works. But from this pairs I made clustercharts (e.g. USDJPY, EURJPY, AUDJPY, CADJPY, GBPJPY form a JPY-cluster ) with .hst files in the same manner as Ive made the single .hst charts. But MT4 doesnt want to show me the chart, Im still -waiting for update-. Ive controlled the hst datas, all seems to be correct. As well the hst header is perfect. I cant find my mistake. I would be very grateful if anybody could help me. Over the years this forum helped me alot to improve my knowledges, Ive read all about the subject here and I thought its enough spoken about this subject, but now Ive found my personal end.


The data structure of the records is as follows (example for one record):

1378921500 (time) 577.429 (Open) 577.329(Low) 577.64 (High) 577.544 (Close) 6020 (volume). Im sure that in the complete file isnt any data error. (e.g. open < high && open > low and close>low,...., high>low,...., no negative number, no zero value).

I have no idea what I can still do to solve the problem. Any help is welcome.

Johann

//+------------------------------------------------------------------+
//|                                          Cluster_symb_groups.mq4 |
//|                                             edszigarski@gmail.de |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "edszigarski@gmail.de"
#property show_inputs
#include <WinUser32.mqh>
extern string symb ="USD";
int strategy = 0;
int basePer=15;
string Symbols[5]={"#AUDUSD","#USDCAD","#EURUSD","#GBPUSD","#USDJPY"};//offline charts
string _Symb[5];//trade advice
double RefClose[5];//reference values 
double Val[1000000][6];//records time,open,low,high,close,vol
double RefValue;//sum of RefClose
double open,low,high,close;
int time,volume;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(strategy == 0){//extern input for testing
_Symb[0] = "+AUDUSD";//'+' -->buy
_Symb[1] = "-USDCAD";//'-'-->sell
_Symb[2] = "-EURUSD";
_Symb[3] = "-GBPUSD";
_Symb[4] = "+USDJPY";
}
string cluster_f_name = StringConcatenate(symb,"Strat_0.hst");//filename

int limit = iBars("#EURUSD",basePer)-1;//getRefBar-->first equal Bar for all pairs

int refBar,refT;
bool found = false;
for(int i = limit;i>=0;i--){
   refT=iTime("#EURUSD",basePer,i);//#EURUSD is reference pair--offline chart
   for(int j = 0;j<5;j++)  {
      if(iBarShift(Symbols[j],basePer,refT,true)<0)break;
      if(j==4)found= true;
   }
   if(found){refBar=i;break;}
}  
Print("ReferenzBar ",refBar);
//--GetRefValues for all pairs
int dig,bar;
for(j = 0;j<5;j++){
   dig=MarketInfo(StringSubstr(Symbols[j],1),MODE_DIGITS);//active chart
   bar=iBarShift(Symbols[j],basePer,refT,true);
   //RefClose for single pairs
   RefClose[j]=iClose(Symbols[j],basePer,bar)*MathPow(10,dig);//Normalize values 
   RefValue+=RefClose[j];
}
   RefValue*=10;//no negative values for later controlling of results
   
   //FileHeader 
//**********************************************************************************************
int cnt_add;
int header_dig=3;
int Temp[13];
int    version=400;
string header_name ="#USD";
string file_name = StringConcatenate("Cluster ",symb," Strategy_",strategy,"_Period",basePer,".hst");
int HistoryHandle = FileOpenHistory( file_name, FILE_BIN | FILE_WRITE );
     if ( HistoryHandle < 0 ){
              Alert( "FileOpenHistory( \"", file_name, "\", FILE_BIN | FILE_WRITE )"," - Error #", GetLastError() );
                   return(-1);
          }
//---- Write the file heading
          FileWriteInteger(HistoryHandle, version, LONG_VALUE);
          FileWriteString       ( HistoryHandle, "Copyright © 2013, Johann", 64 );
          FileWriteString       ( HistoryHandle, header_name, 12 );
          FileWriteInteger      ( HistoryHandle, basePer, LONG_VALUE );//basePer = 15
          FileWriteInteger      ( HistoryHandle, header_dig, LONG_VALUE );//digits=3
          FileWriteInteger      ( HistoryHandle, 0, LONG_VALUE );       //timesign
          FileWriteInteger      ( HistoryHandle, 0, LONG_VALUE );       //last_sync
          FileWriteArray                ( HistoryHandle, Temp, 0, 13 ); 

//calculate records
int time;
bool mist=false;//mistake

for(i=refBar-1;i>0;i--){
         Val[i][0]=0;//time
         Val[i][1]=0;//open
         Val[i][2]=0;//low 
         Val[i][3]=0;//high 
         Val[i][4]=0;//close 
         Val[i][5]=0;//volume
         time=iTime("#EURUSD",basePer,i);//#EURUSD is reference pair
         if(time<=0){
            Print("No data from #EURUSD; Open chart !!!");
            return;
         }
         mist=false;
         for(j = 0;j<5;j++){
            bar=iBarShift(Symbols[j],basePer,time,true);
            if(bar<0){
               mist=true;
               break;
            }
            else{
               dig=MarketInfo(StringSubstr(Symbols[j],1),MODE_DIGITS);
               Val[i][0]=time;
               Val[i][5]+=iVolume (Symbols[j],basePer,bar); 
               //Buy
               if(StringSubstr(_Symb[j],0,1)=="+"){
                  Val[i][1]+=iOpen(Symbols[j],basePer,bar)*MathPow(10,dig);
                  Val[i][2]+=iLow(Symbols[j],basePer,bar)*MathPow(10,dig);
                  Val[i][3]+=iHigh(Symbols[j],basePer,bar)*MathPow(10,dig);
                  Val[i][4]+=iClose(Symbols[j],basePer,bar)*MathPow(10,dig);
            
               }
               //Sell
               if(StringSubstr(_Symb[j],0,1)=="-"){
                  Val[i][1]+=RefClose[j]-iOpen (Symbols[j],basePer,bar)*MathPow(10,dig)+ RefClose[j];
                  Val[i][3]+=RefClose[j]-iLow (Symbols[j],basePer,bar)*MathPow(10,dig)+ RefClose[j];
                  Val[i][2]+=RefClose[j]-iHigh (Symbols[j],basePer,bar)*MathPow(10,dig)+ RefClose[j];
                  Val[i][4]+=RefClose[j]-iClose (Symbols[j],basePer,bar)*MathPow(10,dig)+ RefClose[j];
               }
            }//else
         }//j
         //write FILE_BIN
         //*********************************************************************
         if(mist) continue;//no data writing in case of error
         time=Val[i][0];
         open= Val[i][1]/1000;
         low=Val[i][2]/1000;
         high=Val[i][3]/1000;
         close=Val[i][4]/1000;
         volume=Val[i][5];
         //check for data errors
         if(open<low ||open>high ||close<low||close>high||low>high||time<=0||volume<0){
            Print("data error 1 Bar # ",i);
            continue;
         }
         if(high>0&&low>0&&open>0 &&close>0&&time>0)   {//write
                   FileWriteInteger     ( HistoryHandle,time ,          LONG_VALUE      );                       
                             FileWriteDouble    ( HistoryHandle,open,           DOUBLE_VALUE);                  
                             FileWriteDouble    ( HistoryHandle, low,           DOUBLE_VALUE);                      
                             FileWriteDouble    ( HistoryHandle, high,          DOUBLE_VALUE);                      
                             FileWriteDouble    ( HistoryHandle, close,   DOUBLE_VALUE);                     
                             FileWriteDouble    ( HistoryHandle, volume,        DOUBLE_VALUE); 
                             FileFlush                  ( HistoryHandle );
                             cnt_add ++;
         }
         else
            Print("data error 2 Bar #  ",i);
   }//for i
   
   FileClose(HistoryHandle);
   //refresh
   refresh(symb,basePer,header_name);
   Print(file_name,"  ",cnt_add, " Bars created");
//----

   return(0);
  }
//+------------------------------------------------------------------+
//refresh chart Window
    void refresh(string symbol, int period,string header_name)
    {
      if(symbol==Symbol())Print(RefreshRates(),"  refresh");
      string  WindowSymbol=header_name;
      if(!IsDllsAllowed())Alert("DLL must be allowed");
      int hwnd = WindowHandle(WindowSymbol,period);
            if(hwnd>0)
            {
              PostMessageA(hwnd, WM_COMMAND,33324,0);
               hwnd=0;
            }
            else
            Print("window <",WindowSymbol,"> not found--no refreshing !!!" );
     }
 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Look at any offline generator. They all do a post message update to any active offline chart.
  3. And don't they all close the file so mt4 can read it?
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Look at any offline generator. They all do a post message update to any active offline chart.
  3. And don't they all close the file so mt4 can read it?

Thank you very much WHRoeder. I have inserted the complete code.


Johann

 
string file_name = StringConcatenate("Cluster ",symb," Strategy_",strategy,"_Period",basePer,".hst");
int basePer=15;
You use an unexpected file name, moreover the timeframe would interfere with the online chart (if the name was correct).
 
Ovo:
You use an unexpected file name, moreover the timeframe would interfere with the online chart (if the name was correct).

Ovo, Im slow on the uptake. Thank you so much. What a stupid mistake! I have overwritten a former filename declaration

string cluster_f_name = StringConcatenate(symb,"Strat_0.hst");//filename

to

string file_name = StringConcatenate("Cluster ",symb," Strategy_",strategy,"_Period",basePer,".hst");

My correct use is now: file_name = StringConcatenate(symb,basePer,".hst"); while symb ="#USD" (ClusterSymbol) and baseper = 15.

Im very very grateful.

Johann