Forex
Google

Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2006, 01:51 AM
RJames5541 RJames5541 is offline
Junior Member
 
Join Date: Jul 2006
Posts: 15
RJames5541 is on a distinguished road
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);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-20-2006, 02:06 AM
Maji Maji is offline
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
The variable is:

//---- input parameters
extern int ADXPeriod=14;

Change the value from 14 to whatever period you want to.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-20-2006, 02:31 AM
RJames5541 RJames5541 is offline
Junior Member
 
Join Date: Jul 2006
Posts: 15
RJames5541 is on a distinguished road
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-?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-20-2006, 02:53 AM
Maji Maji is offline
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-20-2006, 03:32 AM
RJames5541 RJames5541 is offline
Junior Member
 
Join Date: Jul 2006
Posts: 15
RJames5541 is on a distinguished road
Thanks!!!

Thank you very much! ... That worked very well!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-20-2006, 04:08 AM
RJames5541 RJames5541 is offline
Junior Member
 
Join Date: Jul 2006
Posts: 15
RJames5541 is on a distinguished road
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);
}
//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-20-2006, 04:31 AM
iscuba11's Avatar
iscuba11 iscuba11 is offline
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 400
iscuba11 is on a distinguished road
Smile

I cannot help you with your programming. But I am attaching this indicator and maybe it will help you.

Dave
<><<
Attached Files
File Type: mq4 bbsqueeze.mq4 (4.2 KB, 41 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-25-2006, 11:06 PM
hidethereal hidethereal is offline
Member
 
Join Date: Apr 2006
Posts: 54
hidethereal is on a distinguished road
Quote:
Originally Posted by Maji
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
Can someone post the compiled version of this? I need to be able to change the DI+ DI- levels but I get errors when I attempt to compile this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-26-2006, 08:50 AM
FX_Sniper's Avatar
FX_Sniper FX_Sniper is offline
Senior Member
 
Join Date: Jan 2006
Location: South Africa
Posts: 201
FX_Sniper is on a distinguished road
Here you go, knock yourself out

ADX will even change color depending on it's direction

Happy Hunting

FX Sniper
Attached Images
File Type: jpg adx.jpg (54.5 KB, 211 views)
Attached Files
File Type: ex4 FX Sniper's ADX Mod.ex4 (3.7 KB, 99 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-31-2006, 02:31 PM
hidethereal hidethereal is offline
Member
 
Join Date: Apr 2006
Posts: 54
hidethereal is on a distinguished road
Quote:
Originally Posted by FX_Sniper
Here you go, knock yourself out

ADX will even change color depending on it's direction

Happy Hunting

FX Sniper
I have the DMI indicator and was curious if you could modify the adx line to change colors like the one you have? I find the DMI more accurate than mt4 adx.

Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


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


All times are GMT. The time now is 02:43 PM.