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

 

Hello! There is a question in the code. This event appears on every new bar of the working TF. TF - should it be like this or is there an error in the code?

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   ResetLastError();   
   datetime Arr[];
   if(CopyTime(NULL,PERIOD_M5,10,1,Arr)<=0) 
   {
      int error=GetLastError();
      Print("Ошибка 4401 возникает на новом баре раб.ТФ, который должен быть ниже М5 в данном случае ",error);
      Print("Почему запрошенная история не найдена ведь я обращаюсь всего лишь к 10-му бару старшего ТФ М5");
      return(0);
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
novichok2018:

There is also Igor Kim's functionbool ExistPositions(), which returns the flag of position existence, which is a bit complicated for me to adapt to my specific conditions. But I don't think it will be tested in the story either.

If no one has a code, actually tested in the real world, to show me, I will try it scientifically. Thank you.

My knowledge is lacking again! A simple substitution in iOpen(NULL,0,0) for EURUSD produces errors undeclared identifier and implicit conversion from 'number' to 'string'. Same when changing Symbol() inOrderSend(Symbol(),OP_BUY,LOT,Ask,slippage,0,TP,"",magic,0,Blue); How do I fix it?

 
novichok2018:

Again my knowledge is lacking! Just replacing NULL in iOpen(NULL,0,0) with EURUSD gives errors undeclared identifier and implicit conversion from 'number' to 'string'. Same when changing Symbol() in OrderSend(Symbol(),OP_BUY,LOT,Ask,slippage,0,TP,"",magic,0,Blue); How do I fix it?

Didn't you forget to put inverted commas?

 
novichok2018:

Yes, that is how I imagined it, but I cannot check if it works on the history, because the opening of a position on the euro should take place by the condition for the pound and is not reflected in the code for the euro, while the history is displayed on the euro. Hence the uncertainty in the correctness of the decision.

Then I will have to learn MQL5 and test the multicurrency variant.

 
Alexey Viktorov:

Then I'll have to learn MQL5 and test the multicurrency variant.

Oh no, thank you! I'm not aiming to study MKL4 or MKL5 thoroughly. My goal is to write simple Expert Advisors that are profitable in 95% of positions opened, and to avoid drawing the whole balance before I decide to close a position with a loss. I have several such Expert Advisors that work on demo accounts, but every time new ideas appear and I want to test them right away. I stick to the opinion that the simpler the code, the better, I do not want to delve into the language. Not yet anyway! A thorough study of the language is justified only with the purpose of earning money by writing experts to order, IMHO.

Thanks for the quotes. Haven't tried it yet, a bit later.

 
novichok2018:

....... My goal is to write simple Expert Advisors for myself, which are profitable in 95% of open positions, and that a hanging minus does not drain my entire balance until I decide to close a position at a loss. .....

You have described the dream of 95% of traders around the world. But you don't even want to bother with the spelling and syntax of the language. Enviable self-confidence, I'd like that. IMHO of course.

 
novichok2018:

Oh no, thank you! I'm not aiming to study MKL4 or MKL5 thoroughly. My goal is to write simple Expert Advisors that are profitable in 95% of positions opened, and to avoid drawing the whole balance before I decide to close a position with a loss. I have several such Expert Advisors that work on demo accounts, but every time new ideas appear and I want to test them right away. I stick to the opinion that the simpler the code, the better, I do not want to delve into the language. Not yet anyway! A thorough study of the language is justified only with the purpose of earning money by writing customized experts, IMHO.

Thanks for the quotes. I haven't tried it yet, I'll try it a bit later.

MQL5 is not any more complicated than MQL4. In some cases it is even simpler and faster. OOP is just a bugbear for beginners. In order to write a simple Expert Advisor you refer to, you don't need to know about OOP.

Tell me how much harder it is to write

// MQL4

OrderSend(_Symbol, OP_BUY, lot, price, Slip, sl, tp, "", Magic);
// MQL5

#include <Trade\\Trade.mqh>
CTrade trade;

trade.Buy(lot);
 
Sergey Voytsekhovsky:

You have described the dream of 95% of the world's traders. But you don't even want to bother with the spelling and syntax of the language. Enviable self-confidence, I'd like that. IMHO, of course.

I don't understand what you mean by "spelling", but it doesn't matter, because my robots do work, and in exactly the way I've described.

 
Alexey Viktorov:

MQL5 is no more complicated than MQL4. And in some cases it is even simpler and faster. OOP is just a horror story for beginners. In order to write a simple Expert Advisor that you're talking about, you don't need to know about OOP.

Tell me how much harder it is to write

OH, MY GOD! You killed me. I don't understand anything, although mechanically it's not harder to write the second version )).

 

Hello, how long will MT4 be around for? a year or two?

Sorry for the question, it's a little off-topic (but very important to me).

Reason: