Questions from Beginners MQL4 MT4 MetaTrader 4 - page 139

 

I am running the Expert Advisor in the Strategy Tester. When modifying a BUYSTOP order, it generates an error:

I do not understand why. The price at which my order is offered to move is 40 higher than the Ask price, StopLevel =30. The price is normalized, what else is required?

 
khorosh:

I am running the Expert Advisor in the Strategy Tester. When modifying a BUYSTOP order, it generates an error:

I do not understand why. The price at which my order is offered to move is 40 higher than the Ask price, StopLevel =30. The price is normalized, what else is required?

I've seen it with one broker - instead of 10, try to set it higher by 11 pips.
 
Лауреат:
Please advise how to make a function for setting the required number of orders! for example, to open a specified number of orders without more. in mql4
 
Konstantin Erin:
if(OrdersTotal() < OrdersMax) OrderSend(...); else Alert("The required number of orders opened"); if this is used then several successive orders are opened ! not orders if there is another signal to trade so how to make it open the required number of orders if there are further signals to trade after the first open order ! ?
 

Why isn't anyone helping, please?

 
Лауреат:
if(OrdersTotal() < OrdersMax) OrderSend(...); else Alert("The required number of orders opened"); if this is used then several consecutive orders will be opened ! not orders if there is another signal to trade so how to make it open the required number of orders if there are further signals to trade after the first open order ! ?
enum Цвет   // Цвет флага
{
  Красный,
  Зеленый
};

Цвет Флаг=Красный;

void start()
{
   if(!Сигнал())Флаг=Зеленый;

   if(Сигнал()>0 && Флаг==Зеленый)
   {
      OrderSend(Покупка...);
      Флаг=Красный;
   }

   if(Сигнал()<0 && Флаг==Зеленый)
   {
      OrderSend(Продажа...);
      Флаг=Красный;
   }
}

int Сигнал()  // Сигналы покупки и продажи
{
   return ЧтоНадо;
}
This could be as short as 5 lines, but I'm too lazy to think...
 

Guys, advise where to find or help me to correct trailing stop, which works this way:

For example, an BUY order with TP = 100 and SL = 200 was opened, and when the price went to BUY and passed 50 points, then SL becamethe opening price, while TP was moved to 50 points and so on constantly????

void TrailingPositions(int otype)
{

int cnt = OrdersTotal();

int lMinProfit = 0; // Min. pips

int lTrailingStop = 40; // Trailing position level (the number of points from the previous SL distance)

int lTrailingStep = 20; // Trailing stop level (the number of points after which it will trigger)

for (int i=0; i<cnt; i++)
{
if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
if (OrderSymbol() != Symbol()) continue;

if (OrderType() == OP_BUY && otype == OP_BUY) {
if (Bid-OrderOpenPrice() > lMinProfit*Point) {
if (OrderStopLoss() < Bid-(lTrailingStop+lTrailingStep-1)*Point) {
if(OrderModify(OrderTicket(), OrderOpenPrice(), Bid-lTrailingStop*Point, TP + lTrailingStop * Point, 0, Blue))
Print("TrailingStop is working");
}
}
}

if (OrderType() == OP_SELL && otype == OP_SELL) {
if (OrderOpenPrice()-Ask > lMinProfit*Point) {
if(OrderStopLoss() > Ask+(lTrailingStop+lTrailingStep-1)*Point || OrderStopLoss() == 0) {
if(OrderModify(OrderTicket(), OrderOpenPrice(), Ask+lTrailingStop*Point, TP - lTrailingStop * Point, 0, Red))
Print("Trailing Stop is working");
}
}
}
 
LRA:
It could be shorter by 5 lines, but I'm too lazy to think...
Good idea I will have to try it out. thank you. however, will it work with onticket void OnTick() function ?
 
Hello comrades! Please help me with the installation of the object "button", I need to place code in the Expert Advisor, so that directly on the chart button in the pressed or not pressed state returns a value of bool. Thank you in advance!
 
Arseniy Barudkin:
Hello Comrades! Please help with setting the "button" object, I need to place code in the EA so that directly on the chart the button in the pressed or not pressed state would return a bool value. Thank you in advance!
ObjectGetInteger(ChartId(),"имя кнопки",OBJPROP_STATE)

here's