Алексей КоКоКо: Please advise mql5, I want to collect statistics of the average size of eg a 12 hour candle, today for example is Friday, and I want to take the data from Thursday, Wednesday, Tuesday and Monday for the calculations.
I take time[] I convert TimeToString, then SplitString and TD. Is there a faster and less cumbersome way to refer to the same time candle a day or more back? Of course, I could run with the number of candlesticks of the current timeframe per day, but I'm afraid that if there are some holes in the quotes, they will be shifted.
I think we cannot do without the loop. But the loop can be built in different ways. Pay attention to CopyRates()
intCopyRates(
string symbol_name, // имя символаENUM_TIMEFRAMES timeframe, // периодdatetime start_time, // с какой датыint count, // сколько копируемMqlRates rates_array[] // массив, куда будут скопированы данные
);
We set PERIOD_H1, start_time - date 12:00 and count 1. At the next iteration, we add to this date or subtract from it (depending on which way the loop is organized) PeriodSeconds(PERIOD_D1)
I have a stochastic indicator with allergy, it gives a signal on crossing of moving lines. Please tell me how to make it give a signal by crossing the slips only when it is above or below the overbought or oversold zone.
#property indicator_separate_window#property indicator_buffers4#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_level180#property indicator_level220#property indicator_maximum100#property indicator_minimum0//---- input parameters/*************************************************************************
PERIOD_M1 1
PERIOD_M5 5
PERIOD_M15 15
PERIOD_M30 30
PERIOD_H1 60
PERIOD_H4 240
PERIOD_D1 1440
PERIOD_W1 10080
PERIOD_MN1 43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
---------------------------------------
MODE_SMA 0 Simple moving average,
MODE_EMA 1 Exponential moving average,
MODE_SMMA 2 Smoothed moving average,
MODE_LWMA 3 Linear weighted moving average.
You must use the numeric value of the MA Method that you want to use
when you set the 'ma_method' value with the indicator inputs.
**************************************************************************/externint TimeFrame=240;
externint KPeriod=5;
externint DPeriod=3;
externint Slowing=3;
externint MAMethod=0;
externint PriceField=0;// PriceField: 0=Hi/Low 1=Close/Closeexternstring note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN";
externstring __MA_Method = "SMA0 EMA1 SMMA2 LWMA3";
externstring __PriceField = "0=Hi/Low 1=Close/Close";
//extern string __Price = "0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
datetime last_t=0;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int init()
{
//---- indicator lineSetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexLabel(0, "MTF_Stochastic("+KPeriod+","+DPeriod+","+Slowing+")TF"+TimeFrame+"");
SetIndexLabel(1,"MTF_Stochastic("+KPeriod+","+DPeriod+","+Slowing+")TF"+TimeFrame+"");
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,233);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,234);
//---- name for DataWindow and indicator subwindow label switch(TimeFrame)
{
case1 : string TimeFrameStr="Period_M1"; break;
case5 : TimeFrameStr="Period_M5"; break;
case15 : TimeFrameStr="Period_M15"; break;
case30 : TimeFrameStr="Period_M30"; break;
case60 : TimeFrameStr="Period_H1"; break;
case240 : TimeFrameStr="Period_H4"; break;
case1440 : TimeFrameStr="Period_D1"; break;
case10080 : TimeFrameStr="Period_W1"; break;
case43200 : TimeFrameStr="Period_MN1"; break;
default : TimeFrameStr="Current Timeframe";
}
IndicatorShortName("MTF_Stochastic("+KPeriod+","+DPeriod+","+Slowing+") "+TimeFrameStr);
start();
return(0);
}
//----//+------------------------------------------------------------------+//| MTF Stochastic |//+------------------------------------------------------------------+int deinit()
{
for (int i=Bars;i>=0;i--){
ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));
}
return(0);
}
bool up_a=false;
bool dn_a=false;
int start()
{
datetime TimeArray[];
ArrayResize(TimeArray,Bars);
int i,limit,y=0,counted_bars=IndicatorCounted();
// Plot defined timeframe on to current timeframe
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
// limit=Bars-counted_bars+TimeFrame/Period(); //igorad
limit=Bars-1;
limit=MathMax(limit,TimeFrame/Period());
//limit=MathMin(limit,BarsToCount);for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
/***********************************************************
Add your main indicator loop below. You can reference an existing
indicator with its iName or iCustom.
Rule 1: Add extern inputs above for all neccesary values
Rule 2: Use 'TimeFrame' for the indicator timeframe
Rule 3: Use 'y' for the indicator's shift value
**********************************************************/
ExtMapBuffer3[i]=EMPTY_VALUE;
ExtMapBuffer4[i]=EMPTY_VALUE;
ExtMapBuffer1[i]=EMPTY_VALUE;
ExtMapBuffer2[i]=EMPTY_VALUE;
ExtMapBuffer1[i]=iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Slowing,MAMethod,PriceField,0,y);
ExtMapBuffer2[i]=iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Slowing,MAMethod,PriceField,1,y);
ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));
if (NormalizeDouble(ExtMapBuffer1[i],Digits)>NormalizeDouble(ExtMapBuffer2[i],Digits) && NormalizeDouble(ExtMapBuffer1[i+1],Digits)<=NormalizeDouble(ExtMapBuffer2[i+1],Digits) && NormalizeDouble(ExtMapBuffer1[i+1],Digits)!=NormalizeDouble(ExtMapBuffer1[i],Digits) ){
ExtMapBuffer3[i]=ExtMapBuffer1[i];
ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));
ObjectCreate("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),22,0,Time[i],Low[i]-5*Point);
ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),6,Blue);
ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),14,233);
}
if (NormalizeDouble(ExtMapBuffer1[i],Digits)<NormalizeDouble(ExtMapBuffer2[i],Digits) && NormalizeDouble(ExtMapBuffer1[i+1],Digits)>=NormalizeDouble(ExtMapBuffer2[i+1],Digits) && NormalizeDouble(ExtMapBuffer1[i+1],Digits)!=NormalizeDouble(ExtMapBuffer1[i],Digits)){
ExtMapBuffer4[i]=ExtMapBuffer1[i];
ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));
ObjectCreate("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),22,0,Time[i],High[i]+5*Point);
ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),6,Red);
ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),14,234);
}
}
////---- Refresh buffers ++++++++++++++ if (TimeFrame < Period()) TimeFrame = Period();
if (TimeFrame>Period()) {
int PerINT=TimeFrame/Period()+1;
datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period());
for(i=0;i<PerINT+1;i++) {if (TimeArr[i]>=TimeArray[0]) {
/********************************************************
Refresh buffers: buffer[i] = buffer[0];
************************************************************/
ExtMapBuffer1[i]=ExtMapBuffer1[0];
ExtMapBuffer2[i]=ExtMapBuffer2[0];
} } }
//+++++++++++++++++++++++++++++++++++++++++++++++++++++ Raff if (ExtMapBuffer3[0]!=EMPTY_VALUE && !up_a){
up_a=true;
dn_a=false;
Alert("MTF Stochastic Long cross Signal on "+Symbol());
}
if (ExtMapBuffer4[0]!=EMPTY_VALUE && !dn_a){
dn_a=true;
up_a=false;
Alert("MTF Stochastic Short cross Signal on "+Symbol());
}
return(0);
}
Good day to all. Can you please tell me how to code the following condition correctly using I don't remember which mathematical function.
if (Bid - Low[1]>=0.0030 && Bid - Low[1]<0.0035) {action;} I know that there is a math function that can be used in the above condition without && sign . But I don't remember what this mathematical function is called and how to apply it. Thanks for the help.
This question seems to be from the basics of MQL4. Suppose some variables X, Y, Z are declared in the global scope. Then, the program calls the F1() function to get the X value. Although this function returns only X, the Y and Z variables are calculated during its operation, i.e. they are assigned some values that will not be changed later. Further down the line, Y and Z are again used in some function F2(). To calculate these variables, should we address the F1() function again providing for return of not only X, but Y and Z as well? Or Y and Z are already overwritten in the global scope and will be automatically inserted into the F2() function in a changed form?
If you change a global variable in a function, it will change. But this is a dangerous way of programming, because in the code, as it grows, there will be unobvious assignments in different functions of the program.
There's a main function in the program, that's where you do the global variable assignment. And in other functions, do it this way:
int X, Y, Z;
voidOnTick()
{
X=Sum(Y,Z);
}
int Sum(int y, int z)
{
return(y+z);
}
Or like this:
int X, Y, Z;
voidOnTick()
{
Replace(X,Y,Z);
}
void Replace(int& x, int& y, int& z)
{
int a=x;
x=y;
y=z;
z=a;
}
Good day to all. Can you please tell me how to code the following condition correctly using I don't remember which mathematical function.
if (Bid - Low[1]>=0.0030 && Bid - Low[1]<0.0035) {action;} I know that there is a math function that can be used in the above condition without && sign and the program will check for price consistency in the range of 4 points. But I don't remember what this mathematical function is called and how to apply it. Thanks for the help.
Could you please tell me why the program (on mql4, on minutes, all ticks) reads the number explicitly and the same number calculated in the function differently? Here is the code
The program does not read Pr as 1.60854 althoughPrint( ) shows the value of Pr as 1.60854 . As a result, the program opens the second order, but it shouldn't do that .
And if we set the number 1.60854 instead of the Pr variable , the program reads it and doesn't open the second order.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Please advise mql5, I want to collect statistics of the average size of eg a 12 hour candle, today for example is Friday, and I want to take the data from Thursday, Wednesday, Tuesday and Monday for the calculations.
I think we cannot do without the loop. But the loop can be built in different ways. Pay attention to CopyRates()
We set PERIOD_H1, start_time - date 12:00 and count 1. At the next iteration, we add to this date or subtract from it (depending on which way the loop is organized) PeriodSeconds(PERIOD_D1)
Please tell me how to enumerate indicator parameters in iCustom.
I have a stochastic indicator with allergy, it gives a signal on crossing of moving lines. Please tell me how to make it give a signal by crossing the slips only when it is above or below the overbought or oversold zone.
Good day to all.
Can you please tell me how to code the following condition correctly using I don't remember which mathematical function.
if (Bid - Low[1]>=0.0030 && Bid - Low[1]<0.0035) {action;}
I know that there is a math function that can be used in the above condition without && sign . But I don't remember what this mathematical function is called and how to apply it.
Thanks for the help.
If you change a global variable in a function, it will change. But this is a dangerous way of programming, because in the code, as it grows, there will be unobvious assignments in different functions of the program.
There's a main function in the program, that's where you do the global variable assignment. And in other functions, do it this way:
Or like this:
how to correctly code the following condition using I don't remember which mathematical function
I don't know a better way of setting the condition
Good day to all.
Can you please tell me how to code the following condition correctly using I don't remember which mathematical function.
if (Bid - Low[1]>=0.0030 && Bid - Low[1]<0.0035) {action;}
I know that there is a math function that can be used in the above condition without && sign and the program will check for price consistency in the range of 4 points. But I don't remember what this mathematical function is called and how to apply it.
Thanks for the help.
Without and
Thank you very much for the tip.
Here is the code
The program does not read Pr as 1.60854 althoughPrint( ) shows the value of Pr as 1.60854 . As a result, the program opens the second order, but it shouldn't do that
.
And if we set the number 1.60854 instead of the Pr variable , the program reads it and doesn't open the second order.
QUESTION What changes we should make in the code so that the program reads Pr and does not open the second order.
Thank you for your help.