Custom Indicator net set the arrows for new bars

Back to topics list To post a new topic, please log in or register
avatar
5
forexstar 2016.02.24 02:16
 

Hi

I was build a Custom Indicator which set buy and sell arrows on the chart with alerts and it was works fine, but when I tried to upgrade the code to MQL4 new build stile with OnCalculate() function the indicator set the arrows to previous bars only in start but not for new bars after it works and don't send alert.

Can any body help me in this


Regards ...    

avatar
Moderator
3404
GumRai 2016.02.24 02:45 #
 
Not without seeing the code.
avatar
5
forexstar 2016.02.24 16:17 #
 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

double BuyBuffer[];
double SellBuffer[];

double SMA, SMAAlert;
double HAOpen, HAClose, HAOpen2, HAClose2;
double HAOpena, HAClosea, HAOpen2a, HAClose2a;
datetime AlertTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//---- indicator buffers mapping  
    IndicatorBuffers(6);
    IndicatorDigits(Digits);
    SetIndexBuffer(0,BuyBuffer);
    SetIndexBuffer(1,SellBuffer); 
      
//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,233); //241 option for different arrow head
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,234); //242 option for different arrow head
    
//---- name for DataWindow
    SetIndexLabel(0,"Buy");
    SetIndexLabel(1,"Sell");
    
   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[])
  {
   ArraySetAsSeries(time,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);  
   int limit, i;
   limit = rates_total-prev_calculated;      
   for (i = 0; i < limit; i++)
   {
      BuyBuffer[i+1]=0;
      SellBuffer[i+1]=0

avatar
12985
WHRoeder 2016.02.24 19:59 #
 
forexstar:
  limit = rates_total-prev_calculated;      
   for (i = 0; i < limit; i++)

The first time prev_calculated == 0 so it processes all bars.

Until a new bar they will be equal and you do nothing.

limit=rates_total-prev_calculated;
if(prev_calculated>0) limit++; // Reprocess last bar.
avatar
5
forexstar 2016.02.25 02:02 #
 

thanks your reply but not worked


avatar
Moderator
3404
GumRai 2016.02.25 03:45 #
 
   limit = rates_total-prev_calculated;      
   for (i = 0; i < limit; i++)
   {
      BuyBuffer[i+1]=0;
      SellBuffer[i+1]=0

when prev_calculated==0

limit=rates_total which is the number of bars on the chart, so limit-1 is the highest index position for the buffers

when i==limit-1,i+1 will give an array out of range error.


The only values assigned to the buffers is zero, in the code that you show, how do you expect it to do anything?

avatar
5
forexstar 2016.02.26 05:03 #
 
GumRai:

when prev_calculated==0

limit=rates_total which is the number of bars on the chart, so limit-1 is the highest index position for the buffers

when i==limit-1,i+1 will give an array out of range error.


The only values assigned to the buffers is zero, in the code that you show, how do you expect it to do anything?

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

double BuyBuffer[];
double SellBuffer[];

 
double SMA, SMAAlert;
double HAOpen, HAClose, HAOpen2, HAClose2;
double HAOpena, HAClosea, HAOpen2a, HAClose2a;
datetime AlertTime;

 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping  
    SetIndexBuffer(0,BuyBuffer);
    SetIndexBuffer(1,SellBuffer); 
      
//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,233); //241 option for different arrow head
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,234); //242 option for different arrow head
    
//---- name for DataWindow
    SetIndexLabel(0,"Buy");
    SetIndexLabel(1,"Sell");
//---- 
    
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
      ObjectsDeleteAll();
//----
   return(0);
  }
  


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit, i, counter;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
  // if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for (i = 0; i <= limit; i++)
   {
      BuyBuffer[i+1]=0;
      SellBuffer[i+1]=0;
     
}
This is my previous code and it was works fine, can you please show me how to convert it to new code style in the right way  
avatar
Moderator
3404
GumRai 2016.02.26 08:24 #
 
forexstar:

I don't see how your previous indicator works fine. I refer you to my earlier reply

GumRai:

The only values assigned to the buffers is zero, in the code that you show, how do you expect it to do anything?

.

avatar
5
forexstar 2016.02.26 14:35 #
 
GumRai:

I don't see how your previous indicator works fine. I refer you to my earlier reply

.

show me how to write the right loop
avatar
Moderator
3404
GumRai 2016.02.26 14:49 #
 
forexstar:
show me how to write the right loop

How can I?

I have no idea what you are trying to do.

Back to topics list  

To add comments, please log in or register