[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 309

 

Please help!

Only two MAH lines are displayed, although the code is equivalent for all four lines.What's the problem?

#property indicator_separate_window // Indicator is drawn in a separate window
#property indicator_buffers 4 // Number of buffers
#property indicator_color1 Blue // Color of the first line
#property indicator_color2 Red // Color of the second line
#property indicator_color3 Olive
#property indicator_color4 Teal


double Buf_ROC_MA40[],Buf_ROC_MA20[],Buf_MA40[],Buf_MA20[]; // array declaration (for indicator buffers)
//--------------------------------------------------------------------
int init() // Special function init()
{
SetIndexBuffer(0,Buf_MA40); // Assignment of an array to the buffer
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);// Line style
SetIndexBuffer(1,Buf_MA20); // Assigning an array to the buffer
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);//Line style
SetIndexBuffer(3,Buf_ROC_MA40); // Assigning an array to the buffer
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);//Line style
SetIndexBuffer(4,Buf_ROC_MA40); // Assigning an array to the buffer
SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,2);// Line style
return; // Exit special init() function
}
//--------------------------------------------------------------------
int start() // Special function start()
{
int i, // bar index
History=3000,
counted_bars; // number of calculated bars
double ma20,ma40,MA40[],MA20[],MA40_s[],MA20_s[],ma40_s,ma20_s,ROC_MA40[],ROC_MA20[];
//--------------------------------------------------------------------
// Counted_bars=IndicatorCounted(); // Number of bars counted
i=Bars;//Counted_bars-1; // Index of the first one not counted
while(i>=0) //Cycle through the uncounted bars
{
ma20=iMA("EURUSD",PERIOD_M1,20,0,MODE_SMA,PRICE_CLOSE,i);
ma20_s=iMA("EURUSD",PERIOD_M1,20,0,MODE_SMA,PRICE_CLOSE,i+20);
ma40=iMA("EURUSD",PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,i);
ma40_s=iMA("EURUSD",PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,i+40);
Alert("ma20=",ma20, " ma20_s=",ma20_s, " ma40_s=",ma40_s, " ma40=",ma40);
MA40_s[i]=ma40_s;
MA40[i]=ma40;
MA20[i]=ma20;
MA20_s[i]=ma20_s;
Buf_MA40[i]=ma40;
Buf_MA20[i]=ma20;
ROC_MA40[i]=MA40[i]-MA40_s[i];
Buf_ROC_MA40[i]=ROC_MA40[i];
ROC_MA20[i]=MA20[i]-MA20_s[i];
Buf_ROC_MA20[i]=ROC_MA20[i];
i--;
// Calculation of the next bar index
}
//--------------------------------------------------------------------
return; // Exit special function start()
}

 

1.recommend, please, a debugger (preferably with step-by-step debugging so you can see intermediate values of variables).

2.How can I display debugging data and where (in which window), because it's inconvenient to use alerts.

3) How can I update the MQL version?

 

Please advise!

How can I make my Expert Advisor trade only on the European session?

 
VNG писал(а) >>

Please help!

Only two MAs lines are output, although the code is equivalent for all four lines.What is the problem?

int init() // Специальная функция init()
{
SetIndexBuffer(0, Buf_MA40); // Назначение массива буферу
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Стиль линии
SetIndexBuffer(1, Buf_MA20); // Назначение массива буферу
SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,2);// Стиль линии
SetIndexBuffer(2, Buf_ROC_MA40); // Назначение массива буферу
SetIndexStyle (2,DRAW_LINE,STYLE_SOLID,2);// Стиль линии
SetIndexBuffer(3, Buf_ROC_MA40); // Назначение массива буферу
SetIndexStyle (3,DRAW_LINE,STYLE_SOLID,2);// Стиль линии
return; // Выход из спец. ф-ии init()
}

I found one mistake. After buffer 1 went immediately buffer 3. Buffer 2 was skipped.

You just shouldn't have output the mashes and the difference in one window. They have more than one order of magnitude difference.

 
KoDi писал(а) >>

Please advise!

How do I make my EA trade only on the European session?

Just put start at the beginning of the module

if(Hour()<7 || Hour()>15)return(0);

 

Please look at the code again. I've removed the MAs as the newly received values have a completely different scale.

Still nothing is displayed.

#property indicator_separate_window // Indicator is drawn in a separate window
#property indicator_buffers 2 // Number of buffers
#property indicator_color1 Blue // Color of the first line
#property indicator_color2 Red //color of the second line
//#property indicator_color3 Olive
//#property indicator_color4 Teal


double Buf_ROC_MA40[],Buf_ROC_MA20[],Buf_MA40[],Buf_MA20[]; // Declaration of arrays (for indicator buffers)
//--------------------------------------------------------------------
int init() // Special function init()
{
//SetIndexBuffer(0,Buf_MA40); // Assignment of an array to the buffer
//SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);// Line style
//SetIndexBuffer(1,Buf_MA20); // Assign array to buffer
//SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);//Line style
SetIndexBuffer(0,Buf_ROC_MA40); // Assigning an array to the buffer
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);//Line style
SetIndexBuffer(1,Buf_ROC_MA20); // Assigning an array to the buffer
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);//Line style
return; // Exit special init() function
}
//--------------------------------------------------------------------
int start() // Special function start()
{
int i, // bar index
History=3000,
counted_bars; // number of calculated bars
double ma20,ma40,MA40[],MA20[],MA40_s[],MA20_s[],ma40_s,ma20_s,ROC_MA40[],ROC_MA20[];
//--------------------------------------------------------------------
// Counted_bars=IndicatorCounted(); // Number of bars counted
i=Bars;//Counted_bars-1; // Index of the first one not counted
while(i>=0) //Cycle through the uncounted bars
{
ma20=iMA("EURUSD",PERIOD_M1,20,0,MODE_SMA,PRICE_CLOSE,i);
ma20_s=iMA("EURUSD",PERIOD_M1,20,0,MODE_SMA,PRICE_CLOSE,i+20);
ma40=iMA("EURUSD",PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,i);
ma40_s=iMA("EURUSD",PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,i+40);
MA40_s[i]=ma40_s;
MA40[i]=ma40;
MA20[i]=ma20;
MA20_s[i]=ma20_s;
Buf_MA40[i]=ma40;
Buf_MA20[i]=ma20;
ROC_MA40[i]=MA40[i]-MA40_s[i];
Buf_ROC_MA40[i]=ROC_MA40[i];
ROC_MA20[i]=MA20[i]-MA20_s[i];
Buf_ROC_MA20[i]=ROC_MA20[i];
i--;
// Calculation of the next bar index
}
//--------------------------------------------------------------------
return; // Exit special function start()
}

 
VNG писал(а) >>

Please look at the code again. I've removed the MAs as the newly received values have a completely different scale.

Still nothing is displayed.

#property indicator_separate_window // Indicator is drawn in a separate window
#property indicator_buffers 2 // Number of buffers
#property indicator_color1 Blue // Color of the first line
#property indicator_color2 Red //color of the second line
//#property indicator_color3 Olive
//#property indicator_color4 Teal


double Buf_ROC_MA40[],Buf_ROC_MA20[],Buf_MA40[],Buf_MA20[]; // Declaration of arrays (for indicator buffers)
//--------------------------------------------------------------------
int init() // Special function init()
{
//SetIndexBuffer(0,Buf_MA40); // Assignment of an array to the buffer
//SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);// Line style
//SetIndexBuffer(1,Buf_MA20); // Assign array to buffer
//SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);//Line style
SetIndexBuffer(0,Buf_ROC_MA40); // Assigning an array to the buffer
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);//Line style
SetIndexBuffer(1,Buf_ROC_MA20); // Assigning an array to the buffer
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);//Line style
return; // Exit special init() function
}
//--------------------------------------------------------------------
int start() // Special function start()
{
int i, // bar index
History=3000,
counted_bars; // number of calculated bars
double ma20,ma40,MA40[],MA20[],MA40_s[],MA20_s[],ma40_s,ma20_s,ROC_MA40[],ROC_MA20[];
//--------------------------------------------------------------------
// Counted_bars=IndicatorCounted(); // Number of bars counted
i=Bars;//Counted_bars-1; // Index of the first one not counted
while(i>=0) //Cycle through the uncounted bars
{
ma20=iMA("EURUSD",PERIOD_M1,20,0,MODE_SMA,PRICE_CLOSE,i);
ma20_s=iMA("EURUSD",PERIOD_M1,20,0,MODE_SMA,PRICE_CLOSE,i+20);
ma40=iMA("EURUSD",PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,i);
ma40_s=iMA("EURUSD",PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,i+40);
MA40_s[i]=ma40_s;
MA40[i]=ma40;
MA20[i]=ma20;
MA20_s[i]=ma20_s;
Buf_MA40[i]=ma40;
Buf_MA20[i]=ma20;
ROC_MA40[i]=MA40[i]-MA40_s[i];
Buf_ROC_MA40[i]=ROC_MA40[i];
ROC_MA20[i]=MA20[i]-MA20_s[i];
Buf_ROC_MA20[i]=ROC_MA20[i];
i--;
// Calculation of the next bar index
}
//--------------------------------------------------------------------
return; // Exit special function start()
}

There are too many errors.

Mainly error in work with arrays.

Files:
proba.mq4  2 kb
 

Help me solve this problem - there is a buy/sell signal, EA opens a deal, sets a profit and a stop. And if the deal is closed on stop on the same candle, then the advisor opens the deal again, and I need it not to open, i.e. on one signal one deal was opened.

How to do it?

 
KoDi >> :

How to do it?

The closing time of the last order must be less than the opening time of the current bar.

If this is not the case, do not open the trade.

 
TheXpert >> :

The closing time of the last order must be less than the opening time of the current bar.

If it does not, we do not open a deal.

>> I'm confused.

Well, how will he open the FIRST trade if the condition is to write that he does not enter until there is at least one trade?

Reason: