Value indicator on opening candle

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
Moderator
3425
GumRai 2016.02.22 01:14 #
 

Does the indicator that you are calling with iCustom have a parameter to operate on Open price?

CCI has this option, so I would have thought that it is possible with the custom indicator.

avatar
63
omissamf 2016.02.22 01:25 #
 
The indicator refers to the CCi and has no reference to the Open Price. The indicator works, but I wish that the alert was referring only to the opening of the candle. If the requirements are met, the arrow will appear that would not disappear even if more before its closure parameters are no longer respected.
Thank you, all, Massimo.
avatar
Moderator
3425
GumRai 2016.02.22 03:41 #
 
   static datetime bar_time=0;
   if(bar_time!=Time[0])
     {
      bar_time=Time[0];
      //CheckCondition and alert if true;
     }
Something like this will only alert at the first tick of a new bar.
avatar
63
omissamf 2016.02.22 09:39 #
 
GumRai:
Something like this will only alert at the first tick of a new bar.

Hello GumRai, you have been very kind, but you have to help me still because I'm really clumsy. I set your el'alert code and the Editor does not give me errors, but does not work. Where am I doing wrong?
Excuse me, but with my skills I can not fix.
Greetings Massimo


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,0);
      ArrayInitialize(Buffer2,0);
     }
   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   
    
   if(BarStart!=Time[0])
     {
      BarStart=Time[0];

      //Indicator Buffer 1
      if( iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, false, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) //CCI Histogram > CCI Histogram
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) //CCI Histogram > CCI Histogram
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) < 0 //CCI Histogram < fixed value
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) < 0 //CCI Histogram < fixed value
        //&& TimeCurrent()>BarStart
       
         )
           {
            Buffer1[i]=Low[i]-iATR(NULL,PERIOD_CURRENT,14,i); //Set indicator value at Candlestick Low - Average True Range
           }
         else
           {
            Buffer1[i]=0;
           }
      //Indicator Buffer 2
      if(iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,false,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,i)<iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,1+i) //CCI Histogram < CCI Histogram
         && iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,1+i)<iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,2+i) //CCI Histogram < CCI Histogram
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) > 0 //CCI Histogram > fixed value
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 2+i) > 0 //CCI Histogram > fixed value
        //&& TimeCurrent()>BarStart
         

         )
           {
            Buffer2[i]=High[i]+iATR(NULL,PERIOD_CURRENT,14,i); //Set indicator value at Candlestick High + Average True Range
           }
         else
           {
            Buffer2[i]=0;
           }
     }
     }
   return(rates_total);
  }
avatar
Moderator
3425
GumRai 2016.02.22 10:03 #
 
You cannot use the check for a new bar when looping through historical bars, it must not be included in the loop.
avatar
63
omissamf 2016.02.22 12:23 #
 
GumRai Hello, thank you very much for your time. I corrected all the code and it seems to work. You could check if it fits?

Thanks for everything, greetings, Massimo.


//+------------------------------------------------------------------+
//|                                                    CCI alert.mq4 |
//|                                                          Massimo |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Massimo"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

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

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0x0000FF
#property indicator_label2 "Sell"


static datetime BarStart=0;

//--- indicator buffers
double Buffer1[];
double Buffer2[];

double myPoint; //initialized in OnInit
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void myAlert(string type,string message)
  {
   if(type=="print")
      Print(message);
   else if(type=="error")
     {
      Print(type+" | Test @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type=="order")
     {
     }
   else if(type=="modify")
     {
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(2);
   SetIndexBuffer(0,Buffer1);
   SetIndexEmptyValue(0,0);
   SetIndexArrow(0,241);
   SetIndexBuffer(1,Buffer2);
   SetIndexEmptyValue(1,0);
   SetIndexArrow(1,242);
   BarStart=TimeCurrent();

//initialize myPoint
   myPoint=Point();
   if(Digits()==5 || Digits()==3)
     {
      myPoint*=10;
     }
   return(INIT_SUCCEEDED);


  }
//_______________________________________________________________

int start(){
if (BarStart !=Time[0]) 
{
  BarStart = Time[0]; 
  //Indicator Buffer 1
      if( iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, false, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 0) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+0) //CCI Histogram > CCI Histogram
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+0) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+0) //CCI Histogram > CCI Histogram
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+0) < 0 //CCI Histogram < fixed value
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+0) < 0 //CCI Histogram < fixed value
       
         )
           {
            Buffer1[0]=Low[0]-10 * myPoint; //Set indicator value at Candlestick Low - Average True Range
           }
         else
           {
            Buffer1[0]=0;
           }
      //Indicator Buffer 2
      if(iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,false,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,0)<iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,1+0) //CCI Histogram < CCI Histogram
         && iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,1+0)<iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,2+0) //CCI Histogram < CCI Histogram
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+0) > 0 //CCI Histogram > fixed value
         && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 2+0) > 0 //CCI Histogram > fixed value
       
         

         )
           {
            Buffer2[0]=High[0]+10 * myPoint;; //Set indicator value at Candlestick High + Average True Range
           }
         else
           {
            Buffer2[0]=0;
           }
     }
     
   return(0);
  }

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

Back to topics list   | 1 2  

To add comments, please log in or register