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

 
Good afternoon to all. Can you tell me how to take the opening of the day with an hour offset? That is, do not take the first hour, but the second for the day???
 
nikelodeon:
Good morning, everyone. Can you tell me how to take the opening of the day with an hour offset? That is, not take the first hour, but the second for the day?

It goes something like this.

if(iTime(_Symbol, PERIOD_H1, 1) == iTime(_Symbol, PERIOD_D1, 0))


But it would not hurt to put a check for a new day, otherwise all ticks from 1:00 to 2:00 will correspond to the condition.

 
Good afternoon. Help me solve the problem. I have to add a few windows of one indicator to a chart. This indicator has ObjectCreate and there is a problem, because the windows of this indicator have different values, the window index in ObjectCreate should be its own, I do not want to create clones of the indicator with different names. For example, if you set the window index to 1, all icons from other windows will be drawn in the window with index 1 and not in your window.
 
I have this operator iOpen(NULL,PERIOD_D1,1) it shows the opening of the day, but how to make the opening of the second hour of the day....????
 
Good afternoon, dear friends! Please tell me where I made a mistake and, if there is no error, what corrections should be made to the code:When powering on the computer again after a power outage, all code lines are loaded sequentially and after the closing curly bracket of OnTick(), the user functions located behind it are read, and after reading the code of CloseAllBuy(), it is executed, even though it has not been called from the OnTick(). So, when loading an EA, all open positions are closed. How to avoid this?
 
rapid_minus:
Good afternoon, dear friends! Please advise me, where is the error in my reasoning, and, if there is no error, what corrections should be done to the code:When powering on the computer again after a power outage, all strings of code are loaded sequentially and after the closing curly bracket of OnTick() is read the user functions behind it, and, after reading the code of CloseAllBuy(), it is executed, although it has not been called from the OnTick(). So, when loading an EA, all open positions are closed. How to avoid this?

Try to use global variables. If you want the EA to start from the same state as when it was closed, all state flags should be stored in global variables. Their value does not change and will be stored for days like this....

 
Thanks for the quick reply. It's just that I didn't understand anything, due to my illiteracy at the mclo level. Which global variables should be used - at expert level or at terminal level? (I'm floating here too, alas).
 
nikelodeon:
I have an operator iOpen(NULL,PERIOD_D1,1) it shows the opening of the day, but how to make the opening of the second hour of this day....????

iOpen() is the price, but iTime() should be used as suggested above. And different western companies may open the day on Sunday evening, you have to keep an eye on that, too.

In general, study whatiBarShift is.

 
rapid_minus:
Good day, dear friends! Please advise me where there is an error in my reasoning and, if there is none, what corrections should be made to the code:When powering on the computer again after a power outage, all code lines are loaded sequentially and after the closing curly bracket of OnTick() the user functions located behind it are read, and after reading the code of CloseAllBuy() its execution occurs, even though it has not been called from the OnTick(). So, when loading an EA, all open positions are closed. How to avoid this?

And how did you check that CloseAllBuy() is not called from nowhere? Or maybe the closure is still prescribed somewhere else?

No one can tell without the code, except the author.

 
CloseAllBuy() is called in a single place: in the OnTick() function by the condition if(Bid>buycloseprice) CloseAllBuy(); this condition did not come at the new turning on and did not come during the turning off period either, but the CloseAllBuy() function was triggered anyway when the EA was turned on again.
Reason: