Serving Traders Since 2005
|
|
|
|||||||
| MetaTrader Indicators Post and discuss the MetaTrader indicators here. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
1. The OnCalculate() function should redeclared for more input parameters:
MQL5 Code:
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. |
|
||||
|
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. |
|
||||
|
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. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MovingAverage Bounce Signal (+Automatic Stop Loss) | ChartSecret | MetaTrader Indicators | 0 | 26th September 2009 12:09 |