micro time frame

 
any one know how to plug in 5 second chart or time frame in Meta trader?
 
Possible with a custom period converter yet I wasn't able to get a historical data, so live only (MT4)
 
Alexander Sinitsyn:
Possible with a custom period converter yet I wasn't able to get a historical data, so live only (MT4)

Hi Alexander Sinitsyn,

can you share the period converter to me?thanks for your help 

 

As far as I know tick history isn't available in MT4, I wrote something for MT5 but it's still let's call it "early stages".

//+--------------------------------------------------------------------------+
//|                                                        i15secProject.mq5 |
//+--------------------------------------------------------------------------+

#property copyright "Copyright 2017, МегаКурец Software Corp."

#property indicator_chart_window

input int Секунди = 15;
input int БройСвещи = 200;
input bool ОтделнаГрафика = true;
input string Шаблон = "muh_template.tpl";

MqlTick muhTickArray[], muhLastBarTickArray[];
MqlRates muhBarArray[], muhLastBarArray[];
double muhTickArrayPrice[],muhLastBarTickArrayPrice[];
datetime starttime, endtime, kyppenttime, kyppentcalctime, startdrawtime, enddrawtime;
int muhMarkFirstTickArray[];

string csname = Symbol()+"."+IntegerToString(Секунди)+"секунди";
long thisChart, nextChart, muhChart;
int endbar;

