paladin80: Where is the best place to declare a variable type (int, double, etc.) in terms of reducing the resource consumption of program execution. For example, int i can be declared globally or in int start() ... for (int i=OrdersTotal()-1; i>=0; i--) ... I have a feeling that declaring on every tick is more costly than declaring once on global level, right after extern parameters. Or is the difference in resource-intensiveness the same?
All variables (memory locations) are created once at program start and must then be initialized where they occur in the text(variable declaration), but this does not always happen, so if you want it to work properly, do not forget to initialize it explicitly when declaring.
Corrected the code to match yours. When testing, four orders closed in order of setting on the first tick, the fifth closed on the next tick. Probably something else is wrong here as I have tested repeatedly. I am providing you the code of the program and logs of the tester. Sincerely. Shurkin
It's clear. Replace
for(i=0, int k=0; i<OrdersTotal();i++,k++)//
to .
int total=OrdersTotal();
for(i=0, int k=0; i<total;i++,k++)//
Hello, Could you tell me how to calculate the sum of indicator values in each separate histogram block? I wrote an indicator, but it starts working only when it is set. On previous bars - nothing! I do not manage to cycle "while"! Help, professionals.
//+-------------------------------------------------------------------------------------+//| Блок поиска своих объектов |//+-------------------------------------------------------------------------------------+bool IsObjectFound()
{
for (int obj=0; obj<=ObjectsTotal()-1; obj++)
{
objName = ObjectName(obj);
isObj = ObjectFind(objName);
objPrice1 = ObjectGet(objName, OBJPROP_PRICE1);
objPrice2 = ObjectGet(objName, OBJPROP_PRICE2);
objPriceCurr = ObjectGetValueByShift(objName,0);
}
Print("objPriceCurr = ", objPriceCurr);
if (isObj != -1) // Если объект найден, значит выходим из функцииreturn (true);
return (false); // Объект не найден!
}
//+-------------------------------------------------------------------------------------+//| Функция start |//+-------------------------------------------------------------------------------------+int start()
{
int signal = GetSignal();
if (IsObjectFound() == false)
{
Print("В окне отсуствуют объекты, поиск продолжается...");
return (0);
}
I have shown a piece of code where there is a misunderstanding. All variables are declared global. In theIsObjectFound() function I get the values of the first and second price point of the object, the name, and the price value of the object on the current bar. If the object is found it should exit the function in true mode , otherwise infalse .
In the start, I prescribed a condition that if the object is not found, then I exit the function:
I run it in the tester, I didn't draw any objects, there is nothing - a bare graph. Nevertheless, the function does not quit and is not printed accordingly :
Global variables are global searches. What can you say about the algorithm without seeing the data model?
I would trace exactly the data. And isObj really boolean, and all that ...
//+-------------------------------------------------------------------------------------+//| TradingByLine.mq4 |//| hoz |//| |//+-------------------------------------------------------------------------------------+#property copyright "hoz"#property link ""externstring ___H0 = "Параметры отклонений зоны сигнала";
externdouble dernovich = 40,
faustUs = 40;
/*extern double limitOverLine = 3,
limitUnderLine = 20;*/string objName; // Имя объектаint isObj; // Возвращает окно, которому принадлежит// ..наденнный объект, либо -1double objPrice1, // Первая координата цены луча
objPrice2, // Вторая координата цены луча
objPriceCurr; // Цена объекта на заданном бареint pt;
#define SIGNAL_BUY 0// Сигнал на покупку#define SIGNAL_SELL 1// Сигнал на продажу#define SIGNAL_NO -1// Сигнала нет//+-------------------------------------------------------------------------------------+//| Функция иницилизации |//+-------------------------------------------------------------------------------------+int init()
{
if(Digits == 2 || Digits == 4)
pt = Point;
if(Digits == 1 || Digits == 3 || Digits == 5)
pt = Point*10;
if(Digits == 6)
pt = Point*100;
if(Digits == 7)
pt = Point*1000;
return (0);
}
//+-------------------------------------------------------------------------------------+//| Функция деиницилизации |//+-------------------------------------------------------------------------------------+int deinit()
{
//----//----return (0);
}
//+-------------------------------------------------------------------------------------+//| Сигнализатор касания о луч |//+-------------------------------------------------------------------------------------+bool AlertByTouching(int signal)
{
double priceDevBefore,
priceDevAfter;
if (signal == SIGNAL_SELL)
{
priceDevAfter = objPriceCurr + faustUs * pt;
priceDevBefore = objPriceCurr - dernovich * pt;
if (Bid <= priceDevAfter && Bid >= priceDevBefore)
{
Print("Внимание. На инструменте ", Symbol(), " ожидается 3-е касание луча. Готовься продавать!");
Alert("Внимание. На инструменте ", Symbol(), " ожидается 3-е касание луча. Готовься продавать!");
return (true);
}
}
if (signal == SIGNAL_BUY)
{
priceDevAfter = objPriceCurr - faustUs * pt;
priceDevBefore = objPriceCurr + dernovich * pt;
Print("priceDevAfter = ", objPriceCurr - faustUs * pt);
Print("priceDevBefore = ", objPriceCurr - faustUs * pt);
Print("Ask >= priceDevAfter && Ask >= priceDevBefore ", Ask ," >= ", priceDevAfter ," && ", Ask ," >= ", priceDevBefore);
if (Ask >= priceDevAfter && Ask >= priceDevBefore)
{
Print("Внимание. На инструменте ", Symbol(), " ожидается 3-е касание луча. Готовься покупать!");
Alert("Внимание. На инструменте ", Symbol(), " ожидается 3-е касание луча. Готовься покупать!");
return (true);
}
}
return (false);
}
//+-------------------------------------------------------------------------------------+//| Блок поиска своих объектов |//+-------------------------------------------------------------------------------------+bool GetSignal()
{
if (!IsObjectFound())
return (SIGNAL_NO);
if (objPrice1 > objPrice2)
return (SIGNAL_BUY);
if (objPrice1 < objPrice2)
return (SIGNAL_SELL);
}
//+-------------------------------------------------------------------------------------+//| Блок поиска своих объектов |//+-------------------------------------------------------------------------------------+bool IsObjectFound()
{
for (int obj=0; obj<=ObjectsTotal()-1; obj++)
{
objName = ObjectName(obj);
isObj = ObjectFind(objName);
objPrice1 = ObjectGet(objName, OBJPROP_PRICE1);
objPrice2 = ObjectGet(objName, OBJPROP_PRICE2);
objPriceCurr = ObjectGetValueByShift(objName,0);
}
Print("objPriceCurr = ", objPriceCurr);
if (isObj != -1) // Если объект найден, значит выходим из функцииreturn (true);
return (false); // Объект не найден
}
//+-------------------------------------------------------------------------------------+//| Функция start |//+-------------------------------------------------------------------------------------+int start()
{
int signal = GetSignal();
if (IsObjectFound() == false)
{
Print("В окне отсуствуют объекты, поиск продолжается...");
return (0);
}
if (signal != SIGNAL_NO)
if (!AlertByTouching(signal))
return (0);
Print("objPrice1 = ", objPrice1, ", objPrice2 = ", objPrice2);
// Print("objPriceCurr = ", objPriceCurr);return (0);
}
isObj is an int. Returns the window that has the object in it, if there is one. If it does not exist, I understand it will return -1. According to the doc, the main window starts at 0 and then the sub-windows... So far, this is an outline for a trading Expert Advisor, purely signal. But it gives out messages whenever it wants.
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.
Where is the best place to declare a variable type (int, double, etc.) in terms of reducing the resource consumption of program execution. For example, int i can be declared globally or in int start() ... for (int i=OrdersTotal()-1; i>=0; i--) ... I have a feeling that declaring on every tick is more costly than declaring once on global level, right after extern parameters. Or is the difference in resource-intensiveness the same?
All variables (memory locations) are created once at program start and must then be initialized where they occur in the text(variable declaration), but this does not always happen, so if you want it to work properly, do not forget to initialize it explicitly when declaring.
Corrected the code to match yours.
When testing, four orders closed in order of setting on the first tick, the fifth closed on the next tick. Probably something else is wrong here as I have tested repeatedly.
I am providing you the code of the program and logs of the tester.
Sincerely. Shurkin
It's clear. Replace
to .
There is the following situation:
I have shown a piece of code where there is a misunderstanding. All variables are declared global. In theIsObjectFound() function I get the values of the first and second price point of the object, the name, and the price value of the object on the current bar. If the object is found it should exit the function in true mode , otherwise infalse .
In the start, I prescribed a condition that if the object is not found, then I exit the function:
I run it in the tester, I didn't draw any objects, there is nothing - a bare graph. Nevertheless, the function does not quit and is not printed accordingly :
The start function goes on and on. What is this all about?
Global variables are global searches. What can you say about the algorithm without seeing the data model?
I would trace exactly the data. And isObj really boolean, and all that ...
Global variables are global searches. What can you say about the algorithm without seeing the data model?
I would trace exactly the data. And isObj really boolean, and all that ...
isObj is an int. Returns the window that has the object in it, if there is one. If it does not exist, I understand it will return -1. According to the doc, the main window starts at 0 and then the sub-windows... So far, this is an outline for a trading Expert Advisor, purely signal. But it gives out messages whenever it wants.