Questions from Beginners MQL5 MT5 MetaTrader 5 - page 779

 
Alexey Volchanskiy:

.ex5 is of no use to anyone, if you want help, publish the source code.


Fuck, I thought it was the source code :-) i'm also looking at the other icons.... I wondered which one was the source...... this one :-)

Turns out it's not....

Files:
ChekParam.mq5  11 kb
 

The point is that the pulse on the minus third bar from the end is zero and is drawn as zero. But it is not zero in the buffer.

I do not know what it was, but I solved the problem by pasting all the code PULSE in a new indicator, bypassing icustom.

I had no error at minus second bar. I didn't change anything else in the code, so it's really a metaquote bug.

 
LookingFor:

The point is that the pulse on the minus third bar from the end is zero and is drawn as zero. But it is not zero in the buffer.

I do not know what it was, but I solved the problem by pasting all the code PULSE in a new indicator, bypassing icustom.

I had no error at minus second bar. I did not change anything else in the code, so it's really a metaquote bug.


without the code, the bug can only be yours. unfortunately, by asking for help, YOU did not give the material...

 
Can anyone help??? What is the error, why is the indicator not displayed correctly?
Files:
ChekParam.mq5  11 kb
 
Vladislav Andruschenko:

Unfortunately, when you asked for help, you did not give the material...

Vladislav, in the name of justice, the desire to understand what it is all about and out of respect for you, I give you the code.


//+------------------------------------------------------------------+
//|                                                   PULS_SWING.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
//--- plot Pulse_Swing
#property  indicator_label1  "Pulse_Swing"
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  1
//--- input parameters
input double   points=0.005;
input double   begin_price_level=1.0;
//--- indicator buffers
double         Pulse_Swing [], pulse [] , trend [] , delta [];
int PULSE_Handle ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Pulse_Swing,INDICATOR_DATA);
   SetIndexBuffer(1,pulse,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,trend,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,delta,INDICATOR_CALCULATIONS);
   IndicatorSetInteger(INDICATOR_DIGITS,0);
   ResetLastError(); 
   PULSE_Handle = iCustom(NULL,0,"PULSE",
                          points,          // Points
                          begin_price_level          // begin_price_level
                          );
   Print("PULSE_Handle",PULSE_Handle,"  error = ",GetLastError()); 
//---
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID);
   //ArrayFree (pulse);ArrayFree (delta);ArrayFree (Pulse_Swing);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   int  bar, start  ;
   if (prev_calculated==0)
   {pulse [0] = pulse [1] =0; start =begin+2 ;}
   else {start = prev_calculated ;}
   //Print(IntegerToString(bar));
   for (bar= start ;bar<rates_total;bar ++)
   {CopyBuffer(PULSE_Handle,0,bar,1,pulse);
   //Print(IntegerToString(pulse[bar]));
   if ((pulse [bar-1]- pulse [bar -2])>0) trend[bar-1] = 1 ; // 
   else
   if ((pulse [bar-1] - pulse [bar -2])<0) trend[bar-1] = -1 ; //
   else
   if (pulse [bar-1] == pulse [bar -2])  {trend[bar-1] = trend[bar-2] ;} // 
   else 
   continue ;
   delta[bar] = pulse[bar]- pulse[bar-1];
   if (trend [bar-1]== 1 && pulse [bar] != pulse [bar-1])
   Pulse_Swing [bar] = Pulse_Swing [bar-1] + delta[bar];
   else
   if (trend [bar-1]== -1 && pulse [bar] != pulse [bar-1])
   Pulse_Swing [bar] = Pulse_Swing [bar-1] - delta[bar];
   else
   if (delta [bar]==0 )Pulse_Swing [bar] = Pulse_Swing [bar-1] ;
   }
   //Print(IntegerToString(delta[rates_total-1]));
   Print(IntegerToString(delta[rates_total-2]));
   //Print(IntegerToString(pulse[rates_total-1]));
   Print(IntegerToString(pulse[rates_total-3]));
   Print(IntegerToString(pulse[rates_total-2]));
   Print(IntegerToString(pulse[rates_total-1]));
  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 

I'm having trouble reading the result of the trade operation. I wrote it like this:

MqlTradeRequest request={0};
MqlTradeResult result={0};
//--- установка параметров операции
....
//--- отправка запроса
if ( !OrderSend(request,result) )
  PrintFormat("OrderSend error %d",GetLastError()); // если отправить запрос не удалось
else // Я хочу получить парамеры резултата
{ Sleep(9999); // Жду получения резултата
  double ClosePrice=result.price;
}

If you remove Sleep : I always get ClosePrice=0.0 . Even if I wait 10 seconds (I don't want to wait longer), I almost always get the result, but sometimes I don't.

How do I get results?

The description of OrderSend() says :

Note

A trade request passes through several validation stages on the trade server. First of all, all required fields of the requestparameter are checked for correctness and, if there are no errors, the server accepts the order for further processing. If the order is successfully accepted by the trading server, the OrderSend() function returns true.

That is, when I get true from OrderSend(), I don't get the MqlResult parameter, if I understand correctly.

When will they come to me ?

 
Ivan Ivanov:

I can't read the result of my trade.

Forum on trading, automated trading systems and strategy testing

Error 131 occurs when modifying an order

fxsaber, 2017.09.12 19:47

All you have to do is write the name of the trading server and the symbol and the problem will be solved in no time, because everyone can try it themselves.

In the meantime, one gets the feeling that the task is not to find a solution, but to answer yes/no.

 

Gentlemen programmers,

Here's a question: If the Strategy Tester in MT5 shows good results only at open prices, will the robot open trades only at open prices with the same result?

 
Dzyga:

Gentlemen programmers,

Question: If the Strategy Tester in MT5 shows good results only at open prices, will the robot open trades only at open prices with the same result?


It is easy to check: in the EA you open trades only at opening price (i.e., at bar birth) and in the Strategy Tester you check it in tick generation mode "All ticks".

 

Colleagues, please help me

I don't understand what's wrong with the loop, data from the Handle is not going into the psa1 array

if (prev_calculated == 0 ){i=bars =start=1;}
  else {start = prev_calculated ;}
  for ( bars=start ; bars<rates_total ; bars ++)
  {CopyBuffer(pulse_Handle,0,start,1,pca1);
  
  if (pca1[bars]!=pca1[bars-1]) {pca2[i]=pca1[bars]; i++;
  string s="";s=IntegerToString(pca1[bars])+"  ";Print(s); continue;}
  else continue ;}
Reason: