Questions from Beginners MQL5 MT5 MetaTrader 5 - page 838

 

In mql4 I used iCustom to make indicators that use someone else's ready-made indicators, even though I know nothing about programming... I have had enough of intuition. I am using mql5 but nothing works, no matter how hard I try to understand it. Please help me, please.

I have this indicator in ex5. I put it in my Downloads folder. I want to take both of its lines and draw it on the chart in other periods, i.e. make it multitime frame with iCustom.

Since I cannot write an indicator from scratch, I have taken the code of a simple Bears Power indicator. I haven't changed anything there, except for changing indicator_chart_window and DRAW_LINE and the line, which, to my mind, should take out the data of the first buffer with default parameters of the current TF:

ExtBearsBuffer[i]=iCustom(NULL,0,"Downloads\\RSI Analytics");

Everything compiles, nothing gets drawn. What else does it need? :(

#property copyright   "2009, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Bears Power"
//--- indicator settings
#property indicator_chart_window                      //---------------------------------
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_type1   DRAW_LINE                 //---------------------------------------
#property indicator_color1  Silver
#property indicator_width1  2
//--- input parameters
input int InpBearsPeriod=13; // Period
//--- indicator buffers
double    ExtBearsBuffer[];
double    ExtTempBuffer[];
//--- handle of EMA 
int       ExtEmaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtBearsBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtTempBuffer,INDICATOR_CALCULATIONS);
//---
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpBearsPeriod-1);
//--- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"Bears("+(string)InpBearsPeriod+")");
//--- get MA handle
   ExtEmaHandle=iMA(NULL,0,InpBearsPeriod,0,MODE_EMA,PRICE_CLOSE);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Average True Range                                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &Time[],
                const double &Open[],
                const double &High[],
                const double &Low[],
                const double &Close[],
                const long &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
   int i,limit;
//--- check for bars count
   if(rates_total<InpBearsPeriod)
      return(0);// not enough bars for calculation   
//--- not all data may be calculated
   int calculated=BarsCalculated(ExtEmaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtEmaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
//--- we can copy not all data
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
//---- get ma buffers
   if(IsStopped()) return(0); //Checking for stop flag
   if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)
     {
      Print("getting ExtEmaHandle is failed! Error",GetLastError());
      return(0);
     }
//--- first calculation or number of bars was changed
   if(prev_calculated<InpBearsPeriod)
      limit=InpBearsPeriod;
   else limit=prev_calculated-1;
//--- the main loop of calculations
   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      ExtBearsBuffer[i]=iCustom(NULL,0,"Downloads\\RSI Analytics"); \\--------------------------------------------
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Технический индикатор RSI ANALYTICS
Технический индикатор RSI ANALYTICS
  • reviews: 5
  • 2013.11.01
  • STRAT ANALYTICS
  • www.mql5.com
Зачем нам RSI в отдельном окне, если его можно построить в основном окне графика, что гораздо более понятно? RSI ANALYTICS - это индикатор, следящий за рынком, созданный на основе той же идеи, что и традиционный RSI (индекс относительной силы). При этом он строится не в отдельном подокне, а в том же окне, что и график цены финансового...
 
Nilog:

In mql4 I used iCustom to make indicators that use someone else's ready-made indicators, even though I know nothing about programming... I have had enough of intuition. I am using mql5 but nothing works, no matter how hard I try to understand it. I want to ask you for help.

I have this indicator in ex5. I put it in my Downloads folder. I want to take both its lines and draw it on the chart in other periods, i.e. make it multitime frame with iCustom.

Since I cannot write an indicator from scratch, I have taken the code of a simple Bears Power indicator. I haven't changed anything there, except for changing indicator_chart_window and DRAW_LINE and the line, which, to my mind, should take out the data of the first buffer with default parameters of the current TF:

Everything compiles, nothing gets drawn. What else does it need? :(

In mql5 the work with custom and standard indicators is organized differently than in mql4. If in mql4 you can get only one indicator value through iCustom, in mql5 you can get indicator values for the whole depth of history in the array. The second major difference is the direction of indexing in the indicator buffers.

It's tedious to look through all the code and check it against the original, so I'll only point out the main ones:

The file must be located in the Indicators folder or in a subfolder located in the same Indicators.

Here is the line to get the MA indicator handle

ExtEmaHandle=iMA(NULL,0,InpBearsPeriod,0,MODE_EMA,PRICE_CLOSE);

and this is the string to get the value of MA indicator

if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)

in this case to an additional buffer or array.

It turns out that to get data of the custom indicator

ExtBearsHandle=iCustom(NULL,0,"RSI Analytics");
CopyBuffer(ExtBearsHandle,0,0,to_copy,ExtTempBuffer)

And then you can process the indicator values from this additional buffer in some way, or you can put them into the indicator buffer without forgetting about the direction of indexing.

 
Alexey Viktorov:


Thank you! I wrote something as I understood it, and now only one error pops up when compiling. On the line

CopyBuffer(ExtBearsHandle,0,0,to_copy,ExtTempBuffer);

errorto_copy - undeclared identifier.

In which section and how do I declare it?

 
Nilog:

Thank you! I wrote something as I understood it, and now only one error pops up when compiling. On the line

errorto_copy - undeclared identifier.

In which section and how do I declare it?

You need to compare my hints with your code and with the source code you already fixed. This variable is declared in those codes. And in addition to my remarks, you should try to understand the logic of building indicators in general, and not just change a piece of shit for a piece of shit.

 
In MetaTrader 5, can one EA work differently on a currency than, for example, on the RTS Index?
 
lil_lil:
In MetaTrader 5, can the performance of one EA on a currency pair be radically different from the performance, for example, on the RTS Index?

The councillor will work the way it is written. And not otherwise.

As for the nuances that must be considered: RTS is an exchange, hence the NETTING type of accounting positions. If the EA is not originally designed to work on the netting, the result is unpredictable.

 
Vladimir Karputov:

The councillor will work the way it is written. And not otherwise.

As for the nuances that must be considered: RTS is an exchange, hence the NETTING type of accounting positions. If the EA is not originally designed to work on netting, the result is unpredictable.

If your EA is not intendedto work on netting, the result is unpredictable.

There are no multi-directional positions in the strategy.

 
lil_lil:

Thank you, how do you know for sure from the code if it is designedto work on netting or not.

There are no oppositely directed positions in the strategy.

And, if so (always ONE position in work), then there is no difference - whether netting or hedging.

 
Vladimir Karputov:

If this is the case (there is always ONE position in operation), it makes no difference whether it is netting or hedging.

On a reverse signal in currencies (Forex) positions are closed, but not on the exchange. Where to look, what to look for?

 
lil_lil:

On a reverse signal on currencies, positions are closed, but not on the exchange. Where to look, what to look for?

To look for the place where the command to close the position comes from.