Download MetaTrader 5
To add comments, please log in or register
Freelance service: the safe way to order a trading robot. Try it!
AntGio51
70
AntGio51 2014.11.10 00:12 
I want to put together Melt 2 indicators RSI-DeMarker! because price error?

I tried to group 2 and RSI indicators DeMarker but it gives me error when compiling Price!

Price is not present in OnCalculate but how do I fix

thanks Franco

 


//+------------------------------------------------------------------+

//|                                                     DeMarker.mq5 |

//|                        Copyright 2009, MetaQuotes Software Corp. |

//|                                              http://www.mql5.com



//-----Fusion Rsi-MeMarker  Franco |

//+------------------------------------------------------------------+

#property copyright "2009, MetaQuotes Software Corp."

#property link      "http://www.mql5.com"

#include <MovingAverages.mqh>

//--- indicator settings

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_plots   1

#property indicator_type1   DRAW_LINE

#property indicator_color1  DodgerBlue

#property indicator_level1  0.3

#property indicator_level2  0.7

//--- input parameters

input int InpDeMarkerPeriod=14; // Period

//--- indicator buffers

double    ExtDeMarkerBuffer[];

double    ExtDeMaxBuffer[];

double    ExtDeMinBuffer[];

double    ExtAvgDeMaxBuffer[];

double    ExtAvgDeMinBuffer[];



#property description "Relative Strength Index"

//--- indicator settings

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_maximum 100

#property indicator_level1 30

#property indicator_level2 70

#property indicator_buffers 3

#property indicator_plots   1

#property indicator_type1   DRAW_LINE

#property indicator_color1  DodgerBlue

//--- input parameters

input int InpPeriodRSI=14; // Period

//--- indicator buffers

double    ExtRSIBuffer[];

double    ExtPosBuffer[];

double    ExtNegBuffer[];

//--- global variable

int       ExtPeriodRSI;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

void OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,ExtDeMarkerBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ExtDeMaxBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(2,ExtDeMinBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(3,ExtAvgDeMaxBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(4,ExtAvgDeMinBuffer,INDICATOR_CALCULATIONS);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,3);

//--- sets first bar from what index will be drawn

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpDeMarkerPeriod);

//--- name for DataWindow and indicator subwindow label

   IndicatorSetString(INDICATOR_SHORTNAME,"DeM("+string(InpDeMarkerPeriod)+")");

//--- initialization done



 if(InpPeriodRSI<1)

     {

      ExtPeriodRSI=12;

      Print("Incorrect value for input variable InpPeriodRSI =",InpPeriodRSI,

            "Indicator will use value =",ExtPeriodRSI,"for calculations.");

     }

   else ExtPeriodRSI=InpPeriodRSI;

//--- indicator buffers mapping

   SetIndexBuffer(0,ExtRSIBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ExtPosBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(2,ExtNegBuffer,INDICATOR_CALCULATIONS);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,2);

//--- sets first bar from what index will be drawn

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodRSI);

//--- name for DataWindow and indicator subwindow label

   IndicatorSetString(INDICATOR_SHORTNAME,"RSI("+string(ExtPeriodRSI)+")");

//--- initialization done

  }

//+------------------------------------------------------------------+

//| DeMarker                                                         |

