Drag drop SCRIPT FILE MQL4 to MQL5

 
hi, i am trying to use this SCRIPT FILE code in mql5 but i have used many attempts to redefine the codes to make it work but i just couldn't do it, i am providing the original code in mql4 kindly help me as i have seen mql5 is lot more complicated than mql4 and i just couldn't do it, please i request your help.
int start()
  {
//----
   int digits   = MarketInfo(Symbol(),MODE_DIGITS);
   double value = NormalizeDouble(WindowPriceOnDropped(),digits);
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol())
         continue;
      
      RefreshRates();
      
      if(OrderType()==OP_BUY)     
      if(value>Ask)
         OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);
      if(OrderType()==OP_SELL)
      if(value<Bid)
         OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);      
      if((OrderType()==OP_BUYSTOP) || (OrderType()==OP_BUYLIMIT))     
      if(value>OrderOpenPrice())
         OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);   
      if((OrderType()==OP_SELLSTOP) || (OrderType()==OP_SELLLIMIT))
      if(value<OrderOpenPrice())
         OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);                  
   }   
   return(0);
  }
//+------------------------------------------------------------------+

 
SunDragon :
hi, i am trying to use this SCRIPT FILE code in mql5 but i have used many attempts to redefine the codes to make it work but i just couldn't do it, i am providing the original code in mql4 kindly help me as i have seen mql5 is lot more complicated than mql4 and i just couldn't do it, please i request your help.

There is nothing complicated in MQL5. The main thing you should do: uproot the word “order” from your head, and use the new word “position” and “pending order” instead.

Position is: BUY and SELL.

A pending order is: Buy stop, Buy limit, Sell stop, Sell limit ...

 
An example based on ChartPriceOnDropped will be later ...
Documentation on MQL5: Standard Library / Price Charts / PriceOnDropped
Documentation on MQL5: Standard Library / Price Charts / PriceOnDropped
  • www.mql5.com
Standard Library / Price Charts / PriceOnDropped - Reference on algorithmic/automated trading language for MetaTrader 5
 

As I promised - here is the code. Here (just in case) a verification of the success of the modification is introduced. This check increased the code, but in case of an error it will be possible to see.

//+------------------------------------------------------------------+
//|                             ChartPriceOnDropped Modification.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.000"
#property script_show_inputs
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\OrderInfo.mqh>
//---
CPositionInfo  m_position;                   // object of CPositionInfo class
CTrade         m_trade;                      // object of CTrade class
CSymbolInfo    m_symbol;                     // object of CSymbolInfo class
COrderInfo     m_order;                      // object of COrderInfo class
//---
input ulong    InpDeviation         = 10;    // Deviation, in points (1.00045-1.00055=10 points)
input bool     InpPrintLog          = false; // Print log
input ulong    InpMagic             = 456;   // Magic number
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   if(!m_symbol.Name(Symbol())) // sets symbol name
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: CSymbolInfo.Name");
      return;
     }
   RefreshRates();
//---
   m_trade.SetExpertMagicNumber(InpMagic);
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(m_symbol.Name());
   m_trade.SetDeviationInPoints(InpDeviation);
