And let's make a "cartoon" out of it (multicurrency) - page 2

 

You can slightly modify my function to return the total number of orders for a given instrument and magician.

 
ALex2008 писал(а) >>

If you do not know what to do with it, and you do not know what to do with it... I do not really care if it will be a real multi... or just distinguish orders of others... The essence of one thing - to make it work on several pairs, not on one) And to test it on a demo is not a problem, just a month or two, but the result is interesting)

Formulate the logic of the multi-fold Expert Advisor, the more detailed the better, and perhaps you won't need help.

As a rule clear understanding of the task is 90% of its success.

 
sergeev >> :

And by the way, you've got mistakes in your code! A lot!

iLow(PERIOD_H4,0,0) - what is this?

Low of the current candle))

Indeed...! How does it work on the test then?

I don't understand how I got it like this. It should be iLow(NULL,PERIOD_H4,0)

 
xeon >> :

Formulate the logic of the multivalent expert, the more detailed the better, and you may not need any more help.

As a rule, a clear understanding of the task is 90% of its success.

There is nothing wrong with logic) I just have no experience. I understand that you need to track orders by any attribute, but as I've never written anything like this before I'm afraid there will just be one question... about functions and their implementation)

 
ALex2008 писал(а) >>

There's nothing wrong with logic) I'm just inexperienced... I understand the need to track orders by any attribute, but as I've never written anything like this before I'm afraid there will just be one question... about functions and their implementation)

Look at previous page for function

 
Vinin >> :

See the function on the previous page

Thanks) I'll try to put it in the code)

Started writing...

#define MAGIC 7779

instead of this -

   if(OrdersTotal()==0){
      mod=false;
      SetOrders();}

writing this -

   if( Order_Count_Calculate(Symbol(), MAGIC)==0){
      mod=false;
      SetOrders();}

... it fails - 'Order_Count_Calculate' - function returns no result

If I understand correctly, the function should find all orders of the current symbol Symbol() with a MAGIC
 
ALex2008 писал(а) >>

Thank you) I'll try to put it in the code)

Started writing...

This is exactly what you don't want extern string _Symbol = Symbol();

Although a variable can be defined, and it's better to assign a value in inite() or start()

 
I stumbled at the first function...( I get the point, but I don't know how to use it properly...
 
ALex2008 писал(а) >>

There's nothing wrong with logic) I'm just inexperienced... I understand the need to track orders by any attribute, but as I've never written anything like this I'm afraid there will just be one question... about functions and their implementation)

Eh.... I'm afraid you don't understand..............

the task - "i want it to fly", it's not logic - what flew where it flew etc. etc.

--------------------------------------------

A brief example of the task:

Simultaneous use of EURUSD, GBPUSD, USDCHF, USDJPY.

H1 period.

......................

currency pair selection condition

BUY condition

SELL setting condition

.......................

Here is a short example of implementation:

int MAGIC = 322223;
string Sym[]={"EURUSD", "GBPUSD", "USDCHF", "USDJPY"};    //Внесем в массив валютные пары с которыми будем работать
int start(){
   
   int s = SymbolSelect();                   //Функция выбора валютной пары
   if( SelectOrder( Sym[ s],OP_BUY, MAGIC)<0){   //Если нет установленного ордера по выбранному символу
      UpTrend( Sym[ s]);                       //Проверим условие установки ордера 
   }
   if( SelectOrder( Sym[ s],OP_SELL, MAGIC)<0){  //Если нет установленного ордера по выбранному символу
      DownTrend( Sym[ s]);                     //Проверим условие установки ордера 
   }

}


int SymbolSelect(){
  int s=-1;
  //Условие выбора валютной пары для работы  
   
  return( s)
}
    //+-------------------Выбор ордера---------------------------+
int SelectOrder(string Sym,int Tip,int MAGIC){
    int TotOrd=OrdersTotal();
    int OrdTick=-1;
    for(int OrdPos= TotOrd-1; OrdPos>=0; OrdPos--){
        if(OrderSelect( OrdPos, SELECT_BY_POS, MODE_TRADES)==true){
           if(OrderSymbol()== Sym){                                           //Есть ли ордера с нужным символом
              if(OrderType()== Tip){                                          //Если нужный тип ордера  
                 if( MAGIC==0){ MAGIC=OrderMagicNumber();}                     //Если магик = 0,неучитывать
                 if(OrderMagicNumber() == MAGIC){                            //Есть ли ордера с нужным Магик номером
                    OrdTick = OrderTicket(); break;                          //Запишем в переменную его тикет и прервем цикл 
    }}}}}
    return( OrdTick);                                                         //Возвращает тикет найденного ордера или -1
}
bool UpTrend(string Sym){
     //Условие установки BUY ордера
}
bool DownTrend(string Sym){
    //Условие установки SELL ордера
}

etc.

I mean it, if you think about the logic in detail, you won't have any problems with the implementation.

 
xeon >> :

...that's what I mean, if you think through the logic in detail, you won't have any problems with implementation.

I'll be thinking about it today... I feel I've found a headache)) Thank you.

Anyway, here's a draft with mistakes... >> correct me.)

extern double Profit = 3000;

