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

 
Pokrov:

I have GetLastError after functions and if an error occurs, won't it go to this block (as written) and commands won't be executed? I understand the chain, e.g. OrderSend() -> GetLastError -> error block Sleep(3000) RefreshRates() -> exit the block and if conditions remain OrderSend() is requested again. Or my reasoning and concepts are wrong. I understand you want to write the return value 1 or 0 in the block, but my functions are simple not related to boolean values like SignalBuy, if I understand correctly, the return values should be returned there.

I will also add that in your example there is no reaction after getting an error. We checked it and it didn't, except that we decided to sleep a bit or refreshed the data. Just exit on completion of OnTick() function
 
Good afternoon!

I need some advice. According to the conditions, the position should be closed and after 121 seconds a new position should open. How can I do it with Sleep(121000)?

if(GetProfitOpenHigestInPoint(NULL,OP_BUY,magic) > PiespieduClose*10)
{
ClosePosWithMaxProfitInCurrency(NULL,OP_BUY,magic);
Sleep(121000);
OpenPosition(NULL, OP_BUY, LotSize(),0,0,magic); 
}
 
abeiks:
Good day!

I need some advice. According to the conditions, the position should be closed and after 121 seconds a new position should be opened. How can I do it with Sleep(121000)?

Help: OnTimer()
 
artmedia70:
OnTimer() to the rescue
Thank you! I never used OnTimer() and this part of code is in void OnTick(). Can I handle OpenPosition() function with OnTimer()? If you can, please correct code how to insert OnTimer() there correctly...
void OnTick()
{
...

if(GetProfitOpenHigestInPoint(NULL,OP_BUY,magic) > PiespieduClose*10)
{
ClosePosWithMaxProfitInCurrency(NULL,OP_BUY,magic);
EventSetTimer(121); 
OpenPosition(NULL, OP_BUY, LotSize(),0,0,magic); 
}

...   
}
 

I just reinstalled Windows 7 and wanted to install Mt4, the problem is the files do not download, what should I do?

 
Alexei and Artem, thank you for your expert comments and advice!
 
abeiks:
Thanks! I never used OnTimer(). This part of code is in void OnTick(). Will the OpenPosition() function be handled by OnTimer() then? If you can, please correct code how to insert OnTimer() there correctly...

The timer is started in OnInit()

EventSetTimer(1); // раз в секунду

To start the countdown, you need to find the closing time of the last position in the timer and count 121 sukunds from this time. To pass the flag allowing you to open a new position, use a global variable whose scope covers the entire program. You can make it initially contain a value higher than 121, for example 122 (you can change the wait time in settings).

In OnTick(), check this variable. If it is greater than 121 and there is no position, you open a position and, after checking if it was successfully opened, reset the variable to zero.

As soon as the position is closed, the timer sees the time of closing (it does this continuously once a second) and if from the current time to the closing time of the position passed less than 121-th second, the timer starts counting - every second the variable value is added by 1.

Approximately so. Where there may be a bug - if the position has not yet been closed, its closing time is zero. This can cause a problem with starting the countdown. You could reset the variable to -1, for example.

Yes, don't forget to destroy the timer in OnDeinit():

//+------------------------------------------------------------------+
   void OnDeinit(const int reason) {EventKillTimer();}
//+------------------------------------------------------------------+
 
artmedia70:

The timer is started in OnInit()

In order to start the countdown, you need to find the time in the timer when the last position was closed and count 121 seconds from that time. To pass the flag allowing you to open a new position, use a global variable that is scalable by the whole program. You can make it initially contain a value higher than 121, e.g. 122 (you can change the wait time in the settings).

In OnTick() You check this variable. If it is greater than 121 and there is no position - open a position - and, after checking if it was successfully opened, reset the variable to zero.

As soon as the position is closed, the timer sees the time of closing (it does this continuously once a second) and if from the current time to the closing time of the position passed less than 121-th second, the timer starts counting - every second the variable value is added by 1.

Approximately so. Where there may be a bug - if the position has not yet been closed, its closing time is equal to zero. This can cause a problem with starting the countdown. You could reset the variable to -1, for example.

Yes, don't forget to destroy the timer in OnDeinit():

Got it, thanks. I was hoping to do it in one line, but probably I'll have to work a bit longer.

 
abeiks:

I see, thank you. I was hoping to do it in one line, but I guess it's going to take more work.

 

как проще всего загрузить всю доступную историю графика? 

evillive:

Script.

it's not working.

Reason: