Questions from Beginners MQL5 MT5 MetaTrader 5 - page 960

 
Vitaly Muzichenko:

You should put a flag to check if the value has changed, so you don't have to yankOnInit on every tick

Like this:

Thank you it worked.

As far as I understand, I need to doIndicatorRelease

Because old calculation is still hanging on the chart? At least in the tester.

Then the code is like this?

void OnTick()
  {
   // Ставим новый параметр индикатора и делаем пересчет с новым параметром ???
   static int NewExtInpMA_ma_period;
   if(ExtInpMA_ma_period != NewExtInpMA_ma_period)
    {
     NewExtInpMA_ma_period=ExtInpMA_ma_period;
     IndicatorRelease(handle_MA);
     OnInit();
    }
  }
 
ilvic:

Thank you it's working.

As far as I understand, I will also need to performIndicatorRelease

Because the old calculation is still hanging on the chart? At least in the tester.

Then the code is like this?

And add to the code:

void OnTick()
  {
   // Ставим новый параметр индикатора и делаем пересчет с новым параметром ???
   static int NewExtInpMA_ma_period;
   if(ExtInpMA_ma_period != NewExtInpMA_ma_period)
    {
     NewExtInpMA_ma_period=ExtInpMA_ma_period;
     IndicatorRelease(handle_MA);
     OnInit();
     return;
    }
  }
 

How to make my custom MA be drawn from RSI indicator instead of price?

I receive data of custom MA throughiCustomGet.

I want to makea compound indicator (indicator from indicator).

input int            InpMA_ma_period      = 25;        // Параметры МА 
input int            InpMA_ma_shift       = 0;         // MA PRICE_HIGH and PRICE_LOW: horizontal shift 
input ENUM_MA_METHOD InpMA_ma_method      = MODE_SMA;  // MA PRICE_HIGH: smoothing type 

int            handle_MA; 

int OnInit()
  {
    handle_MA=iCustom(m_symbol.Name(),Period(),"MA",InpMA_ma_period,InpMA_ma_shift,InpMA_ma_method,PRICE_CLOSE);
  }

void OnTick()
  {
  double MA_price=0.0;
  MA_price=iCustomGet(handle_MA,0,0);
  Print("MA_price",MA_price);
  }

//Получаем данные кастом МА
double iCustomGet(int handle,const int buffer,const int index)
  {
   double Custom[1];
//--- reset error code 
   ResetLastError();
//--- fill a part of the iCustom array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle,buffer,index,1,Custom)<0)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iCustom indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(0.0);
     }
   return(Custom[0]);
  }

Examples for mt4

https://www.mql5.com/ru/forum/110186

https://www.mql5.com/ru/code/22638

Как в коде применить постороение одного индикатора по другому индикатору
Как в коде применить постороение одного индикатора по другому индикатору
  • 2008.08.03
  • www.mql5.com
Хочу написать советника по данной стратегии: http://unfx.ru/strategies_to_trade/strategies_139...
 
ilvic:

How to make my custom MA be drawn from RSI indicator instead of price?

I receive data of custom MA throughiCustomGet.

I want to makea compound indicator (indicator from indicator).

Examples for mt4

https://www.mql5.com/ru/forum/110186

https://www.mql5.com/ru/code/22638

How about this:iMA

int  iMA( 
   string               symbol,            // имя символа 
   ENUM_TIMEFRAMES      period,            // период 
   int                  ma_period,         // период усреднения 
   int                  ma_shift,          // смещение индикатора по горизонтали 
   ENUM_MA_METHOD       ma_method,         // тип сглаживания 
   ENUM_APPLIED_PRICE   applied_price      // тип цены или handle 
   );
 
Vladimir Karputov:

How about this:iMA

Thank you, just what I need

 

To this:

int1 = NormalizeDouble(dou1,0)

The compiler responds: possible loss of data due to type conversion

Question: What's the right way to do this? (so the compiler doesn't swear)

 
User_mt5:

To this:

The compiler responds: possible loss of data due to type conversion

Question: what's the right way to do it? (so that the compiler won't swear)

The compiler doesn't swear but warns you that you are trying to put double into int.


 
User_mt5:

To this:

The compiler responds: possible loss of data due to type conversion

Question: What's the right way to do this? (so the compiler doesn't swear)

int1 = (int)NormalizeDouble(dou1,0)
 
Artyom Trishkin:

The compiler does not swear, but warns that you are trying to put double into int.


I was just perplexed by almost the same thing.

deltaH4[i] = NormalizeDouble(bufOpen[i]-bufClose[i], (int)SymbolInfoInteger(m_symbol, SYMBOL_DIGITS));

That's because of this int ... As I remember SymbolInfoInteger used to return int type and now it suddenly returns long

 
Alexey Viktorov:

I've just been perplexed about pretty much the same thing.

that's because of this int ... As I remember SymbolInfoInteger used to return int type and now it suddenly returns long

It always returns long - look at SymbolInfoInteger() property identifiers

Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Для получения текущей рыночной информации служат функции SymbolInfoInteger(), SymbolInfoDouble() и SymbolInfoString(). В качестве второго параметра этих функций допустимо передавать один из идентификаторов из перечислений ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE и ENUM_SYMBOL_INFO_STRING соответственно. Некоторые символы (как...
Reason: