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

 
It's kind of like we're talking about a 4. The examples seem to have been written at different times, hence the use of different functions, which is misleading.
 
Artyom Trishkin:

Where did you find a tutorial on mql5 ?

google rules:Timur Sergeyevich Mashnin"MQL5 Programming Language: Advanced Use of the MetaTrader 5 Trading Platform".

And so, yes, on MQL4 Metacquotes, the textbook by Kovalev Sergey was officially announced. Programming in the MQL4 Algorithmic Language

 
psyman:
It's kinda like a discussion about the 4. It looks like the examples were written at different times, hence the use of different functions, which is misleading.

Forum on trading, automated trading systems & strategy testing

Any questions for newbies on MQL4, help and discussion on algorithms and codes

Artyom Trishkin, 2016.11.09 22:50

In this branch I want to begin to help those who really want to understand and learn programming in the new MQL4 and want to easily switch to MQL5 - the languages are very similar.

This blog will be a good place to discuss tasks, algorithms and any other questions related to MT programming one way or another.

I hope that other experienced members of our forum will join the discussion and the thread will be interesting to all.


 
Igor Makanu:

google rules:Timur Sergeyevich Mashnin"MQL5 Programming Language: Advanced Use of the MetaTrader 5 Trading Platform".

And so, yes, on MQL4 Metacquotes, the textbook by Kovalev Sergey was officially announced. Programming in Algorithmic Language MQL4

Who here knows about this Timur?

After all, the man is writing:

Forum on trading, automated trading systems and trading strategies testing

Any questions newbies have on MQL4, help and discussion on algorithms and codes

psyman, 2018.10.15 19:56


That should be written at the beginning of the tutorial, as Medvedev said "Cast in granite" :-)

What textbook? There's a reference, there's articles, there's a forum, but there's no textbook. And to claim that it is necessary there, and in what to cast it - it is to the author of the textbook, which you still need to search and find on third-party resources. In other words, the claim is unfounded, and not to MetaQuotes.
 

=i.e.the claim is unsubstantiated


I don't think this thread is the place to make any claims, but if you want accuracy, the word textbook is taken from here https://book.mql4.com/ru

From the very beginning they start using init https://book.mql4.com/ru/programm/structure , without saying anything about OnInit, and go on in other examples.

Учебник по MQL4
Учебник по MQL4
  • book.mql4.com
В настоящее время персональный компьютер стал незаменимым помощником в жизни каждого человека. Благодаря развитию Интернета и увеличению мощности современных компьютеров открылись новые возможности во многих областях деятельности. Ещё десять лет назад торговля на финансовых рынках была доступна только банкам и узкому кругу специалистов. Сегодня...
 
psyman:

=i.e.the claim is unsubstantiated


I don't think this thread is the place to make any claims, but if you want accuracy, the word textbook is taken from here https://book.mql4.com/ru

From the very beginning they start using init https://book.mql4.com/ru/programm/structure , don't say anything about OnInit and go on in other examples.

I see. This textbook is a hundred years old :)

I understand that you may not know about it.

In general - it is necessary (probably, someone) for introductory acquaintance. It has been very many years since it was written and now, after reading it, it's better to ask about something here on the forum.

Well, try without "should", "must", "didn't do", "didn't report", etc...

Everything you need for a complete and in-depth knowledge of mql4 and mql5 - everything is available on this resource in abundance and for all tastes.

 

Hello. Help me with the "Murray lines" indicator. (I want to use its data in my EA through the

iCustom. to return the value of the 1st indicator line on the first bar - " double Divb1=iCustom(Symbol(),PERIOD_CURRENT, "Murrey-levels-system",P,StepBack,1,1); " and use Divb1 as a market entry condition, but when tested, the position is opened without taking this line into account.(Instead of 1, you can put any index of the indicator line, the orders open in the same places. Condition if(Bid<=Divb1)

Perhaps there is an error in the function parameters but I cannot decide which ones.

//| |
//| Copyright © 1999-2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.ru |
//+------------------------------------------------------------------+
#property indicator_chart_window
//----
extern int P=64;
extern inttern StepBack=0;
//----
double dmml=0,dvtl=0,sum=0,v1=0,v2=0,mn=0,mx=0,x1=0,x2=0,x3=0,x4=0,x5=0,x6=0,y1=0,y2=0,y3=0,y4=0,y5=0,y6=0,octave=0,fractal=0,range =0,finalH =0,finalL =0,mml[13];
string ln_txt[13],
buff_str="";
int
bn_v1 =0,
bn_v2 =0,
OctLinesCnt=13,
mml_thk=8,
mml_clr[13],
mml_shft=3,
nTime=0,
CurPeriod=0,
nDigits=0,
i=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
ln_txt[0] ="[-2/8]P";
ln_txt[1] ="[-1/8]P"; ln_txt[2] ="STOP [0/8]";
ln_txt[3] ="STOP_ADVANCED [1/8]";
ln_txt[4] ="ROLL_TURN [2/8]";
ln_txt[5] ="BOTTOM_CHANNEL [3/8]";
ln_txt[6] ="ROTATION_TURN [4/8]";
ln_txt[7] ="TOP_CHANNEL [5/8]";
ln_txt[8] ="ROTATION_TURN [6/8]";
ln_txt[9] ="STOP_circle [7/8]";
ln_txt[10]="СОПРОТИВЛЕНИЕ [8/8]";
ln_txt[11]="[+1/8]P";//"overshoot [+1/8]";
ln_txt[12]="[+2/8]P";// "extremely overshoot [+2/8]";
//----
mml_shft=25;
mml_thk =3;
//----
mml_clr[0] =Magenta;
mml_clr[1] =Pink;
mml_clr[2] =Blue;
mml_clr[3] =Orange;
mml_clr[4] =Red;
mml_clr[5] =OliveDrab;
mml_clr[6] =Blue;
mml_clr[7] =OliveDrab;
mml_clr[8] =Red;
mml_clr[9] =Orange;
mml_clr[10]=Blue;
mml_clr[11]=Pink;
mml_clr[12]=Magenta;
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
Comment(" ");
for(i=0;i<OctLinesCnt;i++)
{
buff_str="mml "+i;
ObjectDelete(buff_str);
buff_str="mml_txt "+i;
ObjectDelete(buff_str);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if((nTime!=Time[0]) || (CurPeriod!=Period()))
{
bn_v1=Lowest(NULL,0,MODE_LOW,P+StepBack,0);
bn_v2=Highest(NULL,0,MODE_HIGH,P+StepBack,0);
//----
v1=Low[bn_v1];
v2=High[bn_v2];
//----
if(v2<=250000 && v2>25000 )
fractal=100000;
else
if(v2<=25000 && v2>2500 )
fractal=10000;
else
if(v2<=2500 && v2>250 )
fractal=1000;
else
if(v2<=250 && v2>25 )
fractal=100;
else
if(v2<=25 && v2>12.5 )
fractal=12.5;
else
if(v2<=12.5 && v2>6.25 )
fractal=12.5;
else
if(v2<=6.25 && v2>3.125 )
fractal=6.25;
else
if(v2<=3.125 && v2>1.5625 )
fractal=3.125;
else
if(v2<=1.5625 && v2>0.390625 )
fractal=1.5625;
else
if(v2<=0.390625 && v2>0)
fractal=0.1953125;
range=(v2-v1);
sum=MathFloor(MathLog(fractal/range)/MathLog(2));
octave=fractal*(MathPow(0.5,sum));
mn=MathFloor(v1/octave)*octave;
if((mn+octave)>v2 )
mx=mn+octave;
else
mx=mn+(2*octave);
if((v1>=(3*(mx-mn)/16+mn)) && (v2<=(9*(mx-mn)/16+mn)) )
x2=mn+(mx-mn)/2;
else x2=0;
if((v1>=(mn-(mx-mn)/8))&& (v2<=(5*(mx-mn)/8+mn)) && (x2==0) )
x1=mn+(mx-mn)/2;
else x1=0;
if((v1>=(mn+7*(mx-mn)/16))&& (v2<=(13*(mx-mn)/16+mn)) )
x4=mn+3*(mx-mn)/4;
else x4=0;
if((v1>=(mn+3*(mx-mn)/8))&& (v2<=(9*(mx-mn)/8+mn))&& (x4==0) )
x5=mx;
else x5=0;
if((v1>=(mn+(mx-mn)/8))&& (v2<=(7*(mx-mn)/8+mn))&& (x1==0) && (x2==0) && (x4==0) && (x5==0) )
x3=mn+3*(mx-mn)/4;
else x3=0;
if((x1+x2+x3+x4+x5) ==0 )
x6=mx;
else x6=0;
finalH=x1+x2+x3+x4+x5+x6;
if(x1>0 )
y1=mn;
else y1=0;
if(x2>0 )
y2=mn+(mx-mn)/4;
else y2=0;
if(x3>0 )
y3=mn+(mx-mn)/4;
else y3=0;
if(x4>0 )
y4=mn+(mx-mn)/2;
else y4=0;
if(x5>0 )
y5=mn+(mx-mn)/2;
else y5=0;
if((finalH>0) && ((y1+y2+y3+y4+y5)==0) )
y6=mn;
else y6=0;
finalL=y1+y2+y3+y4+y5+y6;
for( i=0; i<OctLinesCnt; i++)
{
mml[i]=0;
}
dmml=(finalH-finalL)/8;
mml[0] =(finalL-dmml*2); //-2/8
for( i=1; i<OctLinesCnt; i++)
{
mml[i]=mml[i-1] + dmml;
}
for( i=0; i<OctLinesCnt; i++ )
{
buff_str="mml "+i;
if(ObjectFind(buff_str)==-1)
{
ObjectCreate(buff_str, OBJ_HLINE, 0, Time[0], mml[i];
ObjectSet(buff_str, OBJPROP_STYLE, STYLE_SOLID;)
ObjectSet(buff_str, OBJPROP_COLOR, mml_clr[i]);
ObjectMove(buff_str, 0, Time[0], mml[i]);
}
else
{
ObjectMove(buff_str, 0, Time[0], mml[i]);
}
buff_str="mml_txt "+i;
if(ObjectFind(buff_str)==-1)
{
ObjectCreate(buff_str, OBJ_TEXT, 0, Time[mml_shft], mml_shft;)
ObjectSetText(buff_str, ln_txt[i], 8, "Arial", mml_clr[i]);
ObjectMove(buff_str, 0, Time[mml_shft], mml[i]);
}
else
{
ObjectMove(buff_str, 0, Time[mml_shft], mml[i]);
}
}
nTime =Time[0];
CurPeriod= Period();
}
//----
return(0);
}
//+------------------------------------------------------------------+
 
Anatoliy Ryzhakov:

Hello. Help me figure out the indicator ...

No one is going to look at this kind of tartan.


 

=In general - it's needed (probably by someone) for an introduction.


Is there something more up-to-date, with good examples?


=Well, try without "should", "must", "didn't do", "didn't report".


You seem to have me confused with someone else. I did not use such words here.

 

I don't understand how to write indicators, what is the problem?

I need a line to be drawn showing the difference in price between active_1 and active_2

it works

I also need an average ma_period ma_period to be plotted on this line, there is a problem with it, it is not displayed

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 2
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrGreen, clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrWhite
#property indicator_style2 STYLE_SOLID
#property indicator_width1 1
#include <MovingAverages.mqh>

input string active_1 = "GBPNZD.m";
input string active_2 = "GBPAUD.m";
input ENUM_TIMEFRAMES timeframe = PERIOD_H1;
input int ma_period = 30;

double firstBuffer[], secondBuffer[], colorBuffer[], dataBuffer[], maBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, dataBuffer, INDICATOR_DATA);
   SetIndexBuffer(1, maBuffer, INDICATOR_DATA);
   SetIndexBuffer(2, colorBuffer, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(3, firstBuffer, INDICATOR_CALCULATIONS);
   SetIndexBuffer(4, secondBuffer, INDICATOR_CALCULATIONS);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, ma_period);
   IndicatorSetString(INDICATOR_SHORTNAME, "DifferenceCurrency "+active_1+"  "+active_2);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---

   CopyClose(active_1,timeframe,0,rates_total,firstBuffer);
   CopyClose(active_2,timeframe,0,rates_total,secondBuffer);
   int first, bar;
   if(prev_calculated == 0) first = begin; else first = prev_calculated - 1;
   for(bar = first; bar<rates_total; bar++){
      dataBuffer[bar] = firstBuffer[bar]-secondBuffer[bar];
      maBuffer[bar] = SimpleMA(bar, ma_period, dataBuffer);
   }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: