Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1214

 
Igorz2006:
Thanks, I will give it a try. Quote history for bitcoin and crypto needs to be imported for analysis

Five has a closed history format, I haven't heard of importing. it's easier to open a demo where all the required characters are available.

 

Good day!

Open two buy positions and three sell positions. Calculate the open positions.

There were no problems with the opening of positions, but there were difficulties with the counting.

Please help a novice student)

input int PositionSell = 
5;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
  int buy_count  = 0;
  int sell_count = 0;

//---объявление и инициализация запроса и резкльтата
   MqlTradeResult  result_sell  = {0};
   MqlTradeRequest request_sell = {0};

   request_sell.action = TRADE_ACTION_DEAL;
   request_sell.symbol = Symbol();
   request_sell.volume = 0.1;
   request_sell.type   = ORDER_TYPE_SELL;

   MqlTradeResult  result_bay  = {0};
   MqlTradeRequest request_bay = {0};

   request_bay.action = TRADE_ACTION_DEAL;
   request_bay.symbol = Symbol();
   request_bay.volume = 0.1;
   request_bay.type   = ORDER_TYPE_BUY;



   if(PositionsTotal() < PositionSell)
     {
      OrderSend(request_sell,result_sell);
      OrderSend(request_sell,result_sell);
      OrderSend(request_sell,result_sell);

      OrderSend(request_bay,result_bay);
      OrderSend(request_bay,result_bay);
     } else return;

   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      if(PositionSelect(_Symbol))
     {
      switch(PositionGetInteger(POSITION_TYPE)) //Здесь выдает  ошибку implicit conversion from 'number' to 'string'
           {
            case POSITION_TYPE_BUY:  buy_count++;  break; 
            case POSITION_TYPE_SELL: sell_count++; break;
           }

        }
     }
     Print("Ордеров на покупку: " + buy_count + ", Ордеров на продажу: " + sell_count);
  }
 
Mihail Marchukajtes:

Greetings Colleagues!

Please advise the following. The OnTester function calculates two parameters. Is there a possibility when optimizing on one parameter, the second parameter is simply output in the optimization table??? And how to do this if yes? Thank you!

Colleagues, is there no answer to my question?
 
Pineapple88:

Good day!

Open two buy positions and three sell positions. Count the open positions.

There were no problems with the opening of positions, but there were difficulties with the counting.

Please help a novice student)

     for(int i=0; i<PositionsTotal(); i++)
     {
          if( PositionGetTicket(i) == 0 )                        continue;
          if( PositionGetString(POSITION_SYMBOL) != _Symbol )    continue;
          switch( (int)PositionGetInteger(POSITION_TYPE) )
           {
               case POSITION_TYPE_BUY:  buy_count++;  break; 
               case POSITION_TYPE_SELL: sell_count++; break;
           }
     }
 
Konstantin Nikitin:

Thank you! I'll look into it...

 
Pineapple88:

Thank you! I'll look into it...

Read PositionGetTicket, PositionGetSymbol, PositionSelect. Especially the note.

 
Good afternoon! I need some help. I cannot understand why
For example:
double f=1.11215;
double g=1.17545;
double j=f-(f-g);
Print(j);
//Result: 1.17545

Why not 1.1661?
Where can I read about it?
 
Reznik Nikolai:
Good afternoon! I need some help. I can't understand why
For example:
double f=1.11215;
double g=1.17545;
double j=f-(f-g);
Print(j);
//Result: 1.17545

Why not 1.1661?
Where can I read about it?

You MUST read it in the third grade primary schools arithmetic textbook.

 
Finally found mt4, makes it much easier
 

Good day everyone!

Please help.

My Expert Advisor opens a position at the intersection of two wagons. I am trying to close a position with an opposite one, but [Invalid request] error is displayed. I think there is an error in filling request parameters?

void OnTick()
  {

   MqlTradeResult  result_bay  = {0};
   MqlTradeRequest request_bay = {0};

   request_bay.action = TRADE_ACTION_DEAL;
   request_bay.symbol = Symbol();
   request_bay.volume = 0.1;
   request_bay.type   = ORDER_TYPE_BUY;

   MqlTradeResult  result_sell  = {0};
   MqlTradeRequest request_sell = {0};

   request_sell.action = TRADE_ACTION_DEAL;
   request_sell.symbol = Symbol();
   request_sell.volume = 0.1;
   request_sell.type   = ORDER_TYPE_CLOSE_BY;

   double MovingAverage1[], MovingAverage2[]; //задаем два массиса для МА

   int MovingAverageIndic1 = iMA(_Symbol,0,20,0,MODE_EMA,PRICE_CLOSE);
   int MovingAverageIndic2 = iMA(_Symbol,0,200,0,MODE_EMA,PRICE_CLOSE);

   ArraySetAsSeries(MovingAverage1,true);
   ArraySetAsSeries(MovingAverage2,true);

   CopyBuffer(MovingAverageIndic1,0,0,3,MovingAverage1);
   CopyBuffer(MovingAverageIndic2,0,0,3,MovingAverage2);

   if(
      (MovingAverage1[0]>MovingAverage2[0]) &&
      (MovingAverage1[1]<MovingAverage2[1])
   )
     {

      if(PositionsTotal()==0)
         OrderSend(request_bay,result_bay);
     }

   if(
      (MovingAverage1[0]<MovingAverage2[0]) &&
      (MovingAverage1[1]>MovingAverage2[1])
   )

     {
      if(
         (MovingAverage1[0]<MovingAverage2[0]) &&
         (MovingAverage1[1]>MovingAverage2[1])
      )
        {
         if(PositionsTotal()==1)
         
         OrderSend(request_sell,result_sell); 
           }


     }




  }

Reason: