Hi everyone, I am wondering why this indicator work fine on charts, but fractals do no show up in strategy tester. Code is pretty simple shouldn't take much time to evaluate it.
//+------------------------------------------------------------------+//| AdvancedFractals.mq5 |//| Copyright 2018, MetaQuotes Software Corp. |//| https://mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2018, MetaQuotes Software Corp."#property link"https://mql5.com"#property version"1.00"#property description"Draws fractals of any dimension (Frames)"#property description"------------------------------------"#property description"If the Frames is less than one,"#property description"then one Frames will be used."#property indicator_chart_window#property indicator_buffers2#property indicator_plots2//--- plot UpFactal#property indicator_label1"Factal Up"#property indicator_type1DRAW_ARROW#property indicator_color1clrRed#property indicator_style1STYLE_SOLID#property indicator_width11//--- plot DownFractal#property indicator_label2"Fractal Down"#property indicator_type2DRAW_ARROW#property indicator_color2clrBlue#property indicator_style2STYLE_SOLID#property indicator_width21//--- input parametersinputuint Frames=2; // Frames//--- indicator buffersdouble BufferUpFactal[];
double BufferDownFractal[];
//--- global variablesint frames;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- settings parameters
frames=int(Frames<1 ? 1 : Frames);
//--- indicator buffers mappingSetIndexBuffer(0,BufferUpFactal,INDICATOR_DATA);
SetIndexBuffer(1,BufferDownFractal,INDICATOR_DATA);
//--- setting a buffers parametersPlotIndexSetInteger(0,PLOT_ARROW,119);
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,4);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetInteger(1,PLOT_ARROW,119);
PlotIndexSetInteger(1,PLOT_LINE_WIDTH,4);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//--- strings parametersIndicatorSetString(INDICATOR_SHORTNAME,"Advanced fractals("+(string)frames+")");
//---return(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[])
{
//--- Checking for minimum number of barsif(rates_total<frames*2+2) return0;
//---int limit=rates_total-prev_calculated;
if(limit>1)
{
limit=rates_total-frames-1;
ArrayInitialize(BufferUpFactal,0.0);
ArrayInitialize(BufferDownFractal,0.0);
}
//--- Calculate indicatorfor(int i=limit; i>frames && !IsStopped(); i--)
{
bool FrUp=true;
bool FrDn=true;
for(int n=1; n<=frames; n++)
{
if(high[i+n]>=high[i] || high[i-n]>=high[i]) FrUp=false;
if(low[i+n]<=low[i] || low[i-n]<=low[i]) FrDn=false;
}
//----Fractals upif(FrUp)
BufferUpFactal[i]=high[i];
//----Fractals downif(FrDn)
BufferDownFractal[i]=low[i];
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
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.
Code is pretty simple shouldn't take much time to evaluate it.