Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1126

 
my question is if my EA is on the poundbucks chart and I want it to see a horizontal line from the eurobucks chart this does not work ?
 
Aleksandr Egorov:
my question is if my EA is on the GBP chart and I want it to see a horizontal line from the EUR chart this does not work ?

Note the first parameter of the function

string  ObjectName( 
   long  chart_id,           // идентификатор графика 
   int   pos,                // номер в списке объектов 
   int   sub_window=-1,      // номер окна 
   int   type=-1             // тип объекта 
   );

It is present in all functions of work with graphic objects.

Using the correct identifier you can easily get the object properties from any chart.

Документация по MQL5: Графические объекты / ObjectName
Документация по MQL5: Графические объекты / ObjectName
  • www.mql5.com
Функция использует синхронный вызов – это означает, что функция дожидается выполнения всех команд, которые были помещены в очередь графика перед её вызовом, и поэтому данная функция может быть затратной по времени. Нужно иметь это обстоятельство в виду...
 
Well long is m5 etc 0 current chart, and String Sumbol how?
 
Aleksandr Egorov:
the long is the m5 and tg 0 current chart, but the string sumbol how? i need it on the pound from the chart of the euro or something i do not understand

No, no timeframes - you need a chart ID:ChartID

One of the options: run a script on the chart with the line, which printsChartID, then you can access the line property from another chart. For example, if it is a horizontal line, then throughObjectGetDouble

 
Vladimir Karputov:

No, no timeframes - you need a chart ID:ChartID

One of the options: on the chart where the line is plotted, run a script that printsChartID, then you can access the property of the line from another chart. For example, if it is a horizontal line, then through ObjectGetDoubl thank you

thanks

 
Aleksandr Egorov:

thanks

There is another option: you just need to know the name of the graphical object and the type (you need the name to search through all graphs, and the type to find exactly the right object) ...

 
Aleksandr Egorov:

thanks

Variant #2: set name, type of object and in which window to search for it ("0" - in the main window). The search is performed in OnInit and if the object is found, we save the chart identifier to the m_obj_chart_id variable.

//+------------------------------------------------------------------+
//|                                    Object from another chart.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//--- input parameters
input string      InpObjName     = "Object Name";  // Object: Name
input ENUM_OBJECT InpObjType     = OBJ_HLINE;      // Object: Type
input int         InpObjSubWindow= 0;              // Object: Window Index
//---
long     m_obj_chart_id=-1;   // Object ChartID
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

//--- variables for chart ID
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   Print("ChartFirst =",ChartSymbol(prevChart)," ID =",prevChart);
   while(i<limit)// We have certainly not more than 100 open charts
     {
      currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID
      if(currChart<0)
         break;          // Have reached the end of the chart list
      int total=ObjectsTotal(currChart,InpObjSubWindow,InpObjType);
      for(int j=0; j<total; j++)
         if(ObjectName(currChart,j,InpObjSubWindow,InpObjType)==InpObjName)
           {
            m_obj_chart_id=currChart;
            break;
           }
      prevChart=currChart;// let's save the current chart ID for the ChartNext()
      i++;// Do not forget to increase the counter
     }
//---
   if(m_obj_chart_id==-1)
      return(INIT_FAILED);
   else
      Print("Object Name ",InpObjName," found on chart ",m_obj_chart_id);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
 
If I place market orders(TRADE_ACTION_DEAL) with specified Stop Loss and Take Profit levels, but the broker has a ban on setting orders with SL or TP, will the order be cancelled or set with zero SL and TP?
 
Vladimir Karputov:

Variant #2: specify name, object type and in which window to search for it ("0" - in the main window). The search is performed in OnInit and if the object is found, we save the chart identifier to the m_obj_chart_id variable.

Thank you even more

 

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Vladimir Karputov, 2019.08.31 08:16


And your mistake is in the start price formation:

//--- start work
   double start_price_ask=m_symbol.Ask()-ExtUpGap;
   double start_price_bid=m_symbol.Bid()+ExtDownGap;

I recommend to make the starting price separately for Stop and separately for Limit pending orders.

Hello Vladimir!

Please help me modify the start price of the script below:

//--- start work


   double start_price_ask=0.0;
   double start_price_bid=0.0;
   if(InpPending==stop)
     {
      start_price_ask=m_symbol.Ask()+ExtUpGap;
      start_price_bid=m_symbol.Bid()-ExtDownGap;
     }
   else
      if(InpPending==limit)
        {
         start_price_ask=m_symbol.Ask()-ExtUpGap;
         start_price_bid=m_symbol.Bid()+ExtDownGap;
        }

The script should place pending orders not based on Ask and Bid, but on the hight and low of the previous bar (candlestick).

Sincerely, Vladimir.

Reason: