Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1129

 
miss.natasha:

I need to write data to an hst file, so that I can use the data to build an autonomous graph.

I've been struggling for two days but nothing works.

Code:

#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
ulong    last_fpos=0;         //
int      HandleHistory=-1;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string symbol=Symbol();
   int per=Period()*9;

   ResetLastError();
   if(CreateHeader()==true)//если создали заголовок
     {
      HandleHistory=FileOpenHistory(symbol+(string)per+".hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);
      if(HandleHistory!=INVALID_HANDLE)
        {

         for(int i=199;i>0;i--)//заполняем данными
           {
            MqlRates r;
            r.time=Time[i];//просто пытаюсь записать, это так для примера
            r.open=Open[i];//просто пытаюсь записать, это так для примера
            r.low=Low[i];
            r.high=High[i];
            r.close=Close[i];
            r.tick_volume=(long)10;
            r.spread=0;
            r.real_volume=(long)10;
            uint byteswritten=FileWriteStruct(HandleHistory,r);
            Print("FileOpen OK ",byteswritten," ",Time[i]);
           }
       FileClose(HandleHistory);
       // FileFlush(HandleHistory);
        }
      else Print("Операция FileOpen неудачна, ошибка ",GetLastError());
     }
// long id=ChartOpen(symbol,per);
//Alert(id);
  }
//+------------------------------------------------------------------+
bool CreateHeader()//создаем файл с историей hst(заголовок)
  {

   int      file_version=401;
   string   c_copyright;
   string   c_symbol=Symbol();
   int i_period=Period()*9;
   int      i_digits=Digits;
   int      i_unused[13];
//---  
   ResetLastError();
   HandleHistory=FileOpenHistory(c_symbol+(string)i_period+".hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);
   if(HandleHistory<0)
     {
      Print("Error open ",c_symbol+(string)i_period,".hst file ",GetLastError());
      return(false);
     }
   c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";
   ArrayInitialize(i_unused,0);
//--- write history file header
   FileWriteInteger(HandleHistory,file_version,LONG_VALUE);
   FileWriteString(HandleHistory,c_copyright,64);
   FileWriteString(HandleHistory,c_symbol,12);
   FileWriteInteger(HandleHistory,i_period,LONG_VALUE);
   FileWriteInteger(HandleHistory,i_digits,LONG_VALUE);
   FileWriteInteger(HandleHistory,0,LONG_VALUE);
   FileWriteInteger(HandleHistory,0,LONG_VALUE);
   FileWriteArray(HandleHistory,i_unused,0,13);
   return(true);
  }

As a result of execution a file with history is created, but autonomous graph is not created.

Here's the info on the graph

For some reason, the data is from 2003!

As a result, I get an error when I launch the chart HistoryBase: 196 errors in 'NZDCHF45'.

I understand that I wrote something wrong. I don't know how to correctly write it, I have too little information. Who knows - please advise.


I don't remember MQ officially opening .hst file structure (if they do, check official specs)

maybe this is an excerpt from a very, very old project (C, gcc) :


/* .hst file header
*/
struct HstHeader {
    uint32_t    version;        // +0 4 LE  : database version
    char        copyright[64];  // +4 64    : copyright data
    char        symbol[12];     // +68 12   : symbol (EURUSD..)
    uint32_t    period;         // +80 4 LE : timeframe (sec. in period)
    uint32_t    digits;         // +84 4 LE : decimals after .
    datetime    timesign;       // +88 4 LE : creation time sign.
    datetime    last_sync;      // +92 4 LE : last sync. timestamp
    uint8_t     unused[52];     // +96 52   : reserved for feauture use
                                // total 148 bytes, packed, aligned by 1
};

/* .hst bar array (file payload)
*/
// when HstHeader.version==400
struct HstRates400 {
    datetime    ctm;            // +0 4 LE  : start (creation) time
    double      open;           // +4 8 LE  : open price
    double      low;            // +12 8 LE : lowest price
    double      high;           // +20 8 LE : highst price
    double      close;          // +28 8 LE : close price
    double      volume;         // +36 8 LE : volume (nr of ticks)
                                // total 44 bytes,packed, aligned by 1
} __attribute__((packed));

// when HstHeader.version==401

struct HstRates401 {
    datetime    ctm;            // +0 8 LE  : bar start time (with ms?)
    double      open;           // +8 8 LE  : open price
    double      low;            // +16 8 LE : lowest price
    double      high;           // +24 8 LE : highst price
    double      close;          // +32 8 LE : close price
    uint64_t    volume;         // +40 8 LE : volume (nr of ticks)
    uint32_t    spread;         // +48 4 LE : spread
    long        real_volume;    // +52 8 LE : real volume
                                // total 60 bytes,packed,aligned by 1
} __attribute__((packed));


now, after many years, i'm not sure if high/low should be in that order, but check that your structures are at least the same size (header and record)
 

Hi all, just continuing to refine what we already have

We have an irregular grid of orders and a horizontal line which can be anywhere

We need to implement this:

if the price is below the line close all orders

The difficulties are as follows

1) if the orders are of non-uniform type and already when setting the line everything is done, and not when we put the marking and set the line (in this case we should also set the on/off flag)

2) Implementation of an inscription on the top right of the line by type (if the order is closed at this price, the result will be the same for the balance, i.e., we have to change the display every tick and also when moving the line; it is generally similar to a trailing stop or sl if the order is placed manually, only floating and with the possibility of erroneous triggers initially)

The robot is there, except for the numerical marker everything is already drawn, the question is in the correct assignment of values and information processing of the whole grid.

Files:
USDCHFH1.png  26 kb
 
trader781:


1) if the orders are of an irregular type

This is the first time I have heard of them.
 
Hello. I don't understand why iTime sometimes shows the wrong time. On opening a new candle PERIOD_H1 should show the time in the Print(iTime(NULL,PERIOD_M1,30)) log. It displays everything correctly in tests, but in reality the time is sometimes different even by several hours. Why is it so?
 
Nauris Zukas:
Hello. I don't understand why iTime sometimes gives the wrong time. At the opening of a new candle PERIOD_H1 should show the time in the log Print(iTime(NULL,PERIOD_M1,30)). It displays everything correctly in tests, but in reality the time is sometimes different even by several hours. Why is it so?

UseCopyTime, I also noticed this problem when building graphical objects andCopyTime solved the problem

datetime TM[];
if(CopyTime(Symbol(),Period(),0,1,TM)<0) return;
TIME0=TM[0];
 
Vitaly Muzichenko:

UseCopyTime, I also noticed this problem when building graphical objects andCopyTime solved the problem

datetime TM[];
if(CopyTime(Symbol(),Period(),0,1,TM)<0) return;
TIME0=TM[0];
Thank you!
 
Evgeny Belyaev:
This is the first time I've heard of them.
I just need a floating take that is tied to an object.
 
How do I make the scale of my indicator show 5 decimal places?

Here, the chart has 5 digits and the indicator has 4.
 
igrok333:
How do I make the scale of my indicator show 5 decimal places?

Here, the chart has 5 digits and the indicator has 4.
IndicatorSetInteger(INDICATOR_DIGITS,Digits());
 
Artyom Trishkin:
IndicatorSetInteger(INDICATOR_DIGITS,Digits());
thanks, moderator)
Reason: