Questions from Beginners MQL5 MT5 MetaTrader 5 - page 189

 
How is Metatrader 5 different from the previous 4 is harder to work with or not. Every broker offers these programmes, why isn't there one programme for all brokers so you don't have to install many of them.
Блог полезных и познавательных статей обо всем, на различную тематику категорий, все интересное, что бы Вам хотелось узнать и найти в материалах Интернет сети
Блог полезных и познавательных статей обо всем, на различную тематику категорий, все интересное, что бы Вам хотелось узнать и найти в материалах Интернет сети
  • es-blogy.ru
Если вами соблюдается диета при язве, то это поможет вам избежать частых обострений и свести их к минимуму; а чем меньше обострений, тем меньше количество медикаментозных препаратов вам нужно принимать. Инфекцию Н. pylori можно обнаружить двумя способами: провести анализ крови; анализ желудочного сока. Эндоскопическое или радиологическое...
 
koctik:
How is Metatrader 5 different from the previous 4 is harder to work with or not. Every broker offers these programs, why isn't there one program for all brokers so you don't have to install a lot of them.
Download both terminals, work on them on demo accounts and find out for yourself.
 

I'm trying to make a function that will return the result of the last position closed (plus or minus). This function is designed for a multicurrency Expert Advisor and should select the last closed position out of all currency pairs, and I'm having some problems with it. Can you correct the function?

double last_profit()
{  
int dir = 0;
double prof = 0;
ulong d_ticket;

if (HistorySelect(0,TimeCurrent())) 
    {
       int j=HistoryDealsTotal()-1;
       if(j>0)
      {
         d_ticket = HistoryDealGetTicket(j);
         if (d_ticket>0)
         { 
         mydeal.Ticket(d_ticket);          
         prof = mydeal.Profit();
         }
       }
     }
if(prof < 0)dir = -1;
if(prof > 0)dir = 1;
if(prof == 0)dir =0;

return(dir);
} 

 
Automated-Trading:

OBJ_ALL_PERIODS=2097151

Thanks, but nothing worked. The problem is that D1 and...... period calculations should be displayed on all timeframes, but it doesn't come out running as it is. What to do?
Files:
macd2.mq5  4 kb
 
Reshetov:

What do you mean: unused methods in your classes? This is not the practice in OOP. A normal OOP programmer, in contrast to algorithmic programming, creates classes with all the necessary fields and methods, as they say, for all occasions, because the same class may be later used in other applications or become a part of class library. Not to mention the fact that even within one project it is better to create full classes, not stripped-down, so that you don't have to search through the source code and add the required fields and methods later.

In OOP any economy, which many people get used to in algorithmic programming, may turn out to be detrimental later. Everything what is not used must be excluded from the code by the compiler and not by the programmer.

Of course, OOP results in a larger source code compared to algorithmic programming. But this is not a drawback but an advantage because much of the "unnecessary" code in a given project can be reused in other projects.

There is no need to try to make a conundrum, i.e. everything in one class. You need to create class libraries, i.e. break functionality into separate classes and don't forget to add comments to this fiefdom, and then everything will be in order. Initially, when I started learning Java after Pascal, I too tried to do everything in one piece, i.e. instead of using OOP, I created one class with everything I needed for a certain task, just like in algorithmic programming. The result was a non-universal mess that was impossible to apply anywhere later, not to mention that it was hard to understand such code.

I understand all that very well. But you can at least show us private variables that are not used as it is done in VisualStudio, can't you?

The point is that classes are designed during the development process. You simply cannot take into account everything before creation. That's why frame classes with the least possible functionality are created. While interacting with these framework classes, the overall architecture starts to be elaborated. Some methods are simply deleted, others are moved to the private section, and others are migrated from one class to another. In the process, forgotten variables, methods and even entire classes inevitably appear. This is normal because it's something else like the Okama principle in action - first we write bad, redundant code. Then we formalize the task more clearly and some of the entities simply disappear. Redundancy comes to naught. And it is in this process, the compiler's help would be very useful - to see unused variables and at least private methods would be very useful.

 

Hello.

I understand that the functionOnCalculate() that is used in the indicators generates by itself, i.e. without the price change event ,

What function can be applied in the indicator that generates only when a price change event occurs? Thank you

 
Vikon:

Hello.

I understand that the functionOnCalculate() that is used in the indicators generates by itself, i.e. without the price change event ,

What function can be applied in the indicator that generates only when a price change event occurs? Thank you

TheCalculateevent is generated for indicators immediately after the Init event and at any change of price data. It is handled by theOnCalculate function. When history is changed (when history is paging) this event will also generateOnCalculate.

TheOnCalculate is the most important function for the indicator, in which all of the indicator calculations are performed in case of price data changes.

 
barabashkakvn:

TheCalculateevent is generated only for indicators immediately after the Init event is sent and upon any change in price data. This event is handled by theOnCalculate function. The sameOnCalculate is generated when history is changed (when the history is paging).

TheOnCalculate is the most important function for the indicator, in which all of the indicator's calculations are performed in case of price data changes.

Here it has some looping, i.e. it always generates and when the period changes, the readings change. What is the error?

#property copyright "Copyright 2014, MetaQuotes Software Corp.
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |

int EMA1=12;
int EMA2=26;
int SMA=9;

ENUM_TIMEFRAMES period_macd;
datetime t_MACD[];
double MACD[];
bool high_low=false;
int shift_nachalo;
double w_MACD[]; d_MACD[];
int w_MACD_handle,d_MACD_handle;

int barDown=0;
int barUP=0;

//+------------------------------------------------------------------+ return(0);
int OnInit()
{
w_MACD_handle=iMACD(NULL,PERIOD_W1,EMA1,EMA2,SMA,PRICE_CLOSE);
d_MACD_handle=iMACD(NULL,PERIOD_D1,EMA1,EMA2,SMA,PRICE_CLOSE);
ArraySetAsSeries(MACD,true);
ArraySetAsSeries(t_MACD,true);
ArraySetAsSeries(w_MACD,true);
ArraySetAsSeries(d_MACD,true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+ MACD_handle=iMACD(NULL,PERIOD_W1,EMA1,EMA1,SMA,PRICE_CLOSE);
//| 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[])
{

ObjectsDeleteAll(0,0,-1);
////////////////////////////////////////////////////////
period_macd=PERIOD_D1;
CopyBuffer(d_MACD_handle,0,0,1000,d_MACD);
ArrayCopy(MACD,d_MACD,0,0,WHOLE_ARRAY);
nachalo();
ObjectCreate(0, "lin_2",OBJ_VLINE,0,t_MACD[shift_nachalo],0);
ObjectSetInteger(0, "lin_2",OBJPROP_BACK,true);
ObjectSetInteger(0, "lin_2",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0, "lin_2",OBJPROP_COLOR,clrYellow);
ObjectSetInteger(0, "lin_2",OBJPROP_STYLE,1);
return(rates_total);
}
//+------------------------------------------------------------------+
//////////////////////////////////////////////////////////////////////////////
void nachalo() //beginning of a new wave
{
double low_nachalo[],high_nachalo[];
CopyTime(NULL,period_macd,0,1000,t_MACD);
if (MACD[1]>0)
{high_low=false;
while (MACD[barDown]>0)
{barDown++;}
barUP=barDown;
while (MACD[barUP]<0)
{barUP++;}
CopyLow(NULL,period_macd,0,barUP,low_nachalo);
ArraySetAsSeries(low_nachalo,true);
shift_nachalo=ArrayMinimum(low_nachalo,barDown-1,barUP-(barDown-1));
}
if (MACD[1]<0)
{high_low=true;
while (MACD[barUP]<0)
{barUP++;}
barDown=barUP;
while (MACD[barDown]>0)
{barDown++;}
CopyHigh(NULL,period_macd,0,barDown,high_nachalo);

ArraySetAsSeries(high_nachalo,true);

shift_nachalo=ArrayMaximum(high_nachalo,barUP-1,barDown-(barUP-1));
}}
Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
Files:
macd2.mq5  4 kb
 
Vikon:

This is where the loop happens, i.e. it constantly generates and when the period changes, the readings change. What is the error?


How to insert the code correctly in the forum.

 
Vikon:


Note the error:

No tethered indicator buffers

Use:

//---- превращение динамических массивов в индикаторные буферы
   SetIndexBuffer()
Also read the article"How to write an indicator in MQL5".



Reason: