Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1377

 
Fast235 #:

as one of the participants says, to the factory.

due to the impossibility of perception

You have to assign a unique number to the object, this number has to be collected from the parameters:

- Openingtime of the object

- object period

- object's time frame

For example:

int Num= TimeOpen+Period*0.0001

Well I'm not sure if this number will be exclusive, and the data type under int does not fit, but preferably int

 
Mikhail Toptunov #:

A unique number must be assigned to the object, and this number must be collected from the parameters:

- Openingtime of the object

- object period

- object's timeframe

For example:

Well I'm not sure that this number will be exclusive, and the data type under int does not fit, but it is desirable int

unique number is assigned automatically - tr_Deal73772984

it is not clear what the question is

 

look at this simple code

   for(uint i=0; i<total; i++)
     {
      //--- try to get deals ticket
      if((ticket=HistoryDealGetTicket(i))>0)
        {
         symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
         if(symbol!=Symbol())
            continue;
         //--- get deals properties
         price =HistoryDealGetDouble(ticket,DEAL_PRICE);
         time  =(datetime)HistoryDealGetInteger(ticket,DEAL_TIME);
         type  =HistoryDealGetInteger(ticket,DEAL_TYPE);
         entry =HistoryDealGetInteger(ticket,DEAL_ENTRY);
         profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
         id    =HistoryDealGetInteger(ticket, DEAL_POSITION_ID);
         //---
         text  =DoubleToString(profit,2);
         //---
         //+------------------------------------------------------------------+
         //|                                                                  |
         //+------------------------------------------------------------------+
         if(price && time && symbol==Symbol())
           {
            //--- create price object
            name=prefix+"Deal"+string(ticket);
            name2=prefix+"Price"+string(ticket);
            if(entry==DEAL_ENTRY_IN)
              {
               ObjectCreate(0,name,OBJ_ARROW_LEFT_PRICE,0,time,price,0,0);
                 {
                  timeOpen=time;
                  priceOpen=price;
                 }
              }
            if(entry==DEAL_ENTRY_OUT)
              {
               // if(ShowRightTabTab)
               //---создадим метку на закрытии
               ObjectCreate(0,name,OBJ_ARROW_RIGHT_PRICE,0,time,price,0,0);
               //--- нарисуем линию  сделки
               ObjectCreate(0,name+"_trend",OBJ_TREND,0,timeOpen,priceOpen,time,price);
               //--- добавим на график результат сделки
               ObjectCreate(0,name2,OBJ_TEXT,0,time,price+offset*_Point);
               if(profit>0.0)
                  clr=inpColorTP;
               else
                  clr=inpColorSL;
              }
 

Hello.

How do I make Fibonacci levels visible/invisible? Generally, we need to remove some levels. If I use the OBJPROP_LEVELS property, it just makes the first N levels available. How to set the visibility property for each of the levels, or remove it altogether?

 
leonerd #:

Hello.

How do I make Fibonacci levels visible/invisible? Generally, we need to remove some levels. If I use the OBJPROP_LEVELS property, it just makes the first N levels available. How can I set the visibility property for each of the levels, or remove it altogether?

It goes like this.

double fiboLev[] = {0.0, 0.236, 0.382, 0.5, 0.618, 0.764, 0.882, 1.0, 1.236, 1.382, 1.618, 2.0, 2.236, 2.618, 3.236, 3.618, 4.236};
/************************fiboCreate function*************************/
void fiboCreate(datetime t0, double p0, datetime t1, double p1)
 {
  long chartID = ChartID();
  if(ObjectFind(chartID, fiboName) < 0)
   {
    ObjectCreate(chartID, fiboName, OBJ_FIBO, 0, t1, p1, t0, p0);
    ObjectSetInteger(chartID, fiboName, OBJPROP_WIDTH, 2);
    ObjectSetInteger(chartID, fiboName, OBJPROP_COLOR, clrFibo);
    ObjectSetInteger(chartID, fiboName, OBJPROP_LEVELS, 23);
    ObjectSetInteger(chartID, fiboName, OBJPROP_LEVELCOLOR, clrFibo);
    for(int i = 0; i < 17; i++)
     {
      ObjectSetDouble(chartID, fiboName, OBJPROP_LEVELVALUE, i, fiboLev[i]);
      ObjectSetString(chartID, fiboName, OBJPROP_LEVELTEXT, i, "%$ ("+DoubleToString(fiboLev[i]*100, 1)+")");
     }
   }
  else
    if(ObjectFind(chartID, fiboName) == 0)
     {
      ObjectSetInteger(chartID, fiboName, OBJPROP_TIME, 0, t0);
      ObjectSetDouble(chartID, fiboName, OBJPROP_PRICE, 0, p0);
      ObjectSetInteger(chartID, fiboName, OBJPROP_TIME, 1, t1);
      ObjectSetDouble(chartID, fiboName, OBJPROP_PRICE, 1, p1);
     }
  ChartRedraw();
 }/******************************************************************/

This is excerpted from the EA, some variables are not defined here. This code will not compile.

 

Hello, is there any way to remove an array element with an offset from the structure using standard means


struct OrderFib
  {
   double            id;
   double            Price[Umax];            
   int               type;
   int               PeriodUr50;  // № Периода
  } trade_buff[];

1) trade_buff[0]...
   trade_buff[1]... deleted
   trade_buff[2]...

2) trade_buff[0]...
   trade_buff[1]... 
 

Done like this, you could do it more professionally, couldn't you?

//+----------Удаляем старый сигнал-----------------------------------+
void filterDeal_1(int tf)
  {
   for(int i= 0; i<CountTrade; i++)
      if(trade_buff[i].tf == tf)
        {
         ArrayRemove(trade_buff,i,1);
         CountTrade--;
         i= 0;
        }
  }
 
Mikhail Toptunov #:

Done this, could it be done in a more professional way?

Hi, to delete array elements, start from the end of the array, then you don't need to change the index. It goes in order by itself.

for(int i=CountTrade-1; i>=0; i--)
   {
   if(trade_buff[i].tf == tf)
      {
      ArrayRemove(trade_buff,i,1);
      }
   }
 
Aleksei Stepanenko #:

Hi, to delete array elements, start at the end of the array, then you don't need to change the index. It goes in order by itself.

Right, Cool, Thanks!

 
Mikhail Toptunov #:

A unique number must be assigned to the object, and this number must be collected from the parameters:

- Openingtime of the object

- object period

- object's timeframe

For example:

Well I am not sure that this number will be exclusive, and data type under int does not fit, but preferably int

If we want to decrypt later, it's better to encrypt object name instead of number. I.e. we assemble name from digits and digits to string and then string digits to int. The only thing to do is either divide fields with delimiters or take into account the number of characters in each field.

Reason: