Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi everyone please i need your help on this indicator, i adjusted fractal so that you can switch between periods,
so i used bollinger bands and fractal to avoid false signals, the aim is that if fractal at your desired period shows and current close is above or below the bollinger bands then you sell or buy, it works very great but the problem is that i get alerts very late and arrows also shows very late and i tried alot but still yet i cant figure it out,
so please if their is anything you can add i will really appreciate your help, Thanks in advance.
here is the code:
//------------------------------------------------------------------
#property copyright "Umar Binaslam"
#property link "aliscoderx2030@gmail.com"
#property version "1.00"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrRed
#property indicator_color2 clrBlue
#property indicator_width1 2
#property indicator_width2 2
#property strict
//
//
//
extern int FractalPeriod = 7; // Fractal period: 5 for built in fractal
extern ENUM_APPLIED_PRICE PriceHigh = PRICE_HIGH; // Price high
extern ENUM_APPLIED_PRICE PriceLow = PRICE_LOW; // Price low
extern double UpperArrowDisplacement = 0.2; // Upper arrow displacement
extern double LowerArrowDisplacement = 0.2; // Lower arrow displacement
extern int period = 0;
extern double deviation = 2;
extern int shift = 2;
extern double apply = PRICE_CLOSE;
extern bool DisplayAlerts = true;
static datetime TimeStamp;
static int AlertCount = 1;
double v1[],v2[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
int OnInit()
{
if (MathMod(FractalPeriod,2)==0) FractalPeriod = FractalPeriod+1;
SetIndexBuffer(0,v1); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,159);
SetIndexBuffer(1,v2); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,159);
IndicatorShortName("FractalsAD");
return(INIT_SUCCEEDED);
}
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[])
{
int limit=MathMin(MathMax(rates_total-prev_calculated,FractalPeriod),rates_total-1);
//
//
//
//
//
double b,s;/*BBLowCurrent,
BBLowPrevious,
BBUpCurrent,
BBUpPrevious,
BBCurrentClose,
BBPreviousClose;
bool Uptrend;
bool Downtrend;*/
//bool Downtrend;
int half = FractalPeriod/2;
for(int i=limit; i>=half && !_StopFlag; i--)
{
b = iBands(NULL, 0, period, deviation, shift, apply, MODE_LOWER, i);
s = iBands(NULL, 0, period, deviation, shift, apply, MODE_UPPER,i);
// BBUpCurrent = iBands(NULL, 0, period, deviation, shift, apply, MODE_UPPER, 0);
//BBUpPrevious = iBands(NULL, 0, period, deviation, shift, apply, MODE_UPPER, 1);
//BBCurrentClose = iClose (NULL, 0,0);
//BBPreviousClose = iClose (NULL, 0,1);
/*Uptrend ==false;
Downtrend == false;
double Buy =if (BBLowPrevious < BBPreviousClose && BBLowCurrent >= BBCurrentClose )
{
Uptrend == true;
}
double Sell = if (BBUpPrevious > BBPreviousClose && BBUpCurrent <= BBCurrentClose )
{
Downtrend == true;
}*/
bool found = true;
double compareTo = iMA(NULL,0,1,0,MODE_SMA,PriceHigh,i);
for (int k=1; k<=half; k++)
{
if ( (i+k)<rates_total && iMA(NULL,0,1,0,MODE_SMA,PriceHigh,i+k)> compareTo) { found=false; break; }
if ((i-k)>=0 && iMA(NULL,0,1,0,MODE_SMA,PriceHigh,i-k)>=compareTo) { found=false; break; }
}
if (found && s <= Close[i] )// && s <= Close[i] && Open[i] <=s && s <= Close[i])
v1[i] = high[i]+iATR(NULL,0,20,i)*UpperArrowDisplacement;
if(DisplayAlerts)
{
// On new bar closing
if(TimeStamp != Time[0])
{
// Check buy signal
if(v1[i] != 0 &&
v1[i] != EMPTY_VALUE &&
AlertCount == 0)
{
Alert("Fractal_Filter "+" ["+ Symbol() +"] BUY");
}
}
}
else v1[i] = EMPTY_VALUE;
//
//&& s <= Close[i] && Open[i] <=s && s <= Close[i
//found && Close[0] < b && Open[0] >= b && b >= Close[0]
found = true;
compareTo = iMA(NULL,0,1,0,MODE_SMA,PriceLow,i);
for (int k=1; k<=half; k++)
{
if ((i+k)<rates_total && iMA(NULL,0,1,0,MODE_SMA,PriceLow,i+k)< compareTo) { found=false; break; }
if ((i-k)>=0 && iMA(NULL,0,1,0,MODE_SMA,PriceLow,i-k)<=compareTo) { found=false; break; }
}
if (found && Close[i] <= b)
v2[i] = low[i]-iATR(NULL,0,20,i)*LowerArrowDisplacement;
if(DisplayAlerts)
{
// On new bar closing
if(TimeStamp != Time[0])
{
if(v2[i] != 0 &&
v2[i] != EMPTY_VALUE &&
AlertCount == 0) {
Alert("Fractal_Filter "+"["+ Symbol() +"] SELL");
}
}
}
else v2[i] = EMPTY_VALUE;
TimeStamp = Time[0];
AlertCount = 0;
// Alerts
/*if(DisplayAlerts)
{
// On new bar closing
if(TimeStamp != Time[0])
{
// Check buy signal
if(v1[i] != 0 &&
v1[i] != EMPTY_VALUE &&
AlertCount == 0)
{
Alert("Fractal_Filter "+" ["+ Symbol() +"] Buy");
// Check sell signal
} else if(v2[i] != 0 &&
v2[i] != EMPTY_VALUE &&
AlertCount == 0) {
Alert("Fractal_Filter "+"["+ Symbol() +"] Sell");
}
TimeStamp = Time[0];
AlertCount = 0;
}
}*/
}
return(rates_total);
}