[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 12

 
there it is
Files:
 
igrok2008 >> :

In the previous comment you pointed out my flaw, about incorrect buy and sell levels, which (as I understand it) requires reversing the < > signs.

For CCI it is necessary or not to specify -100????????????????????????

Take it and put it in the tester

and it will show where the result is better

where there is a minus or where it is not

and which number will end up being 250 or -250

 

Please write or suggest how to make an order open when a new bar appears and close when it closes? My head hurts, I can't figure it out ))))

 
vadim2304 >> :

Please write or suggest how to make an order open when a new bar appears and close when it closes? My head already hurts, I can't think it out ))))

if ( isTime(Period()*60)) { закрытьОткрытыйОрдер(); открытьНовыйОрдер()};


bool isTime(int sec){
   bool res = false;
   static datetime time = 0;
   double min = 0;
   if (TimeCurrent() >= time){
      min = MathFloor( sec / 60);
      if ( min==0) min = 1.0;         
      time = iTime(NULL,PERIOD_H1,0) + (MathFloor(Minute()/ min) + 1) * min * 60;
      res = true;
   } 
   return( res);
}
 
keekkenen >> :

I understand this is for bar with H1 timeframe, but where to write code for opening and closing prices, after if (isTime(Period()*60)), and what does it mean, please decipher )))

 

misunderstanding... Period()*60 is for any TF - everything is expressed in seconds, i.e.

on M1 - 60 sec, M5 - 300 sec etc. (because Period() on M1 returns 1, on M5 - 5...)

I wrote it figuratively

if ( isTime(Period()*60)) { закрытьОткрытыйОрдер(); открытьНовыйОрдер()};

The meaning of this - when a new bar appears, you can close an open order and open a new one.

If you can't do it yourself, take a look at the tutorial https://book.mql4.com/ru/

 
keekkenen >> :

misunderstanding... Period()*60 is for any TF - everything is expressed in seconds, i.e.

on M1 - 60 sec, M5 - 300 sec, etc. (as Period() on М1 returns 1, on М5 - 5...)

I wrote it figuratively.

The idea is to close an open order and open a new one.

If you are not able to do it yourself, take a look at "https://book.mql4.com/ru/" for a tutorial.


And if there are no open orders (it will close them after this bar), and just open a new order, there will be no error ???

 
satop >> :

Take it and stick it in the tester

and it'll show you where the results are better.

where there's a minus or where there isn't.

and it'll show you whether it's 250 or -250.

Don't be angry satop. Everyone was a beginner, everyone asked stupid questions. Think back to school. There must have been geeks. They were curious, they wanted to learn. Over time, of course, they pestered them, but it shows that those who were angry grasped and understood everything faster. But both teaching methods HAVE a right to life. Caesar to Caesar......No offence.......I'm not denying that I'm a dummy, but I'm curious. No offense...

 
vadim2304 >> :

And if there are no open orders (it will close them after this bar) and we just open a new order, there will be no error ?

The thing is that the OrderClose() function that closes the order takes the order number as the first parameter, and the order number can only be obtained by calling OrderSelect() to the existing orders, so in general the closing looks like this...

bool res = false;
int slippage = 3;

for (int i = 0; i < OrdersTotal(); i++) {
   if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES) &&
         OrderSymbol()==Symbol()){

      while (IsTradeContextBusy() || !IsTradeAllowed())
         {Comment("Торговый поток занят ...");Sleep(2000);}               
      res = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(), slippage,CLR_NONE);
      if ( res){  
         res = true; Comment("Ордер закрыт !");              
      }else{
         Comment("Ошибка - ", msg);
      }
   }
}
  


If OrdersTotal() = 0, i.e. if there are no open orders, then the for loop will immediately finish...

 
igrok2008 >> :

Don't be angry satop. Everyone was a beginner, everyone asked stupid questions. Think back to school. For sure there were geeks. They were curious, they wanted to learn. Over time, of course, they pestered them, but this shows that those who were angry grasped and understood everything faster. But both teaching methods HAVE a right to life. Caesar to Caesar......No offence.......I'm not denying that I'm a dummy, but I'm curious. >> no offense.

What makes you think I'm angry?

It's just my way of explaining that

by taking any sign of inequality and running

>> in the tester, you can get a positive

the result with some level, and it doesn't matter which level

positive or negative. And when asked

whether to take the level with or without the minus,

unfortunately there's no clear distinction.

Reason: