Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1855

 
Artyom Trishkin #:
Yes - output it yourself

the key word here is "like". There's your own data there, not from a third-party indicator.

 
Andrey Sokolov #:

Greetings. Can you give me a hint?

In the mt5 robot I need to put a curve like a moving average on the chart. Is there a more "civilized" way to display it than drawing it from objects?

Drawing values on CCanvas.

 
Andrey Sokolov #:

the key word here is "like". There's your own data there, not from a third-party indicator.

Make an indicator and add it as #resource
 

Hello. Can you give me a hint? The trading terminal has such a concept as ALERT. That is, we put it on theprice scaleand set conditions for reaching this price. But it turns out it is disposable. The trading robot is not a one-time event and the alert is not a one-time event.

 
valentin104 The trading terminal has such a concept as ALERT. That is, we put it on theprice scaleand set conditions for reaching this price. But it turns out it is disposable. The order is similar to the alerts but they are reusable, i.e. they keep on working until they are deactivated.

// использовать алерт
input bool alert = true;
// уровень срабатывания
input double trigLv = 0.0;
// отклонение от trigLv в пунктах
input int deviation = 30; 


// функция взята из https://www.mql5.com/ru/docs/basis/types/double
bool EqualDoubles(double d1,double d2,double epsilon)
  {
   if(epsilon<0) 
      epsilon=-epsilon;
//---
   if(d1-d2>epsilon) 
      return false;
   if(d1-d2<-epsilon) 
      return false;
//---
   return true;
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
  return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[]
) {
  static bool triggered = false;
  static datetime time_ = 0;
  if (!alert)
    return rates_total;
  if (EqualDoubles(trigLv, close[0], deviation * SymbolInfoDouble(NULL, SYMBOL_POINT))) { // сравнение цены Close с trigLv
    if (time_ != time[rates_total - 1])
      time_ = time[rates_total - 1];
    else
      return rates_total;
    if (!triggered)
      Alert("Level ", NormalizeDouble(trigLv, (int)SymbolInfoInteger(NULL, SYMBOL_DIGITS)), " triggered!");
    triggered = true;
  }
  else
    triggered = false;
  
  return rates_total;
}

The code is for MQL5. The function is based on the assumption that the indicator has the same function as in MQL5 and in MQL5 it is based on the same function as in MQL5.

Files:
Alert.mq5  5 kb
 

A word of advice. I'm stumped on a question.

How doesiOpen count for Ask or Bid?

double DayOpenone = NormalizeDouble(iOpen(Symbol(), PERIOD_D1, 0), Digits);

double DayOpentwo = NormalizeDouble(iOpen(Symbol(), PERIOD_D1, 1), Digits); 

The matter is that comparing the opening price for today with the opening price for yesterday seems to cause spread colocation and then there are further problems in the code. Either only bai or sells are traded because iOpen prices are not correct on some days.

 
Порт-моне тв iOpen count for Ask or Bid?

The matter is that comparing the open price for today with the open price for yesterday seems to cause spread colocation and then I get into problems in the code. I can trade either only bids or sells because iOpen prices are not correct on some days.

The chart is based on Bid price

 

Guys, please advise.

I'm writing a multi-currency EA, everything works as planned except for opening orders. Please tell me what the problem is.

      if((USDTP<=0)&&(JPYTP>=3)&&(z_USDJPY!=2))
        {
         Alert("Продавай USDJPY. USD=", USDTP, ", JPY=", JPYTP);
         z_USDJPY=2; //
         text_massage="Продавай USDJPY";
         SendNotification(text_massage);
         RefreshRates();
         Ask1=MarketInfo("USDJPY",MODE_ASK);
         Bid1=MarketInfo("USDJPY",MODE_BID);
         Point1=MarketInfo("USDJPY",MODE_POINT);
         OrderSend("USDJPY", OP_BUY, 0.1, Bid1, 3, NormalizeDouble((Ask1+StopLoss*Point1),2), NormalizeDouble((Ask1-TakeProfit*Point1),2), NULL, 0, 0, 0);
        }

I don't get any errors, I just don't open orders

 
Sergey Dymov a multi-currency EA, everything is working as planned except for opening orders. Please tell me what the problem is.

I don't get any error, it just does not open orders

OrderSend

Returned value

Returns ticket number assigned to the order by the trade server or -1 in case of failure. To get errorinformation , you need to call GetLastError().

Even the compiler tells you that Ordersend should be checked.

The purchase is done with Ask. But it may work with Bid as well, if the slippage is at least equal to the spread, which may make it harder to find this bug.