Try it like this.
//+------------------------------------------------------------------+ //| Traders Dynamic Index.mq4 | //| Copyright ?2006, Dean Malone | //| www.compassfx.com | //| Conversion for MT4.600 by SDC | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //| Traders Dynamic Index | //| | //| This hybrid indicator is developed to assist traders in their | //| ability to decipher and monitor market conditions related to | //| trend direction, market strength, and market volatility. | //| | //| Even though comprehensive, the T.D.I. is easy to read and use. | //| | //| Green line = RSI Price line | //| Red line = Trade Signal line | //| Blue lines = Volatility Band | //| Yellow line = Market Base Line | //| | //| Trend Direction - Immediate and Overall | //| Immediate = Green over Red...price action is moving up. | //| Red over Green...price action is moving down. | //| | //| Overall = Yellow line trends up and down generally between the | //| lines 32 & 68. Watch for Yellow line to bounces off | //| these lines for market reversal. Trade long when | //| price is above the Yellow line, and trade short when | //| price is below. | //| | //| Market Strength & Volatility - Immediate and Overall | //| Immediate = Green Line - Strong = Steep slope up or down. | //| Weak = Moderate to Flat slope. | //| | //| Overall = Blue Lines - When expanding, market is strong and | //| trending. When constricting, market is weak and | //| in a range. When the Blue lines are extremely tight | //| in a narrow range, expect an economic announcement | //| or other market condition to spike the market. | //| | //| | //| Entry conditions | //| Scalping - Long = Green over Red, Short = Red over Green | //| Active - Long = Green over Red & Yellow lines | //| Short = Red over Green & Yellow lines | //| Moderate - Long = Green over Red, Yellow, & 50 lines | //| Short= Red over Green, Green below Yellow & 50 line | //| | //| Exit conditions* | //| Long = Green crosses below Red | //| Short = Green crosses above Red | //| * If Green crosses either Blue lines, consider exiting when | //| when the Green line crosses back over the Blue line. | //| | //| | //| IMPORTANT: The default settings are well tested and proven. | //| But, you can change the settings to fit your | //| trading style. | //| | //| | //| Price & Line Type settings: | //| RSI Price settings | //| 0 = Close price [DEFAULT] | //| 1 = Open price. | //| 2 = High price. | //| 3 = Low price. | //| 4 = Median price, (high+low)/2. | //| 5 = Typical price, (high+low+close)/3. | //| 6 = Weighted close price, (high+low+close+close)/4. | //| | //| RSI Price Line & Signal Line Type settings | //| 0 = Simple moving average [DEFAULT] | //| 1 = Exponential moving average | //| 2 = Smoothed moving average | //| 3 = Linear weighted moving average | //| | //| Good trading, | //| | //| Dean | //+------------------------------------------------------------------+ #property version "2.00" #property strict #property indicator_buffers 5 #property indicator_color1 MediumBlue #property indicator_color2 Yellow #property indicator_color3 MediumBlue #property indicator_color4 Green #property indicator_color5 Red #property indicator_separate_window input int RSI_Period = 13; //RSI Period (8-25) input ENUM_APPLIED_PRICE RSI_Price=MODE_CLOSE; //RSI Price input int Volatility_Band = 34; //Volatility Band (20-40) input int RSI_Price_Line = 2; //RSI Price Line input ENUM_MA_METHOD RSI_Price_Type=MODE_SMA; //RSI Price Type input int Trade_Signal_Line = 7; //Trade Signal Line input ENUM_MA_METHOD Trade_Signal_Type=MODE_SMA; //Trade Signal Type input bool UseAlerts=false; //Use Alerts double RSIBuf[],UpZone[],MdZone[],DnZone[],MaBuf[],MbBuf[]; int AlertPlayedonBar=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping IndicatorBuffers(6); IndicatorShortName("Traders Dynamic Index"); SetIndexBuffer(0,UpZone,INDICATOR_DATA); SetIndexBuffer(1,MdZone,INDICATOR_DATA); SetIndexBuffer(2,DnZone,INDICATOR_DATA); SetIndexBuffer(3,MaBuf, INDICATOR_DATA); SetIndexBuffer(4,MbBuf, INDICATOR_DATA); SetIndexBuffer(5,RSIBuf,INDICATOR_CALCULATIONS); SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE,0,2); SetIndexStyle(2,DRAW_LINE); SetIndexStyle(3,DRAW_LINE,0,2); SetIndexStyle(4,DRAW_LINE,0,2); SetIndexLabel(0,"VB High"); SetIndexLabel(1,"Market Base Line"); SetIndexLabel(2,"VB Low"); SetIndexLabel(3,"RSI Price Line"); SetIndexLabel(4,"Trade Signal Line"); SetLevelValue(0,50); SetLevelValue(1,68); SetLevelValue(2,32); SetLevelStyle(STYLE_DOT,1,clrSilver); //--- 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[]) { //--- double MA,RSI[]; ArrayResize(RSI,Volatility_Band); int loop = rates_total-prev_calculated; int limit = rates_total-(Volatility_Band+1); if(loop > limit) loop = limit; for(int i=loop; i>=0; i--) { RSIBuf[i]=(iRSI(NULL,0,RSI_Period,RSI_Price,i)); MA=0; for(int x=i; x<i+Volatility_Band; x++) { RSI[x-i]=RSIBuf[x]; MA+=RSIBuf[x]/Volatility_Band; } UpZone[i] = (MA + (1.6185 * StDev(RSI,Volatility_Band))); DnZone[i] = (MA - (1.6185 * StDev(RSI,Volatility_Band))); MdZone[i] = ((UpZone[i] + DnZone[i])/2); } for(int i=limit-1;i>=0;i--) { MaBuf[i] = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i)); MbBuf[i] = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i)); } if((MbBuf[0]>MdZone[0]) && (MbBuf[1]<=MdZone[1]) && (UseAlerts==true) && (AlertPlayedonBar!=Bars)) { Alert("Bullish cross"); PlaySound("alert.wav"); AlertPlayedonBar=Bars; } if((MbBuf[0]<MdZone[0]) && (MbBuf[1]>=MdZone[1]) && (UseAlerts==true) && (AlertPlayedonBar!=Bars)) { Alert("Bearish cross"); PlaySound("alert.wav"); AlertPlayedonBar=Bars; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ double StDev(double &Data[],int Per) { return(MathSqrt(Variance(Data,Per))); } //+------------------------------------------------------------------+ double Variance(double &Data[],int Per) { double sum=0,ssum=0; for(int i=0; i<Per; i++) { sum+=Data[i]; ssum+=MathPow(Data[i],2); } return((ssum*Per - sum*sum)/(Per*(Per-1))); } //+------------------------------------------------------------------+
@ SDC
#property version "1.00"
//#property strict
#property indicator_chart_window ???
or
#property indicator_separate_window ???
Should have been separate window thanks qjol I fixed it.
There is probably an out of range array preventing it running in strict mode I might fix that too later.
Edit: Fixed main loop for the array ranges.
Thank thank you very much
Your welcome I believe it works correctly let us know if it does not.
Hello,
could someone write me:
I am interested only in Yellow line in TDI - Market Base Line.
What is formula for this?
Or maybe enough, is it some SMA? For what?
You know, I am not a programeer and I can write something only in EasyLanguage (TradeStation) so
I would like to know what is behind yellow line.
Thank you in advance.
Vlado
The yellow line is the median price of the two blue lines which use an MA of the RSI and a standard deviation of the RSI and a multiplier 1.6185 which I guess is (loosely) based on fibonachi ratios.
UpZone[i] = (MA + (1.6185 * StDev(RSI,Volatility_Band))); //- blue line DnZone[i] = (MA - (1.6185 * StDev(RSI,Volatility_Band))); //- blue line MdZone[i] = ((UpZone[i] + DnZone[i])/2); //------------------- yellow line
MA of the RSI where Volatility_Band is the periods
for(int x=i; x<i+Volatility_Band; x++) { RSI[x-i]=RSIBuf[x]; MA+=RSIBuf[x]/Volatility_Band; }
Standard deviation of the RSI is calculated in these functions
//+------------------------------------------------------------------+ double StDev(double &Data[],int Per) { return(MathSqrt(Variance(Data,Per))); } //+------------------------------------------------------------------+ double Variance(double &Data[],int Per) { double sum=0,ssum=0; for(int i=0; i<Per; i++) { sum+=Data[i]; ssum+=MathPow(Data[i],2); } return((ssum*Per - sum*sum)/(Per*(Per-1))); } //+------------------------------------------------------------------+
SDC,
is there any difference between Volatility Bands and Bollinger Bands?
It looks similar for me. For first sight, of course :-)
It looks similar but is not the same, bollinger bands are calculated by a standard deviation of a simple moving average. There are a lot of different ways to make bands...
And in your code ( ... which use an MA of the RSI and a standard deviation of the RSI and ...), MA means what type of moving average? Simple or Exponencial or ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone
The indicator in the 610 version, not display properly. How to modify
I am very grateful