|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Simple Question For Mql4 Programers: Changing The Di+ And Di- Periods Of Adx
I HAVE HERE THE MQL4 CODE FOR ADX... WHERE WOULD I CHANGE THE PERIOD OF THE DI+ AND DI-?
//+------------------------------------------------------------------+ //| ADX Ghostrider.mq4 | //| Copyright © 2006, Ghostrider Capital LLC. | //| ryanjmcgregor@tds.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Ghostrider Capital LLC." #property link "ryanjmcgregor@tds.net" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 LightSeaGreen #property indicator_color2 YellowGreen #property indicator_color3 Wheat //---- input parameters extern int ADXPeriod=14; //---- buffers double ADXBuffer[]; double PlusDiBuffer[]; double MinusDiBuffer[]; double PlusSdiBuffer[]; double MinusSdiBuffer[]; double TempBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 3 additional buffers are used for counting. IndicatorBuffers(6); //---- indicator buffers SetIndexBuffer(0,ADXBuffer); SetIndexBuffer(1,PlusDiBuffer); SetIndexBuffer(2,MinusDiBuffer); SetIndexBuffer(3,PlusSdiBuffer); SetIndexBuffer(4,MinusSdiBuffer); SetIndexBuffer(5,TempBuffer); //---- name for DataWindow and indicator subwindow label IndicatorShortName("ADX("+ADXPeriod+")"); SetIndexLabel(0,"ADX"); SetIndexLabel(1,"+DI"); SetIndexLabel(2,"-DI"); //---- SetIndexDrawBegin(0,ADXPeriod); SetIndexDrawBegin(1,ADXPeriod); SetIndexDrawBegin(2,ADXPeriod); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 ); //---- return(0); } //+------------------------------------------------------------------+ //| Average Directional Movement Index | //+------------------------------------------------------------------+ int start() { double pdm,mdm,tr; double price_high,price_low; int starti,i,counted_bars=IndicatorCounted(); //---- i=Bars-2; PlusSdiBuffer[i+1]=0; MinusSdiBuffer[i+1]=0; if(counted_bars>=i) i=Bars-counted_bars-1; starti=i; //---- while(i>=0) { price_low=Low[i]; price_high=High[i]; //---- pdm=price_high-High[i+1]; mdm=Low[i+1]-price_low; if(pdm<0) pdm=0; // +DM if(mdm<0) mdm=0; // -DM if(pdm==mdm) { pdm=0; mdm=0; } else if(pdm<mdm) pdm=0; else if(mdm<pdm) mdm=0; //---- вычисляем истинный интервал double num1=MathAbs(price_high-price_low); double num2=MathAbs(price_high-Close[i+1]); double num3=MathAbs(price_low-Close[i+1]); tr=MathMax(num1,num2); tr=MathMax(tr,num3); //---- counting plus/minus direction if(tr==0) { PlusSdiBuffer[i]=0; MinusSdiBuffer[i]=0; } else { PlusSdiBuffer[i]=100.0*pdm/tr; MinusSdiBuffer[i]=100.0*mdm/tr; } //---- i--; } //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; int limit=Bars-counted_bars; //---- apply EMA to +DI for(i=0; i<=limit; i++) PlusDiBuffer[i]=iMAOnArray(PlusSdiBuffer,Bars,ADXPeriod,0,MODE_EM A,i); //---- apply EMA to -DI for(i=0; i<=limit; i++) MinusDiBuffer[i]=iMAOnArray(MinusSdiBuffer,Bars,ADXPeriod,0,MODE_E MA,i); //---- Directional Movement (DX) i=Bars-2; TempBuffer[i+1]=0; i=starti; while(i>=0) { double div=MathAbs(PlusDiBuffer[i]+MinusDiBuffer[i]); if(div==0.00) TempBuffer[i]=0; else TempBuffer[i]=100*(MathAbs(PlusDiBuffer[i]-MinusDiBuffer[i])/div); i--; } //---- ADX is exponential moving average on DX for(i=0; i<limit; i++) ADXBuffer[i]=iMAOnArray(TempBuffer,Bars,ADXPeriod,0,MODE_EMA,i ); //---- return(0); |
|
|||
|
I have tried altering that already
I have already experimented with changing the line: extern int ADXPeriod=14;...... As you probably already know, the ADX indicator is comprised of 3 lines; the main ADX line, as well as two other lines (DI+ and DI-). It turns out that changing 14 to another period only alters the period of the main ADX Line... I am trying to change the periods of the two other lines plotted on the ADX indicator (the DI+ and DI-)... It is not possible to do this in the indicators properties window in the trading terminal... where in the above MQL4 Code might I be able to change the periods of the DI+ and DI-?
|
|
|||
|
Create another Variable like this just below the ADXPeriod
extern int DIPeriod = 5; Now go to the following lines: PlusDiBuffer[i]=iMAOnArray(PlusSdiBuffer,Bars,ADXPeriod,0,MODE_EM A,i); and MinusDiBuffer[i]=iMAOnArray(MinusSdiBuffer,Bars,ADXPeriod,0,MODE_E MA,i); change ADXPeriod to DIPeriod. Hope this helps. Maji |
|
|||
|
I am trying to write a program to plot the bandwidth between upper and lower bollinger bands. The program seems to be executing all of the math correctly since when I load the indicator into the trading terminal the value of the indicator (bandwidth) is displayed in the upper left corner of the indicator window. Unfortunately, no line is charted in the indicator window. Why might this be happening? any help would be great! ..... The code I have written so far is below:
Thanks, Ryan //+------------------------------------------------------------------+ //| Band Width of Bollinger Bands .mq4 | //| Copyright © 2006, Ghostrider Capital LLC. | //| ryanjmcgregor@tds.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Ghostrider Capital LLC." #property link "ryanjmcgregor@tds.net" #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 DodgerBlue #property indicator_maximum 1.5 #property indicator_minimum -0.5 //---- indicator parameters extern int BandsPeriod=20; extern int BandsShift=0; extern double BandsDeviations=2.0; //---- buffers //---- Moving, Upper, and Lower are for counting to draw Band Width 60 double BandWidth60Buffer[]; double MovingBuffer[]; double UpperBuffer[]; double LowerBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,DodgerBlue ); SetIndexBuffer(0,BandWidth60Buffer); SetIndexLabel(0,"Band Width 20"); SetIndexBuffer(1,MovingBuffer); SetIndexBuffer(2,UpperBuffer); SetIndexBuffer(3,LowerBuffer); //---- //---- 4 Indicators Buffers Mapping SetIndexDrawBegin(0,0); // SetIndexDrawBegin(1,BandsPeriod+BandsShift); // SetIndexDrawBegin(2,BandsPeriod+BandsShift); // SetIndexDrawBegin(3,BandsPeriod+BandsShift); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 ); IndicatorShortName("Band Width of 20 2.0 BB"); //---- return(0); } //+------------------------------------------------------------------+ //| Bollinger Bands | //+------------------------------------------------------------------+ int start() { int i,k,counted_bars=IndicatorCounted(); double deviation; double sum,oldval,newres,upper,lower,middle; //---- if(Bars<=BandsPeriod) return(0); //---- initial zero if(counted_bars<1) for(i=1;i<=BandsPeriod;i++) { MovingBuffer[Bars-i]=EMPTY_VALUE; UpperBuffer[Bars-i]=EMPTY_VALUE; LowerBuffer[Bars-i]=EMPTY_VALUE; BandWidth60Buffer[Bars-i]=EMPTY_VALUE; } //---- int limit=Bars-counted_bars; if(counted_bars>0) limit++; for(i=0; i<limit; i++) MovingBuffer[i]=iMA(NULL,0,BandsPeriod,BandsShift,MODE_SMA,PRICE_ CLOSE,i); middle=MovingBuffer[i]; //---- i=Bars-BandsPeriod+1; if(counted_bars>BandsPeriod-1) i=Bars-counted_bars-1; while(i>=0) { sum=0.0; k=i+BandsPeriod-1; oldval=MovingBuffer[i]; while(k>=i) { newres=Close[k]-oldval; sum+=newres*newres; k--; } deviation=BandsDeviations*MathSqrt(sum/BandsPeriod); UpperBuffer[i]=oldval+deviation; LowerBuffer[i]=oldval-deviation; upper=UpperBuffer[i]; lower=LowerBuffer[i]; //---- Formula Band Width = (Upper - Lower) / Middle Band moving sma BandWidth60Buffer[i]=(upper-lower)/middle; i--; } //---- return(0); } //+------------------------------------------------------------------+ |
|
|||
|
Quote:
|
|
|||
|
Quote:
Thanks in advance! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Flexible time periods | Thruline | Indicators - Metatrader 4 | 2 | 02-20-2007 05:16 AM |
| Simple (i think) question RE iMA | bwilhite | Metatrader 4 | 3 | 09-08-2006 04:30 PM |
| A simple question from a newbye | tradetrade | Metatrader 4 | 1 | 07-18-2006 07:08 AM |
| Simple question of determining the time of day | Fishtank | Metatrader 4 | 2 | 04-04-2006 04:12 AM |
| my first EA, simple question | ycomp | Metatrader 4 | 3 | 01-24-2006 05:46 PM |