//+------------------------------------------------------------------+ //| TkzToCustom.mq5 | //| Loads a .tkz archive into a custom symbol, so the stored tick | //| history can be used in charts and in the Strategy Tester. | //+------------------------------------------------------------------+ #property copyright "TKZ tick compression" #property version "1.1" #property description "Loads the ticks of a .tkz archive into a custom symbol (CustomTicksReplace)." #property script_show_inputs #include "../lib/TkzArchive.mqh" input string InpFile=""; // Archive file (empty = .tkz) input bool InpCommon=false; // File is in the common data folder input string InpCustom=""; // Custom symbol name (empty = .tkz) input string InpOrigin=""; // Copy symbol properties from (empty = archive symbol) //+------------------------------------------------------------------+ void OnStart() { string file=(InpFile=="") ? _Symbol+".tkz" : InpFile; CTkzReader reader; if(!reader.Open(file,InpCommon)) { PrintFormat("TKZ: cannot open %s: %s",file,reader.LastError()); return; } string base=reader.ArchiveSymbol(); string custom=(InpCustom=="") ? base+".tkz" : InpCustom; string origin=(InpOrigin=="") ? base : InpOrigin; bool is_custom=false; if(SymbolExist(custom,is_custom)) { if(!is_custom) { PrintFormat("TKZ: %s exists and is not a custom symbol",custom); return; } } else { bool origin_custom=false; bool have_origin=SymbolExist(origin,origin_custom); ResetLastError(); bool created=have_origin ? CustomSymbolCreate(custom,"TKZ",origin) : CustomSymbolCreate(custom,"TKZ"); if(!created) { PrintFormat("TKZ: CustomSymbolCreate(%s) failed, error %d",custom,GetLastError()); return; } if(!have_origin && reader.ArchiveDigits()>=0) CustomSymbolSetInteger(custom,SYMBOL_DIGITS,reader.ArchiveDigits()); } MqlTick ticks[]; long total=0; int failed=0; ulong t0=GetMicrosecondCount(); for(int i=0; i