Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 96

 
Vadim Podoprigora:

Hello!

Please help me write an EA.

The essence of the Expert Advisor: opens 4 orders of 1 lot.

2 to sell: usdchf; eurusd;

2 to buy: gbpusd; usdjpy;

Upon reaching a total profit of 5 pips, close all trades. And start again.

4 lots in total?

What if there is no profit?

 
Vadim Podoprigora:

Hello!

Please help me write an EA.

The essence of the Expert Advisor: opens 4 orders of 1 lot.

2 to sell: usdchf; eurusd;

2 to buy: gbpusd; usdjpy;

Upon reaching a total profit of 5 pips, close all trades. And start all over again.

There is no need to duplicate your question in different threads.

Please contact Freelance.

 
Andrey Sokolov:

Greetings.

Can you tell me how to write the condition so that the action will be performed at the opening of a new candle on the current chart?

https://www.mql5.com/ru/articles/159
Обработчик события "новый бар"
Обработчик события "новый бар"
  • 2010.10.04
  • Konstantin Gruzdev
  • www.mql5.com
Язык программирования MQL5 позволяет решать задачи на совершенно новом уровне. Даже те задачи, которые уже вроде имеют решения, благодаря объектно-ориентированному программированию могут подняться на качественно новый уровень. В данной статье специально взят простой пример проверки появления нового бара на графике, который был преобразован в достаточно мощный и универсальный инструмент. Какой? Читайте в статье.
 

Hello! Help me understand arrays!

I need to fill an array with the MASD indicator. As I understand it, there is data: bar index,MODE_MAIN value,MODE_SIGNALvalue, i.e. the array should be of three-dimensional type ( a [] [] []), or what? If you can give an example.

 

Sergey, have you ever used this code yourself?

The article is generally good, but it's

datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

very dangerous. To make it work, you have to, as recommended by the drummer, "jerk" the history periodically. I did not specify what place.

In general, after much suffering, I've come to the conclusion that it's better to use CopyRates() function

Messages about possible errors are filled in by each of us if we want to.

bool newBar()
{
static datetime timeLastBar;
  MqlRates mqlRates[];
   int s = 0;
    do
     {
      s++;
     }
    while(CopyRates(_Symbol, PERIOD_CURRENT, 0, 1, mqlRates) < 0 && s < 7);
   bool ret = timeLastBar != mqlRates[0].time;
   if(ret)
    timeLastBar = mqlRates[0].time;
   return(ret);
}/*******************************************************************/
 
Alexey Viktorov:

Sergey, have you ever used this code yourself?

The article is generally good, but it's

datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

very dangerous. To make it work, you have to, as the drummer recommended, "jerk" the history periodically. Which place was not specified.

Alexey, tell me, when did you ran into errors using it? Have you ever had one?

I just use this method myself, and have not run into trouble. Well, maybe I still have to?

I would like some explanations - so to say... :)

Where did the drummer say that?

 
Artyom Trishkin:

Alexei, tell me, when have you ever run into errors with this use? Have you ever?

Because I use this method myself, and have not yet run into any trouble. Well, maybe I still have to.

I would like some explanations - so to say... :)

Where did drubashka say such a thing?

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

There's eight pages of bickering. And not only drubashka, but Slawa says that

Slawa:

Where do you see inadequate behavior of this function? Have you read the documentation carefully?

Returns information about state of historical data. Doesn't update the information, doesn't initiate data swapping. Just returns what is there at the moment.

 
Artyom Trishkin:

Alexei, tell me, when have you ever run into errors with this use? Have you ever?

Because I use this method myself, and have not yet run into any trouble. Well, maybe I still have to.

I would like some explanations - so to say... :)

Where did the drummer say that?

And here's the twitching.

Vladimir Karputov:
It didn't work on one symbol in one terminal (on M15 timeframe) - I'm 99% sure the problem is that using another timeframe I need to "jerk" the history all the time. I think it's better to do it through CopyTime().
The problem is not solved by the cat by the causal place.
 
Artyom Trishkin:

Alexei, tell me, when have you ever run into errors with this use? Have you ever?

As far as I remember, it may not return what is expected if the TF is larger than the current one.
 
Hi, I have a question about MT5.

For example, in the MT5 terminal there are some Expert Advisors (MACD Sample and Moving Averages), but if I try to put a specific TF in their code, for example PERIOD_H4, instead of "_Period", then in the test on the open prices of higher TF, the following indicator loading error occurs: cannot load indicator 'MACD' [4805] and as a result: tester stopped because OnInit failed. What are your opinions? Maybe I'm doing something wrong? Is it possible to code the Expert Advisor so that it is tested for the open prices of any TF?

I have tried to use the indicator as a custom one, the error is the same.

Thank you in advance for your feedback.

int OnInit(void)
{
//--- prepare trade class to control positions if hedging mode is active
ExtHedging=((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE)==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
ExtTrade.SetExpertMagicNumber(MA_MAGIC);
ExtTrade.SetMarginMode();
//--- Moving Average indicator
ExtHandle=iMA(_Symbol,PERIOD_H4,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE);
if(ExtHandle==INVALID_HANDLE)
{
printf("Error creating MA indicator");
return(INIT_FAILED);
}
//--- ok
return(INIT_SUCCEED);
}

Reason: