Questions from Beginners MQL5 MT5 MetaTrader 5 - page 465

 
kashi_ann:

What am I doing wrong?

Doesn't this indicator have any input parameters? (I mean the iCustom(...) function)

(I hope you only have a closing parenthesis missing here)

And since you are only copying 2 items, are you copying them into a statically allocated buffer?

 
Dear,

I opened code of indicator for NT7
it contains if ( v>=a && v<b)
I need to add another condition: not equal to 25

is it correct?
if ( v>=a && v<b && v<25 && v>25)
 

Artyom Trishkin
:

1. Can iMaOnArray()
2. Maybe you have looked at the wrong Momentum? Indicators --> Oscillators --> Momentum
3. Your MAs in the subwindow are strange. Where do you get it all? Indicators --> Trending --> Moving Average

Artyom, thanks for the reply, it turns out it's in the menu... I've got the wrong indicators :) I clicked Indicators\Momentum in the "Navigator" window but it is added to a new subwindow every time and it looks messed up.
Can you please suggest what would put less strain on the processor if the procedure is repeated often:
1) Place my (complex) indicator in a subwindow and take values from here
or
2)Read the indicator value by OnTime(), using (MQL4)iCustom.
If I understand correctly, in case 2) the indicator is not drawn in the window, it is calculated on request. However, I don't understand if the indicator's executable code is loaded once or every time it is called ...
P.S. The second indicator is still added to the new subwindow through the menu ... How to add it to an already existing indicator in a subwindow ?

 

Александр:
Уважаемые,

открыл код индикатора к NT7
вижу в нём if ( v>=a && v<b)
а мне надо добавить ещё условие: неравно числу 25

правильно ли будет следующее?
if ( v>=a && v<b && v<25 && v>25)

Never works, because:"v<25 && v>25" is always false.

It should go something like this:

v!=25

 
Yury Kirillov:

Never works, because:"v<25 && v>25" is always false.

It should go something like this:

v!=25

thanks! yes:

if ( v>=a && v<b && (v<25|| v>25)) orif ( v>=a && v<b && v!=25)

 
Александр:
thanks! another forum suggested: if ( ( v>=a && v<b && (v<25|| v>25))

In mine I would write it like this:

{if((v>=a)&&(v<b)&&(v!=25)) 
{
        //разные действия 
}}//if((v>=a)&&(v<b)&&(v!=25)) 

 
 
Oksana Berenko:

Doesn't this indicator have any input parameters? (I mean the iCustom(...) function)

(I hope you missed the closing parenthesis here only)

And since you're only copying 2 items, are you copying them into a statically allocated buffer?

The indicator has a lot of input parameters.

I don't understand where the parenthesis is missing.

I'm afraid I don't understand what a static buffer means. If you don't mind explaining, please.

 
Mike:

Artem, thanks for the reply, it turns out it's in the menu... I got the indicators in the wrong place :) I clicked Indicators\Momentum in the Navigator window but it is added to a new subwindow each time and it looks messed up.
Can you please suggest what would put less strain on the processor if the procedure is repeated often:
1) Place my (complex) indicator in a subwindow and take values from here
or
2)Read the indicator value by OnTime(), using (MQL4)iCustom.
If I understand correctly, in case 2) the indicator is not drawn in the window, it is calculated on request. However, I don't understand if the indicator's executable code is loaded once or every time it is called ...
P.S. The second indicator is still added to the new subwindow through the menu ... How to add it to an already existing indicator in a subwindow ?

When you call an indicator via iCustom(), its buffers are not displayed in the window, but as far as I know (in old versions of MT it definitely was), all graphical objects displayed by the indicator are displayed in the chart window.

To place an indicator in a window of another indicator drag it with the mouse from the Navigator window in the window of the needed indicator.

About less processor time consumption - didn't check, don't know.

 

help me make the conditions, finish the idea, how easy is it to put a mark on the graph according to the condition ?

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
     
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
  //+------------------------------------------------------------------+
void OnTick()
{
        // скорость тиков
        int nTicksSpeed = TicksSpeed();
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int TicksSpeed()
{
        MqlTick oTicks[5];
        ZeroMemory(oTicks);
        
        int nTicksCopied = CopyTicks(_Symbol, oTicks, COPY_TICKS_TRADE, 0, 5);
        
        int nSpeed = 0;

        if(nTicksCopied > 0)
        {
                // скорость роста
                if(oTicks[0].bid > oTicks[1].bid)
                {
                        if(oTicks[4].bid > 0 && oTicks[0].bid > oTicks[1].bid && oTicks[1].bid > oTicks[2].bid && oTicks[2].bid > oTicks[3].bid && oTicks[3].bid > oTicks[4].bid)
                                nSpeed = 4;
                        else if(oTicks[3].bid > 0 && oTicks[0].bid > oTicks[1].bid && oTicks[1].bid > oTicks[2].bid && oTicks[2].bid > oTicks[3].bid)
                                nSpeed = 3;
                        else if(oTicks[2].bid > 0 && oTicks[0].bid > oTicks[1].bid && oTicks[1].bid > oTicks[2].bid)
                                nSpeed = 2;
                                
                        else if(oTicks[1].bid > 0 && oTicks[0].bid > oTicks[1].bid)
                                nSpeed = 1 ;
                        
                }
        
                // скорость снижения
                if(oTicks[0].bid < oTicks[1].bid)
                {
                        if(oTicks[4].bid > 0 && oTicks[0].bid < oTicks[1].bid && oTicks[1].bid < oTicks[2].bid && oTicks[2].bid < oTicks[3].bid && oTicks[3].bid < oTicks[4].bid)
                                nSpeed = -4;
                        else if(oTicks[3].bid > 0 && oTicks[0].bid < oTicks[1].bid && oTicks[1].bid < oTicks[2].bid && oTicks[2].bid < oTicks[3].bid)
                                nSpeed = -3;
                        else if(oTicks[2].bid > 0 && oTicks[0].bid < oTicks[1].bid && oTicks[1].bid < oTicks[2].bid)
                                nSpeed = -2; 
                        else if(oTicks[1].bid > 0 && oTicks[0].bid < oTicks[1].bid)
                                nSpeed = -1 ; 
                }
        }
        
        return(nSpeed);
}

//+------------------------------------------------------------------+

if( nTickSpeed==-1)  отмечаем это место на графике g_Label.Text("-1 ")

if( nTickSpeed==-2)  отмечаем это место на графике g_Label.Text("-2 ")

if (nTickSpeed==-3)  отмечаем это место на графике g_Label.Text("-3 ")

if( nTickSpeed==-4)  отмечаем это место на графике g_Label.Text("-4 ")




if( nTickSpeed==1)  отмечаем это место на графике g_Label.Text("1 ")

if( nTickSpeed==2)  отмечаем это место на графике g_Label.Text("2 ")

if( nTickSpeed==3)  отмечаем это место на графике g_Label.Text("3 ")

if( nTickSpeed==4)  отмечаем это место на графике g_Label.Text("4 ")
 

You could replace the if's at the end with:

   switch(nTickSpeed)
     {
      case -4:
         g_Label.Text("-4");
         break;
      case -3:
         g_Label.Text("-3");
         break;
      case -2:
         g_Label.Text("-2");
         break;
      case -1:
         g_Label.Text("-1");
         break;
      case 1:
         g_Label.Text("1");
         break;
      case 2:
         g_Label.Text("2");
         break;
      case 3:
         g_Label.Text("3");
         break;
      case 4:
         g_Label.Text("4");
         break;
     }
Reason: