[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 313

 
Can someone explain how to open an order at any time of a bar and only open the next order on the next bar?
 
silhouette:

Don't mind the brakes, this is the first time I've dealt with multidimensional arrays :)

It's easier to orient yourself if you think of a multidimensional array as something else. Namely, if you find a model for the array that captures its essence - the model is easier to keep in front of your eyes.

A one-dimensional array is objects on a line (a coordinate ray starting from zero). An example of such an array would be a queue in a shop. The first in the queue is the person standing right behind the person who is buying now. The person buying can't be called the first in the queue - he is buying - he is zero. He is inside the zero cell of the one-dimensional array.

A two-dimensional array is objects in a plane (coordinate plane). An example would be an auditorium. Such-and-such row, such-and-such place. Add row zero and seat zero to this model, and you have an exact model of a two-dimensional array.

A three-dimensional array is an object in space (coordinate space) - the coordinate of the object is given by three values. It is a cube, with faces. A model could be a residential building with entrance number zero, floor number zero and flat number zero (among all others). Provided that in each entryway the flat numbering starts from zero.

A four-dimensional array is similar to a one-dimensional array. It is a coordinate ray, all points of which are three-dimensional arrays. The model is a street. The coordinate array will be specified by the values: house number, entrance number, floor number, flat number.

And so on into enn-dimensionality - from streets to districts, from districts to cities, from districts to cities, from cities to countries, from countries to planets...

 
GarKain:
Can someone explain how to open an order at any time of a bar and open the next order only at the next bar?

We should loop through the list of orders. If the opening time of the next order is set higher or equal to the time of the current bar opening (Time[0]), we should set the flag prohibiting opening of orders on the current currency pair. At the next candlestick, the loop will detect that there is no such order and it will not place a ban, i.e., it will clear the flag prohibiting the opening of orders.
 
drknn:

We loop through the list of orders. If the opening time of the next order is greater than or equal to the opening time of the current bar (Time[0]), then we set the flag prohibiting the opening of orders on this currency pair.
Thanks a lot
 
drknn, thank you very much for the clarification. I'll keep it ;)
 
GarKain:
Thank you very much.


If the code only works on one currency pair, then put a line to cut off orders of other pairs

if(OrderSymbol()!=Symbol()){continue;}
 
drknn:


If the code only works on one currency pair, then set a line to discard orders of other pairs

question. if the code works on several currency pairs and simultaneously on several timeframes, can you put different magic numbers on them and perform sifting on it?
 

You can.

if(OrderMagicNumber()!=MAGIC) { continue;}
 
drknn:

You can.



bool Times=true;
if (OrdersTotal()>0){
for(int g=OrdersTotal()-1; g>=0; g--){
datetime t;
OrderSelect(g,SELECT_BY_POS);
if (OrderMagicNumber()!=MagicNumber){continue;}
if (t<OrderOpenTime() || g==OrdersTotal()-1) t=OrderOpenTime();

if (t>=Time[0]) Times=false;}}


is this correct?

 
GarKain:

bool Times=true;
if (OrdersTotal()>0){
for(int g=OrdersTotal()-1; g>=0; g--){
datetime t;
OrderSelect(g,SELECT_BY_POS);
if (OrderMagicNumber()!=MagicNumber){continue;}
if (t<OrderOpenTime() || g==OrdersTotal()-1) t=OrderOpenTime();

if (t>=Time[0]) Times=false;}}


is this correct?


No. There is no need to declare a variable inside the loop at each loop iteration.

bool Torg=true;
for(int i=OrdersTotal()-1;i>=0;i--){
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {Print("Ошибка № ",GetLastError()," при выборе ордера № ",i);}
    else {
     if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGIC) { continue;} 
     if(OrderOpenTime()>=Time[0]){
       Torg=false;
     }
   }  
 }


// теперь используем результат работы цикла
// Если есть сигнал и торг разрешён, то открываем ордер