//---
   double price_on_dropped=ChartPriceOnDropped();

   for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of open positions
      if(m_position.SelectByIndex(i))
         if(m_position.Symbol()==m_symbol.Name())
           {
            double price_current = m_position.PriceCurrent();
            double stop_loss     = m_position.StopLoss();
            //---
            if(m_position.PositionType()==POSITION_TYPE_BUY)
              {
               if(price_on_dropped>price_current)
                 {
                  if(!m_trade.PositionModify(m_position.Ticket(),
                                             stop_loss,
                                             m_symbol.NormalizePrice(price_on_dropped)))
                     if(InpPrintLog)
                        Print(__FILE__," ",__FUNCTION__,", ERROR: ","Modify BUY ",m_position.Ticket(),
                              " Position -> false. Result Retcode: ",m_trade.ResultRetcode(),
                              ", description of result: ",m_trade.ResultRetcodeDescription());
                  continue;
                 }
              }
            else
              {
               if(price_on_dropped<price_current)
                 {
                  if(!m_trade.PositionModify(m_position.Ticket(),
                                             stop_loss,
                                             m_symbol.NormalizePrice(price_on_dropped)))
                     if(InpPrintLog)
                        Print(__FILE__," ",__FUNCTION__,", ERROR: ","Modify SELL ",m_position.Ticket(),
                              " Position -> false. Result Retcode: ",m_trade.ResultRetcode(),
                              ", description of result: ",m_trade.ResultRetcodeDescription());
                  continue;
                 }
              }
           }

   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of current orders
      if(m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties
         if(m_order.Symbol()==m_symbol.Name())
           {
            double price_current = m_order.PriceCurrent();
            double price_open    = m_order.PriceOpen();
            double stop_loss     = m_order.StopLoss();
            ENUM_ORDER_TYPE_TIME type_time=m_order.TypeTime();
            datetime expiration  = m_order.TimeExpiration();
            //---
            if(m_order.OrderType()==ORDER_TYPE_BUY_LIMIT)
              {
               if(price_on_dropped>price_open)
                 {
                  if(!m_trade.OrderModify(m_order.Ticket(),price_open,
                                          stop_loss,
                                          m_symbol.NormalizePrice(price_on_dropped),
                                          type_time,expiration))
                     if(InpPrintLog)
                        Print(__FILE__," ",__FUNCTION__,", ERROR: ","Modify Buy limit ",m_position.Ticket(),
                              " Position -> false. Result Retcode: ",m_trade.ResultRetcode(),
                              ", description of result: ",m_trade.ResultRetcodeDescription());
                  continue;
                 }
              }
            else
               if(m_order.OrderType()==ORDER_TYPE_SELL_LIMIT)
                 {
                  if(price_on_dropped<price_open)
                    {
                     if(!m_trade.OrderModify(m_order.Ticket(),price_open,
                                             stop_loss,
                                             m_symbol.NormalizePrice(price_on_dropped),
                                             type_time,expiration))
                        if(InpPrintLog)
                           Print(__FILE__," ",__FUNCTION__,", ERROR: ","Modify Sell limit ",m_position.Ticket(),
                                 " Position -> false. Result Retcode: ",m_trade.ResultRetcode(),
                                 ", description of result: ",m_trade.ResultRetcodeDescription());
                     continue;
                    }
                 }
               else
                  if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
                    {
                     if(price_on_dropped>price_open)
                       {
                        if(!m_trade.OrderModify(m_order.Ticket(),price_open,
                                                stop_loss,
                                                m_symbol.NormalizePrice(price_on_dropped),
                                                type_time,expiration))
                           if(InpPrintLog)
                              Print(__FILE__," ",__FUNCTION__,", ERROR: ","Modify Buy stop ",m_position.Ticket(),
                                    " Position -> false. Result Retcode: ",m_trade.ResultRetcode(),
                                    ", description of result: ",m_trade.ResultRetcodeDescription());
                        continue;
                       }
                    }
                  else
                     if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
                       {
                        if(price_on_dropped<price_open)
                          {
                           if(!m_trade.OrderModify(m_order.Ticket(),price_open,
                                                   stop_loss,
                                                   m_symbol.NormalizePrice(price_on_dropped),
                                                   type_time,expiration))
                              if(InpPrintLog)
                                 Print(__FILE__," ",__FUNCTION__,", ERROR: ","Modify Sell stop ",m_position.Ticket(),
                                       " Position -> false. Result Retcode: ",m_trade.ResultRetcode(),
                                       ", description of result: ",m_trade.ResultRetcodeDescription());
                           continue;
                          }
                       }
           }
  }
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data                                 |
//+------------------------------------------------------------------+
bool RefreshRates()
  {
//--- refresh rates
   if(!m_symbol.RefreshRates())
     {
      if(InpPrintLog)
         Print(__FILE__," ",__FUNCTION__,", ERROR: ","RefreshRates error");
      return(false);
     }
//--- protection against the return value of "zero"
   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
     {
      if(InpPrintLog)
         Print(__FILE__," ",__FUNCTION__,", ERROR: ","Ask == 0.0 OR Bid == 0.0");
      return(false);
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
 
Vladimir Karputov:

As I promised - here is the code. Here (just in case) a verification of the success of the modification is introduced. This check increased the code, but in case of an error it will be possible to see.

I CAN'T THANK YOU ENOUGH, YOU SAVED ME.. i was so stressed, i couldn't think of anything else, this is the best day of my life.. i am trying to learn Advance level of MQL5, i hope i succeed, you really motivated me, thank you sir Vladimir Karputov :) 

Reason: