Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1243

 

I don't have the slightest desire to google or read, so I opened file D:\1.txt

/*
https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew
HINSTANCE ShellExecuteW(
  HWND    hwnd,
  LPCWSTR lpOperation,
  LPCWSTR lpFile,
  LPCWSTR lpParameters,
  LPCWSTR lpDirectory,
  INT     nShowCmd
);
*/
#import "shell32.dll"
int ShellExecuteW(int hWnd, string lpVerb, string lpFile, string lpParameters, string lpDirectory, int nCmdShow);
#import
#define  SW_SHOW 5
#define  SW_SHOWNORMAL 1
//+------------------------------------------------------------------+
void OnStart()
{
   ShellExecuteW(NULL,"Open","notepad.exe","D:\\1.txt",NULL,SW_SHOW); 
}
//+------------------------------------------------------------------+
 

What is the best way to do it in the indicator, to start timer 1s or in OnCalculate to compare time (seconds)

<1sec, exit

or there are other working options?

need to update HistorySelect for the month + work with objects

 
Fast235:

or in OnCalculate compare time (seconds)

<1sec, output

seconds is not enough. The problem is with datetime - it can't be less than a second.

compare at least milliseconds

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const LastOnCalculate = GetTickCount(); &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   static uint LastOnCalculate = GetTickCount();
   if(GetTickCount() - LastOnCalculate < 1000) return(rates_total);
   LastOnCalculate = GetTickCount();
   .........
   return(rates_total);
}
Fast235:

what is better to do in the indicator, to start a timer 1s or in OnCalculate to compare time (seconds)


it is not important where to do it, the only thing that OnCalculate is related to ticks - there will be no tick and therefore there will be no OnCalculate call

Fast235:

you need to update HistorySelect for a month + work with objects

HistorySelect is fast, but when you go to move or create objects, there may be lags, if objects over 1000 +

and you will be modifying these objects every second


(enter your code and the pitfalls will pop up ))))

 

a second is enough for me and less often until the tick comes

for me to display trades on the chart + result of the trade over bars, and some semi-static information such as the global trend

can price watch the change from

int OnCalculate (const int rates_total,      // размер массива price[] 
                 const int prev_calculated,  // обработано баров на предыдущем вызове 
                 const int begin,            // откуда начинаются значимые данные 
                 const double& price[]       // массив для расчета 
   );

or time from the second option

 

Please tell me!

How can I compare the current chart symbol with the one I need?

      case 1 : // кейс для открытия Buy по AUD/USD
               if(Symbol() == (как обозначить нужный символ для сравнения?))                                    // если символ текущего графика AUD/USD открываем сделку
               {
                  RefreshRates();
                  Open_Order = OrderSend("AUDUSD",OP_BUY,Lot(),Ask,0,0,0); // Открытие ордера
//----------------------------------------------------------------------------------------------------
В тоже время советник запущен на другом графике и пытается произвести открытие ордера, цены не совпадают и соответственно вылетает ошибка - неверные цены

      case 2 : // кейс для открытия Bay по GBP/USD 
               if(Symbol() == (как обозначить нужный символ для сравнения?)) 
// если символ текущего графика не AUDUSD то выходим
               {
                  RefreshRates();
                  Open_Order = OrderSend("GBPUSD",OP_SELL,Lot(),Bid,0,0,0); // Открытие ордера

Т.е. надо ему дать понять, что тот или иной кейс принадлежит тому или другому графику, но чтот я пока не придумал как

I need the program to open an order on AUD/USD, so it opens the order (it works properly). However, the program tries to open the order on other open charts(the robot is running on several currency pairs) and it returns a price error for the other currency pairs where the Expert Advisor is running. I have to make a comparison and if Symbol() == is equal to the symbol on which the order should be opened, then we open it and if not, we exit. I haven't found anywhere how to set the symbol name from the terminal and make the comparison.

 
Denis Diakonov:

Please tell me!

How can I compare the current chart symbol with the one I need?

I need the program to open an order on AUD/USD, so it opens the order (it works properly). However, the program tries to open the order on other open charts(the robot is running on several currency pairs) and it returns a price error for the other currency pairs where the Expert Advisor is running. I have to make a comparison and if Symbol() == is equal to the symbol on which the order should be opened, then we open it and if not, we exit. I haven't found anywhere how to set the symbol name from the terminal and make comparison.

There is an example of getting the right prices at the end.

SymbolInfoDouble - Получение рыночной информации - Справочник MQL4
SymbolInfoDouble - Получение рыночной информации - Справочник MQL4
  • docs.mql4.com
2. Возвращает true или false в зависимости от успешности выполнения функции.  В случае успеха значение свойства помещается в приемную переменную, передаваемую по ссылке последним параметром. Если функция используется для получения информации о последнем тике, то лучше использовать SymbolInfoTick(). Вполне возможно, что по данному символу с...
 
Denis Diakonov:

Thank you, but I don't need the right prices. The prices are fine. I need the EA not to open an order if the currency pair at which the order is opened is not the same as the current open chart to which the robot is attached. Maybe we may implement this by opening a new chart with a timeframe, open a desired order in it and then close the chart.

string  symbol;
....
int OnInit()
{...
 symbol=Symbol();
....
}
void OnTick()
...
 if(symbol == Symbol())
{
...//открываем ордер
}
....
 
Valeriy Yastremskiy:
Valeriy Yastremskiy:

No, it doesn't work that way.

My program accesses the current chart, assigns to it the name of the current instrument and seals it into a variable, then compares the value of this variable to the current symbol on the chart. It actually compares it to itself)))) I need to somehow convert Sympol() to any value with which any other variable can be compared. For example:

AUDUSD;

(Symbol() == AUDUSD)

I've somehow managed to do it - while I was rejoicing and changing everything correctly - nothing works anymore))

 
Denis Diakonov:

No, it doesn't work that way.

My program accesses the current chart, assigns it the name of the current instrument and seals it into a variable, then compares the value of this variable to the current symbol on the chart. It actually compares it to itself)))) I need to somehow convert Sympol() to any value with which any other variable can be compared. For example:

AUDUSD;

(Symbol() == AUDUSD)

I've managed it somehow, until I was happy and changed everything correctly - nothing works))

string AUDUSD = "AUDUSD";

At least like this.

 
Denis Diakonov:

No, it doesn't work that way.

My program accesses the current chart, assigns it the name of the current instrument and seals it into a variable, then compares the value of this variable to the current symbol on the chart. It actually compares it to itself)))) I need to somehow convert Sympol() to any value with which any other variable can be compared. For example:

AUDUSD;

(Symbol() == AUDUSD)

I did it somehow, and while I was rejoicing and changing everything, nothing worked anymore))

The Expert Advisor, the script, the indicator do not apply, but work in the current window. And global variables of different windows / charts do not overlap. Therefore, it should work)

string AUDUSD; // This is a text variable, which is initially empty, i.e. equals ""

(Symbol() == AUDUSD) // this string has nothing to do with variable AUDUSD.

Symbol
Возвращает имя символа текущего графика.
string  Symbol();
Возвращаемое значение
Значение системной переменной _Symbol, в которой хранится имя символа текущего графика.

But the order opening criteria should not be the same for different instruments/windows. If they are the same, they will indeed open in all windows.