Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1268

 
Alexey Viktorov:

It is very likely that after renaming an object, it is not yet available to be accessed. You can try putting ChartRedraw after renaming. If that doesn't work, then you need to build the sequence somehow else.

ps; Another option is to repaint with sparam name first and then rename.

Thanks again!!! What would I do without you? ))))

 
Vladimir Karputov:

Example inFibonaci RR code -

Thanks for the example, but this is just setting trading levels. I am interested in setting Fibonacci levels like 0.0%, 23.6%, 38.2%, 50%, 61.8%, 100%, 161.8%, 261.8%...

https://www.metatrader5.com/ru/terminal/help/objects/fibo/fibo_retracement

The auto indicator draws by default and by standard Fibo levels. There should be a source code of Fibo tools in the terminal that could be changed or copied from it... I can't find it, if you know it, please give me a hint.

Or how to add the following levels in custom indicator:0.0%, 23.6%, 38.2%, 50%, 61.8%, 100%, 161.8%, 261.8%...

   ObjectCreate(chart_id,name,OBJ_EXPANSION,nwin,time1,price1,time2,price2,time3,price3);
   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
   ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);

   if(ray>0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,true);
   if(ray<0)ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,true);

   if(ray==0)
     {
      ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,false);
      ObjectSetInteger(chart_id,name,OBJPROP_RAY_LEFT,false);
     }

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

   for(int numb=0; numb<10; numb++)
     {
      ObjectSetInteger(chart_id,name,OBJPROP_LEVELCOLOR,numb,Color);
      ObjectSetInteger(chart_id,name,OBJPROP_LEVELSTYLE,numb,style);
      ObjectSetInteger(chart_id,name,OBJPROP_LEVELWIDTH,numb,width);
     }

Please advise

 
Kira27:

Thanks again!!! What would I do without you? ))))

Maybe I'd learn to think logically.)))

 
VVT:

Thanks for the example, but this is just setting trading levels. I am interested in setting Fibonacci levels like 0.0%, 23.6%, 38.2%, 50%, 61.8%, 100%, 161.8%, 261.8%...

https://www.metatrader5.com/ru/terminal/help/objects/fibo/fibo_retracement

The indicator draws by default and by standard Fibo levels. There should be a source code of Fibo tools in the terminal that could be changed or copied from it... I can't find it, if you know it, please give me a hint.

Or how to add the following levels in custom indicator:0.0%, 23.6%, 38.2%, 50%, 61.8%, 100%, 161.8%, 261.8%...

Please advise

the example I gave above - it has just the setting of levels. If you're asking, would you mind opening the code and checking?

 
Vladimir Karputov:

I gave you an example above - there's just the setting of levels. If you're asking, bother opening the code and checking.

Thanks, yes there is, it's a bit confusing but I'm trying to understand) thanks

 

What the code would look like in Mql5


extern int    StartHour   = 12;    //Час начала торговли(терминальное время)

int start()
{
if  (Hour()==StartHour)
    {
     OrderSend(Symbol(),OP_BUY,Lot,Ask,0,Ask-StopLoss*Point,Bid+TakeProfit*Point,"советник",MAGIC,expiration,Blue);
    }  
return(0);
}
 
Dmitriywelcome:

How would the code look like in Mql5

   MqlDateTime tm;
   TimeCurrent(tm);
   if(tm.hour==12) {
    ...
   }

Exactly as it would look in mql4


A bit of help

MqlDateTime

The date structure contains eight fields of typeint.

structMqlDateTime
{
intyear;// year
intmon;// month
intday;// day
inthour;// hour; // hour
intmin;// minutes
intsec;// seconds
intday_of_week;// day of week (0-Sunday, 1-Monday, ....,6-saturday)
intday_of_year;// sequence number in a year (January 1 has number 0)
};

Документация по MQL5: Основы языка / Типы данных / Целые типы / Типы char, short, int и long
Документация по MQL5: Основы языка / Типы данных / Целые типы / Типы char, short, int и long
  • www.mql5.com
Целый тип char занимает в памяти 1 байт (8 бит) и позволяет выразить в двоичной системе счисления 2^8 значений=256. Тип char может содержать как положительные, так и отрицательные значения. Диапазон изменения значений составляет от -128 до 127. uchar # Целый тип uchar также занимает в памяти 1 байт, как и тип char, но в отличие от него, uchar...
 
Vladimir Karputov:

I gave you an example above - there's just the setting of levels. If you're asking, please open the code and check.

