Indicator for a specific symbol

 

Hello,

I am trying to make an indicator from CCI.

It has to return 1 blue  when CCI is above 0,

                   and 1 red when CCI is below 0.

Very easy stuff. But I would like it to takes value from a different symbol.

So i have use  : input string Symb = "EURUSD";

I don't know how to put that in the "Calculate" section.

I am not a coder, if someone may help It would be nice.

Thank you.

Here is the code :


//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2

#property indicator_type1 DRAW_HISTOGRAM
#property indicator_style1 STYLE_SOLID
#property indicator_width1 5
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_HISTOGRAM
#property indicator_style2 STYLE_SOLID
#property indicator_width2 5
#property indicator_color2 0x0000FF
#property indicator_label2 ""

//--- indicator buffers
double Buffer1[];
double Buffer2[];
input string Symb = "EURUSD";
extern int PeriodCCi = 10;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | CCI1 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
      ArrayInitialize(Buffer2, EMPTY_VALUE);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      
      //Indicator Buffer 1
      if(iCCI(NULL, PERIOD_CURRENT, PeriodCCi, PRICE_CLOSE, i) > 0 //Commodity Channel Index > fixed value
      )
        {
         Buffer1[i] = 1; //Set indicator value at fixed value
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      if(iCCI(NULL, PERIOD_CURRENT, PeriodCCi, PRICE_CLOSE, i) < 0 //Commodity Channel Index < fixed value
      )
        {
         Buffer2[i] = 1; //Set indicator value at fixed value
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+-----------------------------------------------------------------

-+

 
Hello Ben, how you doing?
Just replace:
iCCI(NULL,
by 
iCCI(Symb,

I'm answering from my phone so I could not test, but that should be enough.
 
Ramon Sobrevals Arce #:
Hello Ben, how you doing?
Just replace:
iCCI(NULL,
by 
iCCI(Symb,

I'm answering from my phone so I could not test, but that should be enough.

  Hello Ramon,

  Thank you very much for answer, I will test it.

 

 
Ramon Sobrevals Arce #:
Hello Ben, how you doing?
Just replace:
iCCI(NULL,
by 
iCCI(Symb,

I'm answering from my phone so I could not test, but that should be enough.

   Well, I am doing well, I hope you are fine too.

   I am testing it and it works perfectly.

   Thank you to have taken time to help me.

   Have a nice day ! :)

 
  1. Ben2097: I am trying to make an indicator from CCI.

    if(iCCI(NULL, PERIOD_CURRENT, PeriodCCi, PRICE_CLOSE, i) > 0

    Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Ramon Sobrevals Arce #: Just replace: iCCI(NULL, by iCCI(Symb,

    On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

            1. I didn't see It was in the wrong place , Next time I will post it in the correct place.

                Thanks.