//+------------------------------------------------------------------+

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[])

  {

   int    iDeM,limit;

   double dNum;

//--- check for bars count

   if(rates_total<InpDeMarkerPeriod)

      return(0);

//--- preliminary calculations

   if(prev_calculated==0)

     {

      ExtDeMaxBuffer[0]=0.0;

      ExtDeMinBuffer[0]=0.0;

      //--- filling out the array of True Range values for each period

      for(iDeM=1;iDeM<InpDeMarkerPeriod;iDeM++)

        {

         if(high[iDeM]>high[iDeM-1]) ExtDeMaxBuffer[iDeM]=high[iDeM]-high[iDeM-1];

         else ExtDeMaxBuffer[iDeM]=0.0;



         if(low[iDeM-1]>low[iDeM]) ExtDeMinBuffer[iDeM]=low[iDeM-1]-low[iDeM];

         else ExtDeMinBuffer[iDeM]=0.0;

        }

      for(iDeM=0;iDeM<InpDeMarkerPeriod;iDeM++) ExtDeMarkerBuffer[iDeM]=0.0;

      limit=InpDeMarkerPeriod-1;

    }

   else limit=prev_calculated-1;

//--- the main loop of calculations

   for(iDeM=limit;iDeM<rates_total && !IsStopped();iDeM++)

     {

      if(high[iDeM]>high[iDeM-1]) ExtDeMaxBuffer[iDeM]=high[iDeM]-high[iDeM-1];

      else ExtDeMaxBuffer[iDeM]=0.0;



      if(low[iDeM-1]>low[iDeM]) ExtDeMinBuffer[iDeM]=low[iDeM-1]-low[iDeM];

      else ExtDeMinBuffer[iDeM]=0.0;



      ExtAvgDeMaxBuffer[iDeM]=SimpleMA(iDeM,InpDeMarkerPeriod,ExtDeMaxBuffer);

      ExtAvgDeMinBuffer[iDeM]=SimpleMA(iDeM,InpDeMarkerPeriod,ExtDeMinBuffer);



      dNum=ExtAvgDeMaxBuffer[iDeM]+ExtAvgDeMinBuffer[iDeM];

      if(dNum!=0) ExtDeMarkerBuffer[iDeM]=ExtAvgDeMaxBuffer[iDeM]/dNum;

      else ExtDeMarkerBuffer[iDeM]=0.0;

     }

//--- OnCalculate done. Return new prev_calculated.



 int    i;

   double diff;

//--- check for rates count

   if(rates_total<=ExtPeriodRSI)

      return(0);

//--- preliminary calculations

   int pos=prev_calculated-1;

   if(pos<=ExtPeriodRSI)

     {

      //--- first RSIPeriod values of the indicator are not calculated

      ExtRSIBuffer[0]=0.0;

      ExtPosBuffer[0]=0.0;

      ExtNegBuffer[0]=0.0;

      double SumP=0.0;

      double SumN=0.0;

      for(i=1;i<=ExtPeriodRSI;i++)

        {

         ExtRSIBuffer[i]=0.0;

         ExtPosBuffer[i]=0.0;

         ExtNegBuffer[i]=0.0;

         diff=price[i]-price[i-1];

         SumP+=(diff>0?diff:0);

         SumN+=(diff<0?-diff:0);

        }

      //--- calculate first visible value

      ExtPosBuffer[ExtPeriodRSI]=SumP/ExtPeriodRSI;

      ExtNegBuffer[ExtPeriodRSI]=SumN/ExtPeriodRSI;

      if(ExtNegBuffer[ExtPeriodRSI]!=0.0)

         ExtRSIBuffer[ExtPeriodRSI]=100.0-(100.0/(1.0+ExtPosBuffer[ExtPeriodRSI]/ExtNegBuffer[ExtPeriodRSI]));

      else

        {

         if(ExtPosBuffer[ExtPeriodRSI]!=0.0)

            ExtRSIBuffer[ExtPeriodRSI]=100.0;

         else

            ExtRSIBuffer[ExtPeriodRSI]=50.0;

        }

      //--- prepare the position value for main calculation

      pos=ExtPeriodRSI+1;

     }

//--- the main loop of calculations

   for(i=pos;i<rates_total && !IsStopped();i++)

     {

      diff=price[i]-price[i-1];

      ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(ExtPeriodRSI-1)+(diff>0.0?diff:0.0))/ExtPeriodRSI;

      ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(ExtPeriodRSI-1)+(diff<0.0?-diff:0.0))/ExtPeriodRSI;

      if(ExtNegBuffer[i]!=0.0)

         ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]);

      else

        {

         if(ExtPosBuffer[i]!=0.0)

            ExtRSIBuffer[i]=100.0;

         else

            ExtRSIBuffer[i]=50.0;

        }

     }



   return(rates_total);

  }

//+------------------------------------------------------------------+

 
Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Stuart Browne
5720
Stuart Browne 2014.11.10 02:15  
Please use the SRC button when posting code. I've fixed it for you this time
AntGio51
70
AntGio51 2014.11.10 11:59  

Dear friend filter I tried to put in code on the SRC, but I do not see the code posted on my post, so I decided to paste the TXT

In the meantime, I ask you something! But why not answer my simple questions, maybe I make some mistake, or do not speak a proper language can give me some advice

Ok thanks Franco

Stuart Browne
5720
Stuart Browne 2014.11.10 23:40  
You haven't declared the price array. Without knowing the indicators you are trying to combine, I can't tell what it is. Try replacing "price" with the Close array
AntGio51
70
AntGio51 2014.11.14 14:47  

With Filter I have tried your advice but it does not work.

The question was simple: you can assemble a single indicator, consisting of 2 or 3 indicators such as RSI + markers + wpr

Thanks again,

that nobody here seems to affect my questions I can not explain why,

other forum get instant answers even on trivial matters.

/
To add comments, please log in or register