Forum on trading, automated trading systems and testing trading strategies
How to Start with Metatrader 5
Simon Gniadkowski, 2013.07.24 10:18
How to post code on this forum . . .
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 all
i have very good support and resistence indicator i want to add this to my indicator i m using icustom function but everytime it return 0 please check my code
//+------------------------------------------------------------------+
//| testsupport.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
extern ENUM_TIMEFRAMES SupportResistance_TF=PERIOD_D1;
extern int LB=3;
extern int maxBarsForPeriod=1000;
extern bool showH04=true;
extern bool showD01=true;
extern bool showW01=true;
extern bool showMN1=true;
extern double Min_Distance_Support_Resistance=10;
double res;
double sup;
int bar=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
PivotCalc();
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
void PivotCalc()
{
int i;
res=0; sup=0;
for(i=bar;i<=Bars;i++)
{
double S1=iCustom(Symbol(),SupportResistance_TF,"Spr",LB,maxBarsForPeriod,showH04,showD01,showW01,showMN1,i);
double R1=iCustom(Symbol(),SupportResistance_TF,"Spr",LB,maxBarsForPeriod,showH04,showD01,showW01,showMN1,i+1);
if(res==0 && R1!=EMPTY_VALUE) res=R1;
if(sup==0 && S1!=EMPTY_VALUE) sup=S1;
if(res>0 && sup>0) break;
}
Comment(res + " - " + sup);
}
Spr indicator also attach