Custom Indicator

To add comments, please log in or register
gianvitomercorillo
19
gianvitomercorillo  

Hi guys, I have a problem with my custom indicator:

Then the indicator should mark if there was a band riding so I created a BandRiding.mql4 indicator that works the trend if it is higher or lower than% B

after which in the second indicator acquires the data of the first and if in present trend prints an blue arrow or otherwise red arrow placed in code of both

the problem is that in backtest not found but in visual it's correct i nneed this for use in expert..


Thanks a lot ..



//+------------------------------------------------------------------+
//|                                            Band_Riding_Trend.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//#property strict

#property indicator_separate_window
#property  indicator_buffers 2

#property indicator_color1 clrBlue
#property indicator_color2 clrRed

#property indicator_maximum 2
#property indicator_minimum 0
//---- input parameters
extern int Periodo_BB               = 20;
extern double Dev_BB                = 2.0;
extern int Range_Barre_Band_Riding  = 10;
extern int Range_Barre_Band_Riding_Chiusura =10;
//---- buffers

double UpperTrendBuffer[];
double LowerTrendBuffer[];
double UpperAfterBuffer[];
double LowerAfterBuffer[];
double UpperBuffer[];
double LowerBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(6);
   SetIndexBuffer(0, UpperTrendBuffer);
   SetIndexBuffer(1, LowerTrendBuffer);
   SetIndexBuffer(2, UpperBuffer);
   SetIndexBuffer(3, UpperAfterBuffer);
   SetIndexBuffer(4, LowerBuffer);
   SetIndexBuffer(5, LowerAfterBuffer);
  
   
   SetIndexStyle(0, DRAW_ARROW,0,5);       //Set the style of our indicator 
   SetIndexArrow(0,246);               //Sets the icon for our indicator
   SetIndexEmptyValue(0,0);            //Sets default empty value
   SetIndexLabel(0,"Upper Trend  ");       
   

   SetIndexStyle(1, DRAW_ARROW,0,5);       //Set the style of our indicator 
   SetIndexArrow(1,248);               //Sets the icon for our indicator
   SetIndexEmptyValue(1,0);            //Sets default empty value
   SetIndexLabel(1,"Lower Trend  ");       
   
  
   
  //SetIndexStyle(1, DRAW_LINE,EMPTY);
   SetIndexDrawBegin(0, Periodo_BB);
   SetIndexDrawBegin(1, Periodo_BB);
   IndicatorShortName("Band Riding Trend ( Periodo " + IntegerToString(Periodo_BB) + ", Deviazione " + DoubleToStr(Dev_BB)  + ")");
   SetIndexLabel(0, " % BB");
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+


int start()
  {
  
    int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);
 
   //contatore per le barre da sommare dopo if se supera -->> after buffer
    
    
    int trendbuy=0;
    int trendsell=0;
    
    int countbuy=0;
    int countsell=0;
    
    int barsTotal = 0;
      for(int i = limit; i >= 0; i--)
      

     
      {
       UpperBuffer[i]= iCustom(Symbol(),0,"polloactionindicator\\BandRiding",Periodo_BB,Dev_BB,Range_Barre_Band_Riding,0,i);
       LowerBuffer[i]= iCustom(Symbol(),0,"polloactionindicator\\BandRiding",Periodo_BB,Dev_BB,Range_Barre_Band_Riding,2,i);
       UpperAfterBuffer[i]= iCustom(Symbol(),0,"polloactionindicator\\BandRiding",Periodo_BB,Dev_BB,Range_Barre_Band_Riding,1,i);
       LowerAfterBuffer[i]= iCustom(Symbol(),0,"polloactionindicator\\BandRiding",Periodo_BB,Dev_BB,Range_Barre_Band_Riding,3,i);
       
       if(UpperBuffer[i]== 1 && UpperAfterBuffer[i]== 1)
       { 
       
    //   UpperTrendBuffer[i] = 1;
    Comment("UUP UAP");
       trendbuy=1;
       trendsell=0;
       
       //if(countbuy > Range_Barre_Band_Riding_Chiusura) LowerTrendBuffer[i] = 0;
       

       }
   
      if(LowerBuffer[i]==1 && LowerAfterBuffer[i]==1)
       { 
      // LowerTrendBuffer[i] = 1;
       Comment("LOW  LAP");
       trendsell=1; 
       trendbuy=0;
       }
       
       if(UpperBuffer[i]==1 && UpperAfterBuffer[i]==0){
       countbuy++;
       if(countbuy > Range_Barre_Band_Riding_Chiusura) trendsell= 0;
       countsell=0;
       }
       
       if(LowerBuffer[i]==1 && LowerAfterBuffer[i]==0){
       countsell++;
       
      
       if(countsell > Range_Barre_Band_Riding_Chiusura) trendbuy= 0;
       countbuy=0;
       }
       
       
       if(trendbuy==1){
       UpperTrendBuffer[i] = 1;
       }
       
       if(trendsell==1){
       LowerTrendBuffer[i] = 1;
       }
       
      
      Print("UpperBuffer  " + UpperBuffer[i] + " LowerBuffer  " + LowerBuffer[i]  + " UpperAfterBuffer  "  + UpperAfterBuffer[i] + "  LowerAfterBuffer  " + LowerAfterBuffer[i] + "  UpperTrendBuffer  " + UpperTrendBuffer[i] + " LowerTrendBuffer " + LowerTrendBuffer[i]);
//Comment("UP    " + DoubleToStr(UpperTrendBuffer[i]) + "LOW  " + DoubleToStr(LowerTrendBuffer[i]));
       
       
       
     }
     
   
     
     
    
  
  
   return(0);
  }


Keith Watford
Moderator
17026
Keith Watford  

Do not double post.

I have deleted your duplicate topic.

gianvitomercorillo
19
gianvitomercorillo  
Keith Watford:

Do not double post.

I have deleted your duplicate topic.

OK I'm apologize for this.. thanks :)

To add comments, please log in or register