int MAGIC = 322223;

string Sym[]={"EURUSD", "GBPUSD", "USDCHF", "USDJPY"};    //Внесем в массив валютные пары с которыми будем работать

double b0, b1, s0, s1, StopLoss, Enter;
bool dwnSym, upSym, mod;

int init(){ Profit*=Point;
}

int start()
{
   
      int s = SymbolSelect();                      //Функция выбора валютной пары
      if( SelectOrder( Sym[ s],OP_BUYSTOP, MAGIC)<0){  //Если нет установленного ордера по выбранному символу
         UpTrend( Sym[ s]);                          //Проверим условие установки ордера 
         }
      if( SelectOrder( Sym[ s],OP_SELLSTOP, MAGIC)<0){ //Если нет установленного ордера по выбранному символу
         DownTrend( Sym[ s]);                        //Проверим условие установки ордера 
         }
      
      
      if( SelectOrder( Sym[ s],OP_BUYSTOP, MAGIC)>0 && AccountProfit()&& (! mod)){  //Если установлен ордер по выбранному символу
         SetStopBuy( Sym[ s]);                                                  //и он открылся, ставим стоп
         }
      if( SelectOrder( Sym[ s],OP_SELLSTOP, MAGIC)>0 && AccountProfit()&& (! mod)){ //Если установлен ордер по выбранному символу
         SetStopSell( Sym[ s]);                                                 //и он открылся, ставим стоп
         }
}

   int SymbolSelect(){
   int s=-1;
   return( s);}
   
//+-------------------Выбор ордера---------------------------+
   int SelectOrder(string Sym,int Tip,int MAGIC){
      int TotOrd=OrdersTotal();
      int OrdTick=-1;
      for(int OrdPos= TotOrd-1; OrdPos>=0; OrdPos--){
         if(OrderSelect( OrdPos, SELECT_BY_POS, MODE_TRADES)==true){
            if(OrderSymbol()== Sym){                                           //Есть ли ордера с нужным символом
               if(OrderType()== Tip){                                          //Если нужный тип ордера  
                  if( MAGIC==0){ MAGIC=OrderMagicNumber();}                     //Если магик = 0,неучитывать
                  if(OrderMagicNumber() == MAGIC){                            //Есть ли ордера с нужным Магик номером
                     OrdTick = OrderTicket(); break;                          //Запишем в переменную его тикет и прервем цикл 
      }}}}}
    return( OrdTick);}                                                         //Возвращает тикет найденного ордера или -1


//Условие и установка BUY ордера
   bool UpTrend(string Sym){
       
       if((iOpen( Sym,PERIOD_H4,1) - iClose( Sym,PERIOD_H4,1) <= 0) &&
         (iOpen( Sym,PERIOD_H4,2) - iClose( Sym,PERIOD_H4,2) > 0)){
          upSym=false;
          dwnSym=true;
          CloseOpenOrdersAndCancelPending();
          double Enter=iHigh( Sym,PERIOD_H4,1)+(Ask-Bid)+10*Point;
          OrderSend( Sym, OP_BUYSTOP, 0.1, Enter, 0, 0, Ask+ Profit, 0, 0,0, Green);}
   }

//Условие и установка SELL ордера
   bool DownTrend(string Sym){
       
       if((iOpen( Sym,PERIOD_H4,1) - iClose( Sym,PERIOD_H4,1) >= 0) &&
         (iOpen( Sym,PERIOD_H4,2) - iClose( Sym,PERIOD_H4,2) < 0)){
          upSym=true;
          dwnSym=false;
          CloseOpenOrdersAndCancelPending();
          double Enter=iLow( Sym,PERIOD_H4,1)-10*Point;
          OrderSend( Sym, OP_SELLSTOP, 0.1, Enter, 0, 0, Bid- Profit, 0, 0,0, Green);}
         
   }
   
//-------Вычисление и утановка стопа для бай
void SetStopBuy(string Sym)
   {
      RefreshRates();
      double b0=iLow( Sym,PERIOD_H4,0)-10*Point;
      double b1=iLow( Sym,PERIOD_H4,1)-10*Point;
      
            if( b0< b1) StopLoss= b1;
            else StopLoss= b0;
            RefreshRates();
            mod=OrderModify( OrdTick,OrderOpenPrice(), StopLoss,OrderTakeProfit(),0,Red);
   } 
   
 //-------Вычисление и утановка стопа для сел
void SetStopSell(string Sym)
   {
      RefreshRates();
      double s0=iHigh( Sym,PERIOD_H4,0)+(Ask-Bid)+10*Point;
      double s1=iHigh( Sym,PERIOD_H4,1)+(Ask-Bid)+10*Point;
      
            if( s0< s1) StopLoss= s0;
            else StopLoss= s1;
            RefreshRates();
            mod=OrderModify( OrdTick,OrderOpenPrice(), StopLoss,OrderTakeProfit(),0,Red);
   }
   
void CloseOpenOrdersAndCancelPending()
   {
      for (int i=OrdersTotal()-1; i>=0; i--){
      if (!OrderSelect( i, SELECT_BY_POS))  continue;
      if (OrderSymbol()!= Sym)        continue;
      OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10);}
   }