Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader Indicators

MetaTrader Indicators Post and discuss the MetaTrader indicators here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 30th January 2010, 12:03
Default Avatar
Member
 
Join Date: Dec 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom MovingAverage for MT5

Hi to everybody!

This attached Custom MovingAverage has, as far as I can see, no option yet for price parameter.

I would like to use also high and low e.g.

Can anybody give me a hint how to get this option?

Is this a hidden feature in the code or do I have to change the code?

Thanks in advance.
Attached Files
File Type: mq5 Custom Moving Average.mq5 (7.1 KB, 7 views)
Reply With Quote
  #2 (permalink)  
Old 30th January 2010, 19:27
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,446
Thanks: 6
Thanked 8 Times in 7 Posts
Default

1. The OnCalculate() function should redeclared for more input parameters:

MQL5 Code:
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[])

2. Add the input parameter for price type.

3. Inside the OnCalculate() function check the input type and send he appropriate price array (open/close/high/low) instead of the "price" array to MA calculate functions.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #3 (permalink)  
Old 30th January 2010, 23:19
Default Avatar
Member
 
Join Date: Dec 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the advice.

did the following: changed on Calculate in this way
-------------------------------------------------------
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[]
const int begin,
const double &price[])
{
//--- check for bars count
if(rates_total<InpMAPeriod-1+begin)
return(0);// not enough bars for calculation
//--- first calculation or number of bars was changed
if(prev_calculated==0)
ArrayInitialize(ExtLineBuffer,0);
//--- sets first bar from what index will be draw
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1+begin);

//--- calculation
ArraySetAsSeries(close, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);

ENUM_APPLIED_PRICE myMA_Price;

switch(InpMAPrice) {
case PRICE_CLOSE : myMA_Price=close; break;
case PRICE_OPEN : myMA_Price=open; break;
case PRICE_HIGH : myMA_Price=high; break;
case PRICE_LOW : myMA_Price=low; break;
case PRICE_MEDIAN : myMA_Price=(high+low)/2; break;
case PRICE_TYPICAL : myMA_Price=(high+low+close)/3; break;
case PRICE_WEIGHTED : myMA_Price=(high+low+close+close)/4;
}
switch(InpMAMethod)
{
case MODE_EMA: CalculateEMA(rates_total,prev_calculated,begin,myM A_Price); break;
case MODE_LWMA: CalculateLWMA(rates_total,prev_calculated,begin,my MA_Price); break;
case MODE_SMMA: CalculateSmoothedMA(rates_total,prev_calculated,be gin,myMA_Price); break;
case MODE_SMA: CalculateSimpleMA(rates_total,prev_calculated,begi n,myMA_Price); break;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
-------------------------------------

is this correct or are there any mistakes in the code?

Last edited by fxwalb; 31st January 2010 at 06:02.
Reply With Quote
  #4 (permalink)  
Old 31st January 2010, 08:12
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,446
Thanks: 6
Thanked 8 Times in 7 Posts
Default

First, I am not sure if you need to set the price arrays as timeseries.

Second, you can't add or divide arrays. So, in your switch/case construction you have to run cycles through all price array and reassign each element of the array accordingly.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MovingAverage Bounce Signal (+Automatic Stop Loss) ChartSecret MetaTrader Indicators 0 26th September 2009 12:09


All times are GMT. The time now is 02:25.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2