int OnInit()
  {
   CustomSymbolCreate(csname);
   CustomSymbolSetInteger(csname,SYMBOL_DIGITS,SymbolInfoInteger(Symbol(),SYMBOL_DIGITS));
   SymbolSelect(csname,true);

   if(ОтделнаГрафика==true && ObjectFind(0,"Секундичка")<0)
     {
      ChartOpen(csname,PERIOD_M1);

      thisChart=ChartFirst();
      nextChart=0;
      muhChart=0;

      while(muhChart==0 && nextChart>=0)
        {
         nextChart=ChartNext(thisChart);
         if(ChartSymbol(nextChart)==csname)
           {
            muhChart=nextChart;
            thisChart=ChartID();
            ObjectCreate(thisChart,"Секундичка",OBJ_ARROW_CHECK,0,TimeCurrent(),0.5*(ChartGetDouble(thisChart,CHART_PRICE_MIN)+ChartGetDouble(thisChart,CHART_PRICE_MAX)));
            ObjectSetInteger(thisChart,"Секундичка",OBJPROP_SELECTABLE,true);
           }
         else thisChart=nextChart;
        }

      ChartApplyTemplate(muhChart,Шаблон);
      ChartSetInteger(muhChart,CHART_SCALEFIX,true);
      ChartSetInteger(muhChart,CHART_SHOW_DATE_SCALE,false);
     }

   if(ОтделнаГрафика==false && ObjectFind(0,"Секундичка")<0)
     {
      ObjectCreate(0,"Секундичка",OBJ_CHART,0,0,0);
      ObjectSetInteger(0,"Секундичка",OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSetInteger(0,"Секундичка",OBJPROP_XDISTANCE,10);
      ObjectSetInteger(0,"Секундичка",OBJPROP_YDISTANCE,25);
      ObjectSetInteger(0,"Секундичка",OBJPROP_XSIZE,400);
      ObjectSetInteger(0,"Секундичка",OBJPROP_YSIZE,300);
      ObjectSetInteger(0,"Секундичка",OBJPROP_DATE_SCALE,0);
      ObjectSetString(0,"Секундичка",OBJPROP_SYMBOL,csname);
      ObjectSetInteger(0,"Секундичка",OBJPROP_PERIOD,PERIOD_M1);
      ObjectSetInteger(0,"Секундичка",OBJPROP_SELECTABLE,true);
     }

   ArrayResize(muhBarArray,БройСвещи);
   ArrayResize(muhLastBarArray,1);
   ArrayResize(muhMarkFirstTickArray,БройСвещи+1);

   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]
                )
  {
   int n, y, t, k, a;

   kyppenttime=TimeCurrent();
   if(ChartGetInteger(0,CHART_AUTOSCROLL==true)) kyppentcalctime=kyppenttime;
   if(ChartGetInteger(0,CHART_AUTOSCROLL==false))
     {
      endbar=rates_total-ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR)+ChartGetInteger(0,CHART_WIDTH_IN_BARS);
      if(endbar>=rates_total) kyppentcalctime=kyppenttime;
      else kyppentcalctime=time[endbar];
     }

   if(endtime<kyppentcalctime-Секунди || endtime>=kyppentcalctime)
     {
      endtime=Секунди*floor(kyppentcalctime/Секунди);
      starttime=endtime-(Секунди*БройСвещи);
      enddrawtime=Секунди*floor(kyppenttime/Секунди);
      startdrawtime=enddrawtime-(Секунди*БройСвещи);

      if(CopyTicksRange(Symbol(),muhTickArray,COPY_TICKS_ALL,1000*starttime,1000*endtime)<0) Print("да го ева");

      int muhTickArraySize = ArraySize(muhTickArray);
      ArrayResize(muhTickArrayPrice,muhTickArraySize);

      for(k=0; k<muhTickArraySize; k++) muhTickArrayPrice[k]=muhTickArray[k].bid;

      y=1;
      muhMarkFirstTickArray[0]=0;
      muhMarkFirstTickArray[БройСвещи]=muhTickArraySize-1;

      for(n=1; n<muhTickArraySize; n++)
        {
         if(muhTickArray[n].time_msc>=1000*(starttime+y*Секунди))
           {
            muhMarkFirstTickArray[y]=n;
            y++;
           }
        }

      for(t=0; t<БройСвещи; t++)
        {
         muhBarArray[t].open=muhTickArrayPrice[muhMarkFirstTickArray[t]];
         muhBarArray[t].low=muhTickArrayPrice[ArrayMinimum(muhTickArrayPrice,muhMarkFirstTickArray[t],muhMarkFirstTickArray[t+1]-muhMarkFirstTickArray[t])];
         muhBarArray[t].high=muhTickArrayPrice[ArrayMaximum(muhTickArrayPrice,muhMarkFirstTickArray[t],muhMarkFirstTickArray[t+1]-muhMarkFirstTickArray[t])];
         muhBarArray[t].close=muhTickArrayPrice[muhMarkFirstTickArray[t+1]-1]; 
         muhBarArray[t].tick_volume=MathMax(muhMarkFirstTickArray[t+1]-muhMarkFirstTickArray[t],0);
         muhBarArray[t].time=enddrawtime-(БройСвещи-t+1)*60;
        }

      CustomRatesReplace(csname,enddrawtime-БройСвещи*60,enddrawtime,muhBarArray);
     }

   if(kyppentcalctime==kyppenttime)
     {
      CopyTicks(Symbol(),muhLastBarTickArray,COPY_TICKS_ALL,1000*endtime,0);
      
      int muhLastBarTickArraySize = ArraySize(muhLastBarTickArray);
      ArrayResize(muhLastBarTickArrayPrice,muhLastBarTickArraySize);
   
      for(a=0; a<muhLastBarTickArraySize; a++) muhLastBarTickArrayPrice[a]=muhLastBarTickArray[a].bid;
   
      muhLastBarArray[0].open=muhLastBarTickArrayPrice[0];
      muhLastBarArray[0].low=muhLastBarTickArrayPrice[ArrayMinimum(muhLastBarTickArrayPrice,0,0)];
      muhLastBarArray[0].high=muhLastBarTickArrayPrice[ArrayMaximum(muhLastBarTickArrayPrice,0,0)];
      muhLastBarArray[0].close=muhLastBarTickArrayPrice[muhLastBarTickArraySize-1];
      muhLastBarArray[0].tick_volume=muhLastBarTickArraySize;
      muhLastBarArray[0].time=enddrawtime;
   
      CustomRatesReplace(csname,enddrawtime-60,enddrawtime+60,muhLastBarArray);
     }

   return(rates_total);
  }

void OnDeinit(const int reason)
  {
   if(reason!=REASON_RECOMPILE && reason!=REASON_CHARTCHANGE) ObjectDelete(0,"Секундичка");
   SymbolSelect(csname,false);
   CustomSymbolDelete(csname);
   Comment("");
  }

//+--------------------------------------------------------------------------+

You need to change the timeframe of the base chart a few (dozen) times so it can reinitialize after all the errors and it may or may not work.

It also write too much too often to disk and I don't know how to fix it, any help is appreciated.