Nice auto-drawer) with different objects, levels, timeframes, thanks a lot

 
int OnInit()
  {
//---
   ChartSetInteger(ChartID(), CHART_EVENT_OBJECT_CREATE, true);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

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

/***********************OnChartEvent function************************/
void OnChartEvent(const int id,         // идентификатор события
                  const long& lparam,   // параметр события типа long
                  const double& dparam, // параметр события типа double
                  const string& sparam  // параметр события типа string
                 )
  {
   if(id == CHARTEVENT_OBJECT_CREATE)
     {
      //----------------------------------------------------------------------------------------
      double   Level_0= ObjectGetDouble(
                           0,          // идентификатор графика
                           sparam,              // имя объекта
                           OBJPROP_PRICE,           // идентификатор свойства
                           0     // модификатор свойства
                        );


      double   Level_1= ObjectGetDouble(
                           0,          // идентификатор графика
                           sparam,              // имя объекта
                           OBJPROP_PRICE,           // идентификатор свойства
                           1     // модификатор свойства
                        );
      //------------------------------------------------------------------------------------------------------
      if(Level_0 > Level_1)
         ObjectSetInteger(0,sparam,OBJPROP_COLOR,clrDeepSkyBlue);
      else
         ObjectSetInteger(0,sparam,OBJPROP_COLOR,clrYellow);
      //+------------------------------------------------------------------+
      ulong timeCreate = ObjectGetInteger(0, sparam, OBJPROP_CREATETIME); //  получим время создания объекта
      string newName = "fibka"+string(timeCreate); //  сформируем новое имя объекта
      ObjectSetString(0, sparam, OBJPROP_NAME, newName);  //  переименуем объект
     }
  }/******************************************************************/

//+------------------------------------------------------------------+
Alexey Viktorov
:

Maybe I would learn to think logically)))).

I tried everything I could out of what you've told me, I twisted and turned, but all the same colour lines in MT5. In MT4 it re-colours in a normal way, without any delay.

 

how to organise an algorithm in one indicator to take points and transfer them to another buffer.

- To draw the trend lines. (as on the picture)

Snapshot of a point

-----------------------------------------

I tried everything with gut feeling, they are drawn but in strange places.

//---
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
//---
   z=Z_;
   for(i=limit; i>=0; i--)
     {
      if(!CalculatePivot())
         return(0);
      if(rates_total!=prev_calculated && i==0)
         Z_=z;
      //---
      DnArrowiCustom[i]=0.0;
      UpArrowiCustom[i]=0.0;
      CoralDn=((Inpyna && BufferC[i]<BufferC[i+1]) || (Inpdoy && BufferCcop[i]<BufferCcop[i+1]) ||
               (Inptrei && BufferC[i]<BufferCcop[i]) || (Inppatry && BufferCcop[i]<BufferC[i]) ||
               (Inpcinc && close[i]<m_Coral_price) || (Inpshase && close[i]<BufferC[i]) || (Inpshapt && close[i]<m_p_price));
      CoralUp=((Inpyna && BufferC[i]>BufferC[i+1]) || (Inpdoy && BufferCcop[i]>BufferCcop[i+1]) ||
               (Inptrei && BufferC[i]>BufferCcop[i]) || (Inppatry && BufferCcop[i]>BufferC[i]) ||
               (Inpcinc && close[i]>m_Coral_price) || (Inpshase && close[i]>BufferC[i]) || (Inpshapt && close[i]>m_p_price));
      if(CoralDn)
         z = 1;
      if(CoralUp)
         z = 2;
      if(CoralDn && (z==1 || z==0))
        {
         if(((InpFiltryP && close[i]<m_p_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||
            ((InpFiltryC && close[i]<m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||
            ((InpFiltryM && close[i]<m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)))
            if(OldTrend>0)
               UpArrowiCustom[i]=high[i];
         if(i!=0)
            OldTrend=-1;
         //if(FractalUpBuffer[i]==UpArrowiCustom[i])
           // return(rates_total);
        }
      if(CoralUp && (z==2 || z==0))
        {
         if(((InpFiltryP && close[i]>m_p_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||
            ((InpFiltryC && close[i]>m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||
            ((InpFiltryM && close[i]>m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)))
            if(OldTrend<0)
               DnArrowiCustom[i]=low[i];
         if(i!=0)
            OldTrend=+1;
        // if(FractalDownBuffer[i]==DnArrowiCustom[i])
           // return(rates_total);
        }
     }
   m_left_Ctime=time[rates_total-2];
//---
   /*if(prev_calculated==0)
     {
      //---
      for(int u=rates_total-4; u>=10; u--)
        {
         if(FractalUpBuffer[u]!=0.0 && FractalUpBuffer[u]!=EMPTY_VALUE)
           {
            if(upper_left==0.0)
              {
               upper_left=FractalUpBuffer[u];
               upper_left_date=time[u];
              }
            else
               if(upper_right==0.0)
                 {
                  upper_right=FractalUpBuffer[u];
                  upper_right_date=time[u];
                 }
           }
         if(FractalDownBuffer[u]!=0.0 && FractalDownBuffer[u]!=EMPTY_VALUE)
           {
            if(lower_left==0.0)
              {
               lower_left=FractalDownBuffer[u];
               lower_left_date=time[u];
              }
            else
               if(lower_right==0.0)
                 {
                  lower_right=FractalDownBuffer[u];
                  lower_right_date=time[u];
                 }
           }
         if(upper_left!=0.0 && upper_right!=0.0 && lower_left!=0.0 && lower_right!=0.0)
            break;
        }
      if(upper_left==0.0 || upper_right==0.0 || lower_left==0.0 || lower_right==0.0)
         return(rates_total);
      //---
      TrendPointChange(0,m_Upper_line,0,upper_right_date,upper_right);
      TrendPointChange(0,m_Upper_line,1,upper_left_date,upper_left);
      TrendPointChange(0,m_Lower_line,0,lower_right_date,lower_right);
      TrendPointChange(0,m_Lower_line,1,lower_left_date,lower_left);
      //---
      return(rates_total);
     }*/
//---

-----------------------------------------------------------------------------------------------------

I attached the indicator - it works - but these lines cannot be adjusted.

Files:
1.mq5  82 kb