[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 829

 
dimon74:
Might be useful!!! Try to base it on one price: say Bid. The opening price for OP_SELLSTOP will be Bid , and for OP_BUYSTOP - Bid+87*Point (or whatever you need).
I see the idea, thank you!
 
Vinin:

Now one magician, the parameters are set to

Look at the private message...
 

Please help. Maybe someone knows how to implement a function in the code, which compares the penultimate value from the history with the last (we're talking about closed positions) no matter what value (for example OrderCloseTime()), and if they are different (in this case the penultimate is less than the last) - make a BLA-BLA-BLA. If possible refine my code, or write your own if you've got it in the wrong direction.

double C_T_L_C_P() {

datetime t;

double r=0;

int i, k=OrdersHistoryTotal(), q=0;

if (q==0)

for (i=0; i<k; i++) {

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)==true) {

if (OrderType()==OP_BUY || OrderType()==OP_SELL) {

if (t<OrderCloseTime()) {r=OrderCloseTime();}

}}}

return (r);}

THANKS IN ADVANCE!!!

 

Help with checking.

After the first unit appears in the cycle, check whether this unit will hold for t+t1 time (check every delta seconds). If it holds, we buy it, and if at some point it does not hold, we exit the loop. In other words the signal is valid, if it was checked every delta interval and was always one.

Am I thinking correctly?

if(sign0==1) //проверка начинаертя только после появления 1 
     {
      t=TimeCurrent();                                     //фиксируем время
                                                           //в цикле от t до t+t1 через каждые дельта секунд
       while(t<t+t1)                                       //t1 отрезок времени в перед за которое будем проверять if(sign0==1)
         {
            if(sign0==1)                                   //еще паз проверка наличия  1
              sign1=1;                                    //новой переменой присваиваем 1
            else
              {sign1=0;break;}                             // если нет присваиваем 0 и заканчиваем цикл
            t=t+delta;                                     //проверяем через каждые дельта секунд
         }
      if(sign1==1) op="BUY";
            return;
     }
 
gince:

Help with checking.

After the first unit appears in the cycle, check whether this unit will hold for t+t1 time (check every delta seconds). If it holds, then we buy, and if at some point it does not hold, then we exit the loop.

Am I thinking correctly ?


The result is an infinite while loop (t is always <t+t1, only if t1=0). In the loop sign1 always =1
 
abolk:

The result is an infinite while loop (t is always <t+t1, only if t1=0). In the loop sign1 always =1

How to fix the error ?
 
gince:

How to correct an error ?

To fix an error, you have to detail the algorithm (not the code, but the algorithm). And then overlay the code on the algorithm
 
abolk:

To correct the error, the algorithm must be detailed

A binary signal 0 or 1 is received. If a 1 is received, then from this moment we start checking if it will hold for 10 min (600 sec) checking every 60 sec. If all 10 minutes there was one - Buy, and if at least once there was no one then finish checking and consider that there is no signal for opening.
 
gince:

A binary signal 0 or 1 is received. If a 1 is received, then from this moment we start checking if it will hold for 10 minutes (600 seconds) checking every 60 seconds. If all 10 min were one - Buy, and if at least once was not a one then finish checking and consider that there is no signal for opening.

It is not clear in the code how the discrete signal sign0 changes. In the presented code the signal does not change. There is an unsuccessful attempt to work with changed t
 
void CheckForOpen()
  {
   
   int    res;
   datetime t;
   int sign=0;
//---- go trading only for first tiks of new bar


  
  double tr0=iCustom(NULL,0,"trd",0,0);
  double tr1=iCustom(NULL,0,"trd",1,0); 
//---- sell conditions
   if(tr1==1)  
     {
      t=TimeCurrent();
       while(t<t+tim)
         {
            if(tr1==1)
              sign=-1;
            else
              {sign=0;break;}
            t=t+delta;
         }
      if(sign==-1) 
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
      return;
     }
This is taken from Moving Average.mq4
Reason: