Help to upgrade to MetaTrader 5 without loss - page 13

 
mario065:

Hello,

I couldn't do what I wanted.

I have a different mouwing buffer in my head, I have a different pair, than the one I had in my head.

[code]
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   2
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_type2   DRAW_COLOR_LINE
#property indicator_color1  clrBlue
#property indicator_color2  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_style2  STYLE_SOLID

input int period_1 = 20;
input int period_2 = 100;
input ENUM_MA_METHOD ma_method = MODE_SMA;
input ENUM_APPLIED_PRICE applied_price = PRICE_CLOSE;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
int EMHandle1=0;
int EMHandle2=0;
int EMHandle11=0;
int EMHandle22=0;
MqlParam params[];      // Структура за съхранение  параметрите на индикатора
double ma1[],ma2[],ma3[],ma4[];//Временни буфери

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, ExtMapBuffer1, INDICATOR_DATA);
   SetIndexBuffer(1, ExtMapBuffer2, INDICATOR_DATA);
   SetIndexBuffer(2, ma1, INDICATOR_DATA);
   SetIndexBuffer(3, ma2, INDICATOR_DATA);
   SetIndexBuffer(4, ma3, INDICATOR_DATA);
   SetIndexBuffer(5, ma4, INDICATOR_DATA);
  
   PlotIndexSetInteger(0, PLOT_SHIFT, 0);
   PlotIndexSetInteger(1, PLOT_SHIFT, 0);
  
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID);
   PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_SOLID);
//---
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrBlue);
   PlotIndexSetInteger(1,PLOT_LINE_COLOR,clrRed);

   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);
   IndicatorSetString(INDICATOR_SHORTNAME,"2_2_MA");
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,4);  
//---
   ArrayResize(params,4);
   params[0].type         =TYPE_INT;
   params[0].integer_value=period_1;
   // Смещение
   params[1].type         =TYPE_INT;
   params[1].integer_value=0;
   // Метод расчета: простое усреднение
   params[2].type         =TYPE_INT;
   params[2].integer_value=MODE_SMA;
   // Тип цен для рассчета: цены закрытия
   params[3].type         =TYPE_INT;
   params[3].integer_value=PRICE_CLOSE;
  
   EMHandle1 = IndicatorCreate(_Symbol, 0, IND_MA, 4, params);
   ArrayResize(params,4);
   params[0].type         =TYPE_INT;
   params[0].integer_value=period_2;
   params[1].type         =TYPE_INT;
   params[1].integer_value=0;
   params[2].type         =TYPE_INT;
   params[2].integer_value=MODE_SMA;
   params[3].type         =TYPE_INT;
   params[3].integer_value=PRICE_CLOSE;
  
   EMHandle2 = IndicatorCreate(_Symbol, 0, IND_MA, 4, params);
   ArrayResize(params,4);
   params[0].type         =TYPE_INT;
   params[0].integer_value=period_1;
   params[1].type         =TYPE_INT;
   params[1].integer_value=0;
   params[2].type         =TYPE_INT;
   params[2].integer_value=MODE_SMA;
   params[3].type         =TYPE_INT;
   params[3].integer_value=PRICE_CLOSE;
  
   EMHandle11 = IndicatorCreate(_Symbol, 0, IND_MA, 4, params);
   ArrayResize(params,4);
   params[0].type         =TYPE_INT;
   params[0].integer_value=period_2;
   params[1].type         =TYPE_INT;
   params[1].integer_value=0;
   params[2].type         =TYPE_INT;
   params[2].integer_value=MODE_SMA;
   params[3].type         =TYPE_INT;
   params[3].integer_value=PRICE_CLOSE;
  
   EMHandle22 = IndicatorCreate(_Symbol, 0, IND_MA, 4, params);
     
   return(0);
}
int OnCalculate (const int rates_total,    // размер массива price[];
                 const int prev_calculated,// количество доступных баров ;на предыдущем вызове;
                 const int begin,// с какого индекса в массиве  price[] начинаются достоверные данные;
                 const double &price[]) // массив, по которому и будет считаться индикатор;
  {
   int i;
   ArraySetAsSeries(ma1, true);
   ArraySetAsSeries(ma2, true);
   ArraySetAsSeries(ma3, true);
   ArraySetAsSeries(ma4, true);
  
   if(CopyBuffer(EMHandle1, 0, 0, 1, ma1) < 0){Print("CopyBuffer ma1 error =", GetLastError());}
   if(CopyBuffer(EMHandle2, 0, 0, 1, ma2) < 0){Print("CopyBuffer ma2 error =", GetLastError());}
   if(CopyBuffer(EMHandle11, 0, 0, 1, ma3) < 0){Print("CopyBuffer ma3 error =", GetLastError());}
   if(CopyBuffer(EMHandle22, 0, 0, 1, ma4) < 0){Print("CopyBuffer ma4 error =", GetLastError());} 
   int limit;
   //if(prev_calculated<1)
      //limit=period_1;
      limit=prev_calculated-1;
   for( i=0; i<limit; i++)
   ExtMapBuffer1[0]=вычисление;
   ExtMapBuffer2[0]=вычисление;

      Comment(
      "\n=====================",
      "\n ma1[0]     :   ",DoubleToString(ma1[0],5),
      "\n ma2[0]     :   ",DoubleToString(ma2[0],5),
      "\n ma3[0]     :   ",DoubleToString(ma3[0],5),
      "\n ma4[0]     :   ",DoubleToString(ma4[0],5),
      "\n ExtMapBuffer1[0] : ",DoubleToString(ExtMapBuffer1[0],4),
      "\n ExtMapBuffer2[0] : ",DoubleToString(ExtMapBuffer2[0],4)
      );
       return(rates_total);
  }
void OnDeinit(const int reason)
  {
   Comment("");      
  }
[/code] 

When 0 instead of i (for a bar) I see the result, when the bar (current = i) shows that I can not find data for the second pair.

The chart of the pair is open, in the Market Window I do not know where I confuse things.

Two different pairs in one indicator - so where is my error?

I try to put 0 and see the result as a comment, but I have not got a line.

To clarify: I put ma1 and ma2 on one pair and ma3 and ma4 on the other pair.

Thanks.

First you are counting from 0----->prev_calculated-1 and you need from the last bar counted to rates_total

this:

      limit=prev_calculated-1;
   for( i=0; i<limit; i++)
   ExtMapBuffer1[0]=вычисление;

change it to this:

   
   for(int i=prev_calculated-1>=0?prev_calculated-1:0; i<rates_total; i++)
       ExtMapBuffer1[i]=вычисление;

The second thing I don't really understand, do you want to get muwings from different instruments or different timeframes, I couldn't find either of them in the code.

 

Good day, gentlemen!

Who can help me to adapt the following indicators for the MT5 (pre-files).

I will throw you 10 dollars for a beer for the work.

Files:
 
master_kiln:

Good day, gentlemen!

Who can help me to adapt the following indicators for the MT5 (pre-files).

I will throw you 10 dollars for a beer for the work.

https://www.mql5.com/ru/job
MQL5 работа
MQL5 работа
  • www.mql5.com
Заказы на разработку программ для трейдинга
 

Urain,

Thank you for your attention.

I cannot make it draw. If you can, put it here.

I think it is cool to make different pairs and different frames in xpert.

//+------------------------------------------------------------------+
//|2_2_v2.mq5 |
//|Yuriy Tokman |
//| yuriytokman@gmail.com|
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link"yuriytokman@gmail.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 2
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color1 clrBlue
#property indicator_color2 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
//#property indicator_label1 "EURUSD"
//#property indicator_label2 "GBPUSD"

input int period_1 = 13 ;
input int period_2 = 55 ;;
input ENUM_MA_METHOD ma_method = MODE_SMA;
input ENUM_APPLIED_PRICE applied_price = PRICE_CLOSE;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
int EMHandle1;
int EMHandle2;;
int EMHandle11;
int EMHandle22;
double ma1[],ma2[],ma3[],ma4[];//times buffer
double p1 = SymbolInfoDouble("EURUSD",SYMBOL_POINT);
double p2 = SymbolInfoDouble("GBPUSD",SYMBOL_POINT);
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0, ExtMapBuffer1, INDICATOR_DATA);
SetIndexBuffer(1, ExtMapBuffer2, INDICATOR_DATA);
SetIndexBuffer(2, ma1, INDICATOR_DATA);
SetIndexBuffer(3, ma2, INDICATOR_DATA);
SetIndexBuffer(4, ma3, INDICATOR_DATA);
SetIndexBuffer(5, ma4, INDICATOR_DATA);

PlotIndexSetInteger(0, PLOT_SHIFT, 0);
PlotIndexSetInteger(1, PLOT_SHIFT, 0);

PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID);
PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_SOLID);
//---
PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrBlue);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,clrRed);

PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,1);

PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);

//--- name for DataWindow
IndicatorSetString(INDICATOR_SHORTNAME, "2_2_MA");
//---
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,4);

EMHandle1 = iMA("EURUSD", 0, period_1, 0, ma_method, applied_price);
EMHandle2 = iMA("EURUSD", 0, period_2, 0, ma_method, applied_price);
EMHandle11 = iMA("GBPUSD", 0, period_1, 0, ma_method, applied_price);
EMHandle22 = iMA("GBPUSD", 0, period_2, 0, ma_method, applied_price);

ArraySetAsSeries(ExtMapBuffer1,true);
ArraySetAsSeries(ExtMapBuffer2,true);
ArraySetAsSeries(ma1,true);
ArraySetAsSeries(ma2,true);
ArraySetAsSeries(ma3,true);
ArraySetAsSeries(ma4, true);

//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,// size of array price[];
const int prev_calculated,// number of available bars ;on previous call;
const int begin,// which index in price[] array will start valid data;
const double &price[]) // array, on which the indicator will be calculated;
{
if(CopyBuffer(EMHandle1, 0, 0, 1, ma1) < 0){Print("CopyBuffer ma1 error =", GetLastError());}
if(CopyBuffer(EMHandle2, 0, 0, 1, ma2) < 0){Print("CopyBuffer ma2 error =", GetLastError());}
if(CopyBuffer(EMHandle11, 0, 0, 1, ma3) < 0){Print("CopyBuffer ma3 error =", GetLastError());}
if(CopyBuffer(EMHandle22, 0, 0, 1, ma4) < 0){Print("CopyBuffer ma4 error =", GetLastError());}

ExtMapBuffer1[0]=(ma1[0]-ma2[0])/p1;
ExtMapBuffer2[0]=(ma3[0]-ma4[0])/p2;

Comment(
"\n=====================",
"\n ma1[] : ",DoubleToString(ma1[0],5),
"\n ma2[] : ",DoubleToString(ma2[0],5),
"\n ma3[] : ",DoubleToString(ma3[0],5),
"\n ma4[] : ",DoubleToString(ma4[0],5),
"\n ExtMapBuffer1[] : ",DoubleToString(ExtMapBuffer1[0],4),
"\n ExtMapBuffer2[] : ",DoubleToString(ExtMapBuffer2[0],4)
);
//---

//--- return value of prev_calculated for next call
return(rates_total);
}
void OnDeinit(const int reason)
{
Comment(");
}
//+------------------------------------------------------------------+

 

Good day to all.

I have a request to redo this indicator for MT5 because I only use it in trading.

Files:
 

I do not know where to write, but maybe you can help me to solve this question: In MT4 you just copy an EA to the folder experts and run strategy tester, everything looks good and works, but in MT5 I can not understand how to test an EA, I throw in the folder experts, with the extension .I have copied and pasted them somewhere else. Can you tell me how to copy an EA and where to paste it correctly?

 
ZahvatkiN:

I do not know where to write, but maybe you can help me to solve this problem: In MT4 I just copy an EA into the experts folder, put it into Strategy Tester, everything looks good and works, but in MT5 I can not understand how to test an EA, I put it in the experts folder with the extension .I have copied and pasted them somewhere else. Can you tell me how to copy an EA correctly and where to paste it?

You can run both in the tester and in real time, you can only run an EA with the extension ex5 or the compiled version,

If you open an mq5 file in MetaEditor, press F7 and you will be happy. The source code with extension mq5, this is only test information, in order to get the byte-code (executable code) from it, you need to compile it.

 

Urain thanks for the reply, only I know all the basics, I compiled and did everything according to the instructions, even though I knew it, but once again I read it, I don't know what could be wrong, here are 2 skins attached. I downloaded MT5 from this site.

Files:
1__17.jpg  420 kb
2__10.jpg  117 kb
 
ZahvatkiN:

Urain thanks for the reply, only I know all the basics, I compiled and did everything according to the instructions, even though I knew it, but once again I read it, I don't even know what could be wrong, here are 2 skins attached. I downloaded MT5 from this site.

I want to place my copy of grr-al.ex5 in the right folder and reload MT5 after I have made sure that it is in the right folder.

By the way is MT5 the only one on the computer?

 

Urain finally figured it out, the thing is that EAs are copied not to the folder C:\Program Files\MT5\MQL5\Experts but to C:\Users\Dyma\AppData\Roaming\MetaQuotes\Terminal\8B052D0699A0083067EBF3A36123603B\MQL5\Experts, I do not know why this hassle, these damn programmers)))

Reason: