a possible example to use MTF Fractals in right way.
//+------------------------------------------------------------------+//| Demo_iFractals.mq5 |//| Copyright 2011, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2011, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property description"The indicator demonstrates how to obtain data"#property description"of indicator buffers for the iFractals technical indicator."#property description"A symbol and timeframe used for calculation of the indicator,"#property description"are set by the symbol and period parameters."#property description"The method of creation of the handle is set through the 'type' parameter (function type)."#property indicator_chart_window#property indicator_buffers4#property indicator_plots4//--- the FractalUp plot#property indicator_label1"FractalUp"#property indicator_type1DRAW_ARROW#property indicator_color1clrBlue//--- the FractalDown plot#property indicator_label2"FractalDown"#property indicator_type2DRAW_ARROW#property indicator_color2clrRed//--- the FractalUp plot#property indicator_label3"FractalUp2"#property indicator_type3DRAW_ARROW#property indicator_color3clrBlue//--- the FractalDown plot#property indicator_label4"FractalDown2"#property indicator_type4DRAW_ARROW#property indicator_color4clrRed//+------------------------------------------------------------------+//| Enumeration of the methods of handle creation |//+------------------------------------------------------------------+inputstring symbol=" "; // symbolinputENUM_TIMEFRAMES period=PERIOD_M1; // timeframeinputENUM_TIMEFRAMES period2=PERIOD_M5; // timeframe//--- indicator buffersdouble FractalUpBuffer[],FractalUpBuffer2[];
double FractalDownBuffer[],FractalDownBuffer2[];
//--- variable for storing the handle of the iFractals indicatorint handle,handle2;
//--- variable for storingstring name=symbol;
//--- name of the indicator on a chartstring short_name,short_name2;
//--- we will keep the number of values in the Fractals indicatorint bars_calculated=0,bars_calculated2=0;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit() {
//--- assignment of arrays to indicator buffersSetIndexBuffer(0,FractalUpBuffer,INDICATOR_DATA);
SetIndexBuffer(1,FractalDownBuffer,INDICATOR_DATA);
SetIndexBuffer(2,FractalUpBuffer2,INDICATOR_DATA);
SetIndexBuffer(3,FractalDownBuffer2,INDICATOR_DATA);
//--- set codes using a symbol from the Wingdings charset for the PLOT_ARROW propertyPlotIndexSetInteger(0,PLOT_ARROW,217); // arrow upPlotIndexSetInteger(1,PLOT_ARROW,218); // arrow downPlotIndexSetInteger(2,PLOT_ARROW,217); // arrow upPlotIndexSetInteger(3,PLOT_ARROW,218); // arrow down//--- determine the symbol the indicator is drawn for
name=symbol;
//--- delete spaces to the right and to the leftStringTrimRight(name);
StringTrimLeft(name);
//--- if it results in zero length of the 'name' stringif(StringLen(name)==0) {
//--- take the symbol of the chart the indicator is attached to
name=_Symbol;
}
//--- create handle of the indicator
handle=iFractals(name,period);
handle2=iFractals(name,period2);
//--- if the handle is not createdif(handle==INVALID_HANDLE) {
//--- tell about the failure and output the error codePrintFormat("Failed to create handle of the iFractals indicator for the symbol %s/%s, error code %d",
name,
EnumToString(period),
GetLastError());
//--- the indicator is stopped earlyreturn(INIT_FAILED);
}
if(handle2==INVALID_HANDLE) {
//--- tell about the failure and output the error codePrintFormat("Failed to create handle of the iFractals2 indicator for the symbol %s/%s, error code %d",
name,
EnumToString(period2),
GetLastError());
//--- the indicator is stopped earlyreturn(INIT_FAILED);
}
//--- show the symbol/timeframe the Fractals indicator is calculated for
short_name=StringFormat("iFractals(%s/%s)",name,EnumToString(period));
short_name2=StringFormat("iFractals(%s/%s)",name,EnumToString(period2));
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- normal initialization of the indicatorreturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[]) {
//--- number of values copied from the iFractals indicatorint values_to_copy, values_to_copy2;
//--- determine the number of values calculated in the indicatorint calculated=BarsCalculated(handle);
int calculated2=BarsCalculated(handle2);
if(calculated<=0) {
PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
return(0);
}
if(calculated2<=0) {
PrintFormat("BarsCalculated2() returned %d, error code %d",calculated2,GetLastError());
return(0);
}
//--- if it is the first start of calculation of the indicator or if the number of values in the iFractals indicator changed//---or if it is necessary to calculated the indicator for two or more bars (it means something has changed in the price history)if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1) {
//--- if the FractalUpBuffer array is greater than the number of values in the iFractals indicator for symbol/period, then we don't copy everything//--- otherwise, we copy less than the size of indicator buffersif(calculated>rates_total) values_to_copy=rates_total;
else values_to_copy=calculated;
} else {
//--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()//--- for calculation not more than one bar is added
values_to_copy=(rates_total-prev_calculated)+1;
}
if(prev_calculated==0 || calculated2!=bars_calculated2 || rates_total>prev_calculated+1) {
//--- if the FractalUpBuffer array is greater than the number of values in the iFractals indicator for symbol/period, then we don't copy everything//--- otherwise, we copy less than the size of indicator buffersif(calculated2>rates_total) values_to_copy2=rates_total;
else values_to_copy2=calculated2;
} else {
//--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()//--- for calculation not more than one bar is added
values_to_copy2=(rates_total-prev_calculated)+1;
}
//--- fill the FractalUpBuffer and FractalDownBuffer arrays with values from the Fractals indicator//--- if FillArrayFromBuffer returns false, it means the information is nor ready yet, quit operationif(!FillArraysFromBuffers(FractalUpBuffer,FractalDownBuffer,handle,values_to_copy)) return(0);
if(!FillArraysFromBuffers(FractalUpBuffer2,FractalDownBuffer2,handle2,values_to_copy)) return(0);
//--- form the messagestring comm=StringFormat("%s ==> Updated value in the indicator %s: %d",
TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS),
short_name,
values_to_copy);
string comm2=StringFormat("%s ==> Updated value in the indicator %s: %d",
TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS),
short_name2,
values_to_copy2);
//--- display the service message on the chartComment(comm,"\n",comm2);
//--- memorize the number of values in the Fractals indicator
bars_calculated=calculated;
bars_calculated2=calculated2;
//--- return the prev_calculated value for the next callreturn(rates_total);
}
//+------------------------------------------------------------------+//| Filling indicator buffers from the iFractals indicator |//+------------------------------------------------------------------+bool FillArraysFromBuffers(double &up_arrows[], // indicator buffer for up arrowsdouble &down_arrows[], // indicator buffer for down arrowsint ind_handle, // handle of the iFractals indicatorint amount // number of copied values
) {
//--- reset error codeResetLastError();
//--- fill a part of the FractalUpBuffer array with values from the indicator buffer that has 0 indexif(CopyBuffer(ind_handle,0,0,amount,up_arrows)<0) {
//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the iFractals indicator to the FractalUpBuffer array, error code %d",
GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false);
}
//--- fill a part of the FractalDownBuffer array with values from the indicator buffer that has index 1if(CopyBuffer(ind_handle,1,0,amount,down_arrows)<0) {
//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the iFractals indicator to the FractalDownBuffer array, error code %d",
GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false);
}
//--- everything is finereturn(true);
}
//+------------------------------------------------------------------+//| Indicator deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason) {
if(handle!=INVALID_HANDLE)
IndicatorRelease(handle);
if(handle2!=INVALID_HANDLE)
IndicatorRelease(handle2);
//--- clear the chart after deleting the indicatorComment("");
}
//+------------------------------------------------------------------+
Yes its just an idea so you know what you were doing wrong. It shows you how to use Handle
To shift arrows
You need to study this and play with value 10
yeah, I try that; but it's not about shift arrow :
//+------------------------------------------------------------------+//| Demo_iFractals.mq5 |//| Copyright 2011, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2011, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property description"The indicator demonstrates how to obtain data"#property description"of indicator buffers for the iFractals technical indicator."#property description"A symbol and timeframe used for calculation of the indicator,"#property description"are set by the symbol and period parameters."#property description"The method of creation of the handle is set through the 'type' parameter (function type)."#property indicator_chart_window#property indicator_buffers4#property indicator_plots4//--- the FractalUp plot#property indicator_label1"FractalUp"#property indicator_type1DRAW_ARROW#property indicator_color1clrBlue//--- the FractalDown plot#property indicator_label2"FractalDown"#property indicator_type2DRAW_ARROW#property indicator_color2clrRed//--- the FractalUp plot#property indicator_label3"FractalUp2"#property indicator_type3DRAW_ARROW#property indicator_color3clrBlue//--- the FractalDown plot#property indicator_label4"FractalDown2"#property indicator_type4DRAW_ARROW#property indicator_color4clrRed//+------------------------------------------------------------------+//| Enumeration of the methods of handle creation |//+------------------------------------------------------------------+inputstring symbol=" "; // symbolinputENUM_TIMEFRAMES period=PERIOD_M1; // timeframeinputENUM_TIMEFRAMES period2=PERIOD_M5; // timeframe//--- indicator buffersdouble FractalUpBuffer[],FractalUpBuffer2[];
double FractalDownBuffer[],FractalDownBuffer2[];
//--- variable for storing the handle of the iFractals indicatorint handle,handle2;
//--- variable for storingstring name=symbol;
//--- name of the indicator on a chartstring short_name,short_name2;
//--- we will keep the number of values in the Fractals indicatorint bars_calculated=0,bars_calculated2=0;
int ExtArrowShift=10;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit() {
//--- assignment of arrays to indicator buffersSetIndexBuffer(0,FractalUpBuffer,INDICATOR_DATA);
SetIndexBuffer(1,FractalDownBuffer,INDICATOR_DATA);
SetIndexBuffer(2,FractalUpBuffer2,INDICATOR_DATA);
SetIndexBuffer(3,FractalDownBuffer2,INDICATOR_DATA);
//--- set codes using a symbol from the Wingdings charset for the PLOT_ARROW propertyPlotIndexSetInteger(0,PLOT_ARROW,217); // arrow upPlotIndexSetInteger(1,PLOT_ARROW,218); // arrow downPlotIndexSetInteger(2,PLOT_ARROW,217); // arrow upPlotIndexSetInteger(3,PLOT_ARROW,218); // arrow downPlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-ExtArrowShift);
PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,ExtArrowShift);
PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,-ExtArrowShift);
PlotIndexSetInteger(3,PLOT_ARROW_SHIFT,ExtArrowShift);
//--- determine the symbol the indicator is drawn for
name=symbol;
//--- delete spaces to the right and to the leftStringTrimRight(name);
StringTrimLeft(name);
//--- if it results in zero length of the 'name' stringif(StringLen(name)==0) {
//--- take the symbol of the chart the indicator is attached to
name=_Symbol;
}
//--- create handle of the indicator
handle=iFractals(name,period);
handle2=iFractals(name,period2);
//--- if the handle is not createdif(handle==INVALID_HANDLE) {
//--- tell about the failure and output the error codePrintFormat("Failed to create handle of the iFractals indicator for the symbol %s/%s, error code %d",
name,
EnumToString(period),
GetLastError());
//--- the indicator is stopped earlyreturn(INIT_FAILED);
}
if(handle2==INVALID_HANDLE) {
//--- tell about the failure and output the error codePrintFormat("Failed to create handle of the iFractals2 indicator for the symbol %s/%s, error code %d",
name,
EnumToString(period2),
GetLastError());
//--- the indicator is stopped earlyreturn(INIT_FAILED);
}
//--- show the symbol/timeframe the Fractals indicator is calculated for
short_name=StringFormat("iFractals(%s/%s)",name,EnumToString(period));
short_name2=StringFormat("iFractals(%s/%s)",name,EnumToString(period2));
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- normal initialization of the indicatorreturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[]) {
//--- number of values copied from the iFractals indicatorint values_to_copy, values_to_copy2;
//--- determine the number of values calculated in the indicatorint calculated=BarsCalculated(handle);
int calculated2=BarsCalculated(handle2);
if(calculated<=0) {
PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
return(0);
}
if(calculated2<=0) {
PrintFormat("BarsCalculated2() returned %d, error code %d",calculated2,GetLastError());
return(0);
}
//--- if it is the first start of calculation of the indicator or if the number of values in the iFractals indicator changed//---or if it is necessary to calculated the indicator for two or more bars (it means something has changed in the price history)if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1) {
//--- if the FractalUpBuffer array is greater than the number of values in the iFractals indicator for symbol/period, then we don't copy everything//--- otherwise, we copy less than the size of indicator buffersif(calculated>rates_total) values_to_copy=rates_total;
else values_to_copy=calculated;
} else {
//--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()//--- for calculation not more than one bar is added
values_to_copy=(rates_total-prev_calculated)+1;
}
if(prev_calculated==0 || calculated2!=bars_calculated2 || rates_total>prev_calculated+1) {
//--- if the FractalUpBuffer array is greater than the number of values in the iFractals indicator for symbol/period, then we don't copy everything//--- otherwise, we copy less than the size of indicator buffersif(calculated2>rates_total) values_to_copy2=rates_total;
else values_to_copy2=calculated2;
} else {
//--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()//--- for calculation not more than one bar is added
values_to_copy2=(rates_total-prev_calculated)+1;
}
//--- fill the FractalUpBuffer and FractalDownBuffer arrays with values from the Fractals indicator//--- if FillArrayFromBuffer returns false, it means the information is nor ready yet, quit operationif(!FillArraysFromBuffers(FractalUpBuffer,FractalDownBuffer,handle,values_to_copy)) return(0);
if(!FillArraysFromBuffers(FractalUpBuffer2,FractalDownBuffer2,handle2,values_to_copy)) return(0);
//--- form the messagestring comm=StringFormat("%s ==> Updated value in the indicator %s: %d",
TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS),
short_name,
values_to_copy);
string comm2=StringFormat("%s ==> Updated value in the indicator %s: %d",
TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS),
short_name2,
values_to_copy2);
//--- display the service message on the chartComment(comm,"\n",comm2);
//--- memorize the number of values in the Fractals indicator
bars_calculated=calculated;
bars_calculated2=calculated2;
//--- return the prev_calculated value for the next callreturn(rates_total);
}
//+------------------------------------------------------------------+//| Filling indicator buffers from the iFractals indicator |//+------------------------------------------------------------------+bool FillArraysFromBuffers(double &up_arrows[], // indicator buffer for up arrowsdouble &down_arrows[], // indicator buffer for down arrowsint ind_handle, // handle of the iFractals indicatorint amount // number of copied values
) {
//--- reset error codeResetLastError();
//--- fill a part of the FractalUpBuffer array with values from the indicator buffer that has 0 indexif(CopyBuffer(ind_handle,0,0,amount,up_arrows)<0) {
//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the iFractals indicator to the FractalUpBuffer array, error code %d",
GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false);
}
//--- fill a part of the FractalDownBuffer array with values from the indicator buffer that has index 1if(CopyBuffer(ind_handle,1,0,amount,down_arrows)<0) {
//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the iFractals indicator to the FractalDownBuffer array, error code %d",
GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false);
}
//--- everything is finereturn(true);
}
//+------------------------------------------------------------------+//| Indicator deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason) {
if(handle!=INVALID_HANDLE)
IndicatorRelease(handle);
if(handle2!=INVALID_HANDLE)
IndicatorRelease(handle2);
//--- clear the chart after deleting the indicatorComment("");
}
//+------------------------------------------------------------------+
Please pay attention to what is posted. I provided a link for the iFractals function, which includes an example for Fractals.
Did you read it? Did you experiment with the example code?
There are also examples in the CodeBase. Please do some research on their use.
Hold On Trying To Do Some Change With iFractal.
Let Me Check. And Then I'll Share My Code Here, If You Can Help Me.
Please pay attention to what is posted. I provided a link for the iFractals function, which includes an example for Fractals.
Did you read it? Did you experiment with the example code?
There are also examples in the CodeBase. Please do some research on their use.
Nevermind, it didnt work for me sir.
I can't manage things together... because of my knowledge.
But I really appreciate what you do here for me.
Thanks
Here Is The Final Code, I Think It's Fine; But it cant draw the arrow on top of the higher time frame array :
IDK, Maybe There Is Buffer Or Array Problem.
Pleas Check This :
Good morning
there are warnings for me in the ifractal example code
Nothing serious
But for me the timeframe selection does not work
Good morning
there are warnings for me in the ifractal example code
Nothing serious
But for me the timeframe selection does not work
Yeah I Remove that first buffer property.
but, it's not working...
Yeah I Remove that first buffer property.
but, it's not working...
a possible example to use MTF Fractals in right way.
a possible example to use MTF Fractals in right way.
thans a lot.
but this have not a normal result :
Yes its just an idea so you know what you were doing wrong. It shows you how to use Handle
To shift arrows
You need to study this and play with value 10
Yes its just an idea so you know what you were doing wrong. It shows you how to use Handle
To shift arrows
You need to study this and play with value 10
yeah, I try that; but it's not about shift arrow :
You are mixing apples and oranges.