It looks like the terminal keeps pumping up the history - so the indicator keeps recalculating. Or another variant: you have a VERY large number of bars set in the terminal for display on the chart, and your computer has a VERY large number of bars on the chart.
Thanks for the help!
When you select a different date, the calculation takes place immediately. In the first test there was a gap in price, possibly missing some prices - this is most likely the problem.
Hello! There is an MT5 indicator "Grid Builder" which drawshorizontal lines in price increments. You can select e.g. 100p, 200p etc. And it builds a horizontal grid up and down with a given step. But it has one problem, for example, when I draw horizontal levels on timeframe H4 (I put horizontal lines from drawing tools in the terminal) and switch to any other timeframe, all my lines are removed. Only horizontal indicator levels remain. How can I correct this error in the code? To ensure that my horizontal levels are never deleted. Here is the indicator code (I wrote this question in another thread, but there is no answer yet)
//+------------------------------------------------------------------+//| GridBuilder.mq5 |//| Copyright 2015, AM2 |//| https://www.forexsystems.biz |//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "https://www.forexsystems.biz"
#property version "1.00"
#property indicator_chart_window
//---- для расчёта и отрисовки индикатора использовано ноль буферов
#property indicator_buffers 0//---- использовано всего ноль графических построений
#property indicator_plots 0//--- входные параметры
input int count = 50; //количество линий вверх вниз от цены
input int step = 333; //шаг линий
input double pr = 1.4622; //цена от которой пляшем//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int OnInit()
{
//--- indicator buffers mapping
ObjectsDeleteAll(0,0,OBJ_HLINE);
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+void OnDeinit(constint reason)
{
Comment("");
ObjectsDeleteAll(0,0,OBJ_HLINE);
}
//+------------------------------------------------------------------+ //| Создает горизонтальную линию | //+------------------------------------------------------------------+ bool HLine(conststring name="HLine",double price=0)
{
//--- создадим горизонтальную линию if(!ObjectCreate(0,name,OBJ_HLINE,0,0,price))
{
Print(__FUNCTION__,
": не удалось создать горизонтальную линию! Код ошибки = ",GetLastError());
return(false);
}
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,clrGreen);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
return(true);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+int OnCalculate(constint rates_total,
constint prev_calculated,
const datetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
double price=pr;
//--- создадим горизонтальную линию for(int i=0;i<=count;i++)
{
HLine("HLine"+(string)i,price+step*i*_Point);
HLine("HLine"+(string)(i+count+1),price-step*i*_Point);
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+
При создании графического объекта функцией ObjectCreate() необходимо указать тип создаваемого объекта, который может принимать одно из значений перечисления ENUM_OBJECT. Дальнейшие уточнения свойств созданного объекта возможно с помощью функций по работе с графическими объектами.
Hello! There is an MT5 indicator "Grid Builder" which drawshorizontal lines in price increments. You can select e.g. 100p, 200p etc. And it builds a horizontal grid up and down with a given step. But it has one problem, for example, when I draw horizontal levels on timeframe H4 (I put horizontal lines from drawing tools in the terminal) and switch to any other timeframe, all my lines are removed. Only horizontal indicator levels remain. How can I correct this error in the code? To ensure that my horizontal levels are never deleted. Here is the code of indicator (I wrote this question in another topic, but there is no answer)
[in] Префикс, по которому будут удалены все объекты, чьи имена начинаются с данного набора символов. Префикс можно указывать как 'name' или 'name*' – оба варианта работают одинаково. Если в качестве префикса указана пустая строка, то будут удалены объекты с любым именем. Функция использует синхронный вызов – это...
Available. Just keep an eye on the location of the base. They are created just like the files.
#define DB_NAME "OHLC_DB"int db_handle;
string TableName;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit(){
db_handle = DatabaseOpen(DB_NAME, DATABASE_OPEN_READWRITE|DATABASE_OPEN_CREATE);
if (db_handle != INVALID_HANDLE){
Print(StringFormat("Database %s was opened", DB_NAME));
TableName = Symbol() + "_" + enumTimeFrameToString(Period());
if (DatabaseTableExists(db_handle, TableName)){
Print(StringFormat("Table %s is exist", TableName));
}else{
if (DatabaseExecute(db_handle, "CREATE TABLE " + TableName + "(""TIME TEXT PRIMARY KEY NOT NULL,""OPEN REAL NOT NULL,""HIGH REAL NOT NULL,""LOW REAL NOT NULL,""CLOSE REAL NOT NULL );")){
Print(StringFormat("Table %s was created", TableName));
string time = "'" + TimeToString(iTime(Symbol(), PERIOD_CURRENT, 0)) + "'";
double open = iOpen(Symbol(), PERIOD_CURRENT, 0);
double high = iHigh(Symbol(), PERIOD_CURRENT, 0);
double low = iLow(Symbol(), PERIOD_CURRENT, 0);
double close = iClose(Symbol(), PERIOD_CURRENT, 0);
if (!DatabaseExecute(db_handle,"INSERT INTO " + TableName + " (TIME,OPEN,HIGH,LOW,CLOSE) ""VALUES (" + StringFormat("%s,%.5f,%.5f,%.5f,%.5f", time, open, high, low, close) + ");")){
Print("Table: ", TableName, " insert failed with code ", GetLastError());
DatabaseClose(db_handle);
return(INIT_FAILED);
}elsePrint("New table started:");
}else{
Print(StringFormat("Could not create %s table. Error is: %d", TableName, GetLastError()));
DatabaseClose(db_handle);
return(INIT_FAILED);
}
}
return(INIT_SUCCEEDED);
}else{
Print("Could not open db. Error is: ", GetLastError());
return(INIT_FAILED);
}
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason){
DatabaseClose(db_handle);
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick(){
string time = "'" + TimeToString(iTime(Symbol(), PERIOD_CURRENT, 0)) + "'";
double open = iOpen(Symbol(), PERIOD_CURRENT, 0);
double high = iHigh(Symbol(), PERIOD_CURRENT, 0);
double low = iLow(Symbol(), PERIOD_CURRENT, 0);
double close = iClose(Symbol(), PERIOD_CURRENT, 0);
if (!DatabaseExecute(db_handle,"INSERT INTO " + TableName + " (TIME,OPEN,HIGH,LOW,CLOSE) ""VALUES (" + StringFormat("%s,%.5f,%.5f,%.5f,%.5f", time, open, high, low, close) + ");")){
Print("Table: ", TableName, " insert failed with code ", GetLastError());
DatabaseClose(db_handle);
}
}
//+------------------------------------------------------------------+string enumTimeFrameToString(ENUM_TIMEFRAMES frame){
switch(frame){
casePERIOD_M1: return"M1";
casePERIOD_M2: return"M2";
casePERIOD_M3: return"M3";
casePERIOD_M4: return"M4";
casePERIOD_M5: return"M5";
casePERIOD_M6: return"M6";
casePERIOD_M10: return"M10";
casePERIOD_M12: return"M12";
casePERIOD_M15: return"M15";
casePERIOD_M20: return"M20";
casePERIOD_M30: return"M30";
casePERIOD_H1: return"H1";
casePERIOD_H2: return"H2";
casePERIOD_H3: return"H3";
casePERIOD_H4: return"H4";
casePERIOD_H6: return"H6";
casePERIOD_H8: return"H8";
casePERIOD_D1: return"D1";
casePERIOD_W1: return"W1";
default: return"MN1";
}
}
Here is my code. In the initialization it creates one record in the table. In the OnTick body it should immediately return an error, because I try to add a record with the same PRIMARY KEY, and after that the base closes immediately. But at the same time I should see at least that first record when I open it, but when I run it in the tester it's not there. And even the table is not created. If I just open it in the terminal, everything is normal. The first record is there.
Here is my code. In the initialization it creates one record in the table. In the OnTick body it should immediately return an error, because I try to add a record with the same PRIMARY KEY, and after that the base closes immediately. But at the same time I should see at least that first record when I open it, but when I run it in the tester it's not there. And even the table is not created. If I just open it in the terminal, everything is normal. The first record is there.
Once again I am convinced that the tester and the terminal itself are different hypostases...
HistorySelect(xxx,TimeCurrent()) miss the latest history order / deal sometimes. Now you have to use HistorySelect(xxx,TimeCurrent()+1) To get a more accurate result.
It has long been recommended to add one day toTimeCurrent(). It's just that now, in response to your not quite correct code, the terminal is giving you advice.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
It looks like the terminal keeps pumping up the history - so the indicator keeps recalculating. Or another variant: you have a VERY large number of bars set in the terminal for display on the chart, and your computer has a VERY large number of bars on the chart.
Thanks for the help!
When you select a different date, the calculation takes place immediately. In the first test there was a gap in price, possibly missing some prices - this is most likely the problem.
Hello! There is an MT5 indicator "Grid Builder" which drawshorizontal lines in price increments. You can select e.g. 100p, 200p etc. And it builds a horizontal grid up and down with a given step. But it has one problem, for example, when I draw horizontal levels on timeframe H4 (I put horizontal lines from drawing tools in the terminal) and switch to any other timeframe, all my lines are removed. Only horizontal indicator levels remain. How can I correct this error in the code? To ensure that my horizontal levels are never deleted. Here is the indicator code (I wrote this question in another thread, but there is no answer yet)
Hello! There is an MT5 indicator "Grid Builder" which drawshorizontal lines in price increments. You can select e.g. 100p, 200p etc. And it builds a horizontal grid up and down with a given step. But it has one problem, for example, when I draw horizontal levels on timeframe H4 (I put horizontal lines from drawing tools in the terminal) and switch to any other timeframe, all my lines are removed. Only horizontal indicator levels remain. How can I correct this error in the code? To ensure that my horizontal levels are never deleted. Here is the code of indicator (I wrote this question in another topic, but there is no answer)
Do pay attention to this code:
In particular, read about ObjectsDeleteAll() - there the cause and answer for correction.
Pay attention to this code:
In particular read about ObjectsDeleteAll() - there's the reason and the answer on how to tweak it.
Thank you!!! Sorted it out, now it works without deletion.
Are SQLite database operations available from the tester? I mean adding and changing data.
Available. Just keep an eye on the location of the base. They are created in the same way as the files.
Available. Just keep an eye on the location of the base. They are created just like the files.
Here is my code. In the initialization it creates one record in the table. In the OnTick body it should immediately return an error, because I try to add a record with the same PRIMARY KEY, and after that the base closes immediately. But at the same time I should see at least that first record when I open it, but when I run it in the tester it's not there. And even the table is not created. If I just open it in the terminal, everything is normal. The first record is there.
Here is my code. In the initialization it creates one record in the table. In the OnTick body it should immediately return an error, because I try to add a record with the same PRIMARY KEY, and after that the base closes immediately. But at the same time I should see at least that first record when I open it, but when I run it in the tester it's not there. And even the table is not created. If I just open it in the terminal, everything is normal. The first record is there.
Once again I am convinced that the tester and the terminal itself are different hypostases...
It has long been recommended to add one day toTimeCurrent(). It's just that now, in response to your not quite correct code, the terminal is giving you advice.