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

 
Ihor Herasko:

See SymbolSelect function.

Thank you!

 
Please advise how to shift the graph more to the left programmatically.Thank you!
 

Forum on trading, automated trading systems & strategy testing

Any questions for newbies on MQL4, help and discussion on algorithms and codes

labvic, 2018.03.12 14:43

Hi all, I am facing such a problem:

I open a trade without stoploss and takeprofit:

OrderSend("EURUSD",OP_BUY,0.1,Ask,0,0,0,"",Magic,0,Red);

I want to close this order.

OrderClose(Magic,OrderOpenPrice(),Ask,0,Red);

I get this error: OrderClose error 131

If instead ofOrderOpenPrice() I point 0.1 or OrderLots() there is an error: OrderClose error 138

What's the problem?

Judging by the documentation, it's very hard to write a much wackier close.

bool  OrderClose(
   int        ticket,      // номер ордера
   double     lots,        // количество лотов
   double     price,       // цена закрытия
   int        slippage,    // максимальное проскальзывание
   color      arrow_color  // цвет
   );
Instead of ticket written magik, instead of volume written open price. Read the documentation and feel free to look into it more often when writing code.


 
Nikolay Gaylis:
Please advise how to shift the chart even more to the left programmatically.Thank you!

I need to disable autoscroll and offset (chart properties CHART_AUTOSCROLL and CHART_SHIFT respectively) and then use ChartNavigate().

 
Ihor Herasko:

Need to disable autoscroll and offset (chart properties CHART_AUTOSCROLL and CHART_SHIFT respectively) and then use ChartNavigate().

Thank you!

 

Greetings all! I'm a newbie, trying to create an EA. I wrote a simple one to see how it would work. When a signal appears, the alert does not work. I do not know what is the error. I do not know what exactly the error is.

//+------------------------------------------------------------------+
//|                                             тенк больше кидж.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 double tenkan=iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,1);       //ЗНАЧЕНИЕ ТЕНКАН
 double kijun=iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,1);         // ЗНАЧЕНИЕ КИДЖУН
 //-------------------------------------------------------------------+
  if(tenkan>kijun)                                               //"ЗОЛОТОЙ КРЕСТ"
  Alert("ЗОЛОТОЙ КРЕСТ");                                       // ОПОВЕЩЕНИЕ
  return;
  }

Sincerely Andrei.

Files:
 
Andrey Ilinykh:

Greetings all! I'm a newbie, trying to create an EA. I wrote a simple one to see how it would work. When a signal appears, the alert does not work. I do not know what is the error. I do not know what exactly the error is.

Regards Andrew.

Is it working! Do you check it in the tester?

 
Nikolay Gaylis:

It's working! Do you check with a tester?

That's what I thought, for some reason.

No, I haven't figured out the tester yet.

I have compiled the Expert Advisor and I am using it on a minute chart. The cloud changes colour but the alert window does not open. Could it be a software error?

Thank you!

 
void Laguerr::  deleteOrders()   //  (int otype)
{
   int k = OrdersTotal();
   datetime mDateOrderOp; 
   
   
   for(int i=k-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol()==nameSym && OrderMagicNumber()== Magic && OrderCloseTime()==0)  // && OrderType() == otype)
         {
            if(OrderType()== OP_BUYSTOP || OrderType()== OP_SELLSTOP) 
            {
               mDateOrderOp = OrderOpenTime();
               int  mTick = OrderTicket();
               //if (OrderType()== OP_BUYSTOP) mOpType = OP_SELL;
               bool flag= false;
               for(int pos=k-1;pos>=0;pos--)
               {
                  if (OrderSelect(pos,SELECT_BY_POS, MODE_TRADES))
                  {
                     if (OrderSymbol()==nameSym && OrderMagicNumber()== Magic && OrderCloseTime()==0)  // && OrderType() == otype)
                     {
                        if(OrderOpenTime() == mDateOrderOp && (OrderType()== OP_BUY || OrderType()== OP_SELL)  ) 
                        {
                            flag = true;   
                            break;
                        } 
                     }
                  }
               }
               if (!flag)
               {
                  if (!OrderDelete(mTick))
                  Print("Ошибка delete ордера . Код ошибки=",GetLastError()); 
                  break;
               }
             } 
         }
      }
   }
}
Hello everyone, here is the situation: I open an order with a certain TP and OD. but OD triggers and a second order opens at the OD price of the first order in the opposite direction (OD is equal to the number of pips lost on the first order). In the case of a secondary SL, the third order should be opened in the opposite direction to the second order with the price equal to the value of the second order (Stop loss). Question: How to make this cascade of opening these three orders?
 
Can you tell me if the function of closing all orders opened by the EA on the symbol is correct?
void OrderCloseAll(double close_price)
{
   for(int i=OrdersTotal(); i>-1; i--)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) OrderClose(OrderTicket(),lot,close_price,slippage,clrWhite);
      }

}