Questions from Beginners MQL5 MT5 MetaTrader 5 - page 72

 

Lester:
This is a template with built-in functions for opening, closing and modifying.
The opening and closing are written by Nikolay Kositsin.

I easily changed them and added modifications.

I think it's clear how to call them up, so for your convenience.

Sorry about that - mixed upthe file.

Документация по MQL5: Файловые операции / FileMove
Документация по MQL5: Файловые операции / FileMove
  • www.mql5.com
Файловые операции / FileMove - Документация по MQL5
Files:
schablon_1.mq5  13 kb
 
papaklass:

Try it this way:

Unfortunately, the orders don't close at all. I think I should think about it for a while)
 
mario065:

Lester:
This template has built-in functions for opening, closing and modifying.
The opening and closing are written by Nikolay Kositsin.

I easily changed them and added modifications.

I think it's clear how to challenge them, so for your convenience.

How do I open such files with an editor?
 
Lester:
How do you open such files with an editor?

You can't open those. ))

Try reading some articles. There's a lot to choose from, from the smallest to the most mature. ))

 
Lester:
Unfortunately, the orders do not close at all. I think I should think about it for a while)

Changed the file, sorry about that.

I got the file mixed up, sorry.

 
papaklass:

Whoa. What does this have to do with warrants? We have been talking about a position all along. A position and pending orders are different things. They must be closed differently!

Pending orders are not closed but deleted. Positions are closed by opening a market order of equal volume and opposite direction to the open position.

The code you cited was not designed to delete pending orders.

You can use this function to delete orders:


Got it. Nothing about orders - just positions.

I prescribed PositionSelect at night - it seems to have caught my breath. It sends (closes) positions every once in a while, but I think conditions are already involved here.

I do not understand something else. It does not form stop and profit losses, the values of which are prescribed in the input parameters. If I prescribe these values in the sending, the same thing happens - i.e. nothing.

input int StopLoss=60;      // Stop Loss
input int TakeProfit=170;   // Take Profit
int OnInit()
 ...
   STP = StopLoss;
   TKP = TakeProfit;
   if(_Digits==5 || _Digits==3)
     {
      STP = STP*10;
      TKP = TKP*10;
     }
   return(0);
  }
...
 mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
         mrequest.price = NormalizeDouble(Ask,_Digits);    // последняя цена ask
         mrequest.sl = StopLoss; // Stop Loss
         mrequest.tp = TakeProfit; // Take Profit
         mrequest.symbol = _Symbol;                                            // символ
         mrequest.volume = Lot;                                                // количество лотов для торговли
         mrequest.magic = EA_Magic;                                            // Magic Number
         mrequest.type = ORDER_TYPE_BUY;                                       // ордер на покупку
         mrequest.type_filling = ORDER_FILLING_FOK;                            // тип исполнения ордера - все или ничего
         mrequest.deviation=10;                                               // проскальзывание от текущей цены
         //--- отсылаем ордер
         OrderSend(mrequest,mresult);
         // анализируем код возврата торгового сервера
         if(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
           {
            Alert("Ордер Buy успешно помещен, тикет ордера #:",mresult.order,"!!");
           }
         else
           {
            Alert("Запрос на установку ордера Buy не выполнен - код ошибки:",GetLastError());
            return;

 

Hello. Can you please tell me what I should do in MT4 after I subscribe to the signals, so that the synchronization could take place? I found in the instructions what to do with MT5, I have not found instructions for MT4. I have subscribed to the signal from MT4.

I have signed up for the signal from MT4. Thank you.

Торговые сигналы
Торговые сигналы
  • www.mql5.com
Торговые Сигналы для MetaTrader: копирование сделок, мониторинг счета, автоматическое исполнение сигналов и социальный трейдинг
 
Lester:

Understood. No mention of orders - just positions.

I prescribed PositionSelect at night - it seems to have caught my breath. It sends (closes) positions every once in a while, but I think conditions are already involved here.

I do not understand something else. It does not form Stop and Profit Loss, values of which are prescribed in the input parameters. If I prescribe these values in the sending, the same thing happens - i.e. nothing.

Stops and Profits are not specified correctly.
Здес указали целое число
input int StopLoss=60;      // Stop Loss
input int TakeProfit=170;   // Take Profit

...
   STP = StopLoss;
   TKP = TakeProfit;
   if(_Digits==5 || _Digits==3)
     {
      STP = STP*10;
      TKP = TKP*10;
     }
   return(0);
  }
...

mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
         mrequest.price = NormalizeDouble(Ask,_Digits);    // последняя цена ask
         mrequest.sl = NormalizeDouble(Ask - StopLoss*_Points,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(Ask + TakeProfit*_Points,_Digits);  // Take Profit

На места для стоп и профит нужна цена!
 
papaklass:

The reason why stops are not set when a position is opened may depend on the trading mode. There are three modes: Request Execution, Instant Execution and Market Execution.

If your broker uses the Market Execution mode, you need to open a position first and then modify (set stops) it on the next tick. At the same time, i.e. in one order, with this trading mode it is not possible to open a position with stops.

In general, deal with the structure of a trade request:MQL5 Reference / Standard constants, enumerations and structures / Data structures / Structure of a trade request. I think this will help you in further study of the language.

Indeed, there's Market Execution in Alpari . Is there an order modification structure itself? As there is no modification in the forum as long as there is an open sell or buy order.

If I'm not mistaken, the "fish" of modification looks like this.

if(PositionSelect(_Symbol)==true) // есть открытая позиция
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        { ModifyPosition(стоплосс на покупку)
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
        {
         { ModifyPosition(стоплосс на продажу)
        }
return


 
Lester:
Indeed, in Alpari Market Execution . Is there an order modification structure itself? As there is no modification in the forum as long as there is an open Sell or Buy order.

If I'm not mistaken, the 'fish' of the modification looks like this.

Use the ready solution from the standard library(CTrade class- PositionModify method). It is a good solution for a beginning. At any moment you can make your own similar class and make the necessary changes.
Reason: