Getting MT5 Rectangle value

 

hi everyone, first i should specify that I'm a beginner, I'm still learning while playing with codes. It would be great if your answers are detailed and simplified. I'm not only looking for an answer, I'm also trying to learn from it.

I have attached all the code source to this document. 

MT4 Version

  • Indicator : shved_supply_and _demand.mq4
  • Expert    : SbD_Expert_Advisor.mq4

MT5 Version

  • indicator : shved_supply_and _demand_v1.6.mq5

Both indicators are the same just one is for mt4 and the other one is for mt5. My goal here is to build an MT5 EA from the mt5 version of the indicator using ICustom function. The problem I'm currently facing is how to specify the buy and sell conditions, don't get me wrong, i mean how to write the code for buy and for sell.

The indicator is a support and resistance indicator, it draws a rectangle and S&R zone. After many failure on trying to do the EA, i have found the MT4 version, and I find i did understand the most of it. 

First we neet to get the indicator value

S&R rectangle value illustration

Second Apply the trades conditions

// this is just my opinion, based on what i know 
// and that i think it is correct
   
//+------------------------------------------------------------------+
//|  BUY Condition                                                   |
//+------------------------------------------------------------------+
   
if(Open(0)>ZONE_RESIST_LOW && Close(0)<ZONE_RESIST_LOW) OP_SELL;
//--- some may also prefer if(Open(1)/bid/ask/Close(1)/Open(0)>ZONE_RESIST && Close(0)<ZONE_RESIST) OP_SELL;
//--- i think this part depend doesnt matter as lond that it does the job'

//+------------------------------------------------------------------+
//|  SELL Condition                                                  |
//+------------------------------------------------------------------+
  
if(Open(0)<ZONE_SUPPORT_HIGH && Close(0)>ZONE_SUPPORT_HIGH)


Now my problem is the function that is used to get the indicator S&R value, Normaly i should have done something like this



// get res level from the chart
double get_res()
  {
   double _res=999999999999;
   double _tmp=0;
   long _chart=ChartID();
   for(int i=0;i<ObjectsTotal(_chart);i++)
     {
      string _name=ObjectName(_chart,i);
      if(StringFind(_name,"R#R",0)>0 && StringFind(_name,"Untested",0)>0) _tmp=ObjectGetDouble(_chart,_name,OBJPROP_PRICE2);
      if(_res>_tmp && _tmp!=0) _res=_tmp;
     }
   return(_res);
  }
  
double get_res_sl()   //--- For the stop loss
  {
   double _res=999999999999;
   double _tmp=0;
   long _chart=ChartID();
   for(int i=0;i<ObjectsTotal(_chart);i++)
     {
      string _name=ObjectName(_chart,i);
      if(StringFind(_name,"R#R",0)>0 && StringFind(_name,"Untested",0)>0) _tmp=ObjectGetDouble(_chart,_name,OBJPROP_PRICE1);
      if(_res>_tmp && _tmp!=0) _res=_tmp;
     }
   return(_res);
  }
//+------------------------------------------------------------------+

int OrdersTotalT(int _type)
  {
   int _total=0;
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
     {

      bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()==_type)
        {
         _total++;
        }
     }
   return(_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double get_sup()
  {
   double _res=0;
   double _tmp=0;
   long _chart=ChartID();
   for(int i=0;i<ObjectsTotal(_chart);i++)
     {
      string _name=ObjectName(_chart,i);
      if(StringFind(_name,"R#S",0)>0 && StringFind(_name,"Untested",0)>0) _tmp=ObjectGetDouble(_chart,_name,OBJPROP_PRICE1);
      
     }
   return(_res);// return lower untested support
  }
  
double get_sup_sl() //--- For the stop loss

  {
   double _res=0;
   double _tmp=0;
   long _chart=ChartID();
   for(int i=0;i<ObjectsTotal(_chart);i++)
     {
      string _name=ObjectName(_chart,i);
      if(StringFind(_name,"R#S",0)>0 && StringFind(_name,"Untested",0)>0) _tmp=ObjectGetDouble(_chart,_name,OBJPROP_PRICE2);
      
      if(_res<_tmp && _tmp!=0) _res=_tmp;
     }
   return(_res);
  }

I'm having hard time trying to do the mt5 version of this part of the code. can anyone please assist me ?

 

ObjectGetDouble has a moderator, the last parameter:  int prop_modifier=0

For it applies: OBJPROP_PRICE  Price coordinate  double    modifier=number of anchor point.

It's all written in the reference: place the cursor on the function and press F1 - just two clicks and a tenth of a second away

Dokumentation zu MQL5: Graphische Objekte / ObjectGetDouble
Dokumentation zu MQL5: Graphische Objekte / ObjectGetDouble
  • www.mql5.com
ObjectGetDouble - Graphische Objekte - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5
 
Carl Schreiber #:

ObjectGetDouble has a moderator, the last parameter:  int prop_modifier=0

For it applies: OBJPROP_PRICE Price coordinate double    modifier=number of anchor point.

It's all written in the reference: place the cursor on the function and press F1 - just two clicks and a tenth of a second away

with all the respect i have for you, i did understand nothing, can you please repeat it in easy English?

Should I go with the first function or the second?

because i'm now a little more confused, should i return all value or just the variable

 

Well search for this: objectgetdouble OJPROP_PRICE (choose articles)

Then take the first one: https://www.mql5.com/en/articles/3442

And search there (Ctrl+F) for OBJPROP_PRICE and you have an example:

        double p1 = ObjectGetDouble(0, name, OBJPROP_PRICE, 0);
        double p2 = ObjectGetDouble(0, name, OBJPROP_PRICE, 1);
P.S. Before learning to code learn to search.
TradeObjects: Automation of trading based on MetaTrader graphical objects
TradeObjects: Automation of trading based on MetaTrader graphical objects
  • www.mql5.com
The article deals with a simple approach to creating an automated trading system based on the chart linear markup and offers a ready-made Expert Advisor using the standard properties of the MetaTrader 4 and 5 objects and supporting the main trading operations.