Coding help - page 672

 
mladen:

NWFstudent

Why don't you use original source code for start (bb stop indicator was always for free, no need to use decompiled version, and it is much easier to work with original code)

Thanks for your advice mr mladen.

 

Where can i find the original code? 

 

EDIT: I think i found it, so much more clean readable code, thanks a thousands time.

 

This is it right?:

//+------------------------------------------------------------------+
//|                                               BBands_Stop_v1.mq4 |
//|                           Copyright © 2006, TrendLaboratory Ltd. |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                       E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"
//----
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Chartreuse
#property indicator_color2 Orange
#property indicator_color3 Chartreuse
#property indicator_color4 Orange
#property indicator_color5 Chartreuse
#property indicator_color6 Orange
//---- input parameters
extern int    Length=20;      // Bollinger Bands Period
extern int    Deviation=2;    // Deviation
extern double MoneyRisk=1.00; // Offset Factor
extern int    Signal=1;       // Display signals mode: 1-Signals & Stops; 0-only Stops; 2-only Signals;
extern int    Line=1;         // Display line mode: 0-no,1-yes  
extern int    Nbars=1000;
//---- indicator buffers
double UpTrendBuffer[];
double DownTrendBuffer[];
double UpTrendSignal[];
double DownTrendSignal[];
double UpTrendLine[];
double DownTrendLine[];
double smax[],smin[],bsmax[],bsmin[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   SetIndexBuffer(0,UpTrendBuffer);
   SetIndexBuffer(1,DownTrendBuffer);
   SetIndexBuffer(2,UpTrendSignal);
   SetIndexBuffer(3,DownTrendSignal);
   SetIndexBuffer(4,UpTrendLine);
   SetIndexBuffer(5,DownTrendLine);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);
   SetIndexArrow(2,108);
   SetIndexArrow(3,108);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   short_name="BBands Stop("+Length+","+Deviation+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"UpTrend Stop");
   SetIndexLabel(1,"DownTrend Stop");
   SetIndexLabel(2,"UpTrend Signal");
   SetIndexLabel(3,"DownTrend Signal");
   SetIndexLabel(4,"UpTrend Line");
   SetIndexLabel(5,"DownTrend Line");
//----
   SetIndexDrawBegin(0,Length);
   SetIndexDrawBegin(1,Length);
   SetIndexDrawBegin(2,Length);
   SetIndexDrawBegin(3,Length);
   SetIndexDrawBegin(4,Length);
   SetIndexDrawBegin(5,Length);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Bollinger Bands_Stop_v1                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,shift,trend;
//----
   /*for(shift=Nbars;shift>=0;shift--)
     {
      UpTrendBuffer[shift]=0;
      DownTrendBuffer[shift]=0;
      UpTrendSignal[shift]=0;
      DownTrendSignal[shift]=0;
      UpTrendLine[shift]=EMPTY_VALUE;
      DownTrendLine[shift]=EMPTY_VALUE;
     }
*/     
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   int limit = Bars - counted_bars;
   if(counted_bars==0) limit-=1+1;
   
   int xsize=ArraySize(UpTrendBuffer);  
   ArrayResize(smax,xsize);
   ArrayResize(smin,xsize);
   ArrayResize(bsmax,xsize);
   ArrayResize(bsmin,xsize);
   
   for(shift=limit;shift>=0;shift--)
     {
      smax[shift]=iBands(NULL,0,Length,Deviation,0,PRICE_CLOSE,MODE_UPPER,shift);
      smin[shift]=iBands(NULL,0,Length,Deviation,0,PRICE_CLOSE,MODE_LOWER,shift);
//----
      if (Close[shift]>smax[shift+1]) trend=1;
      if (Close[shift]<smin[shift+1]) trend=-1;
      if(trend>0 && smin[shift]<smin[shift+1]) smin[shift]=smin[shift+1];
      if(trend<0 && smax[shift]>smax[shift+1]) smax[shift]=smax[shift+1];
//----
      bsmax[shift]=smax[shift]+0.5*(MoneyRisk-1)*(smax[shift]-smin[shift]);
      bsmin[shift]=smin[shift]-0.5*(MoneyRisk-1)*(smax[shift]-smin[shift]);
//----
      if(trend>0 && bsmin[shift]<bsmin[shift+1]) bsmin[shift]=bsmin[shift+1];
      if(trend<0 && bsmax[shift]>bsmax[shift+1]) bsmax[shift]=bsmax[shift+1];
      if (trend>0)
        {
         if (Signal>0 && UpTrendBuffer[shift+1]==-1.0)
           {
            UpTrendSignal[shift]=bsmin[shift];
            UpTrendBuffer[shift]=bsmin[shift];
            if(Line>0) UpTrendLine[shift]=bsmin[shift];
           }
         else
           {
            UpTrendBuffer[shift]=bsmin[shift];
            if(Line>0) UpTrendLine[shift]=bsmin[shift];
            UpTrendSignal[shift]=-1;
           }
         if (Signal==2) UpTrendBuffer[shift]=0;
         DownTrendSignal[shift]=-1;
         DownTrendBuffer[shift]=-1.0;
         DownTrendLine[shift]=EMPTY_VALUE;
        }
      if (trend<0)
        {
         if (Signal>0 && DownTrendBuffer[shift+1]==-1.0)
           {
            DownTrendSignal[shift]=bsmax[shift];
            DownTrendBuffer[shift]=bsmax[shift];
            if(Line>0) DownTrendLine[shift]=bsmax[shift];
           }
         else
           {
            DownTrendBuffer[shift]=bsmax[shift];
            if(Line>0)DownTrendLine[shift]=bsmax[shift];
            DownTrendSignal[shift]=-1;
           }
         if (Signal==2) DownTrendBuffer[shift]=0;
         UpTrendSignal[shift]=-1;
         UpTrendBuffer[shift]=-1.0;
         UpTrendLine[shift]=EMPTY_VALUE;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
 
NWFstudent:

Thanks for your advice mr mladen.

 

Where can i find the original code? 

 

EDIT: I think i found it, so much more clean readable code, thanks a thousands time.

 

This is it right?:

Yes, that is the one :)
 
NWFstudent:

Thanks for your advice mr mladen.

 

Where can i find the original code? 

 

EDIT: I think i found it, so much more clean readable code, thanks a thousands time.

 

This is it right?:

NWFstudent

I think this of MLADENs limited bar and this of MRTOOLs line versions are more latest and with mq4 format.

regards


 

Mladen

I’m trying to get the TMA mtf to work in my EA. I got the “tma centered” crossing the 200ma to work but the 1 &-1 of the mtf seems to be earlier for some reason & timely, see my chart.

Can you check my EA. Right now it’s set up to trade on the “TMA mtf” trend buffer #3. It compiles and runs in the tester but no trades & no errors. The only change I made to the TMA mtf is adding the SetIndexLabels. If I load both tmas indicators on a chart they mirror each other.

Appreciate any help

Ray

 
traderduke:

Mladen

I’m trying to get the TMA mtf to work in my EA. I got the “tma centered” crossing the 200ma to work but the 1 &-1 of the mtf seems to be earlier for some reason & timely, see my chart.

Can you check my EA. Right now it’s set up to trade on the “TMA mtf” trend buffer #3. It compiles and runs in the tester but no trades & no errors. The only change I made to the TMA mtf is adding the SetIndexLabels. If I load both tmas indicators on a chart they mirror each other.

Appreciate any help

Ray

That is a problem with recalculating/repainting indicators. You can not use them for signals. Take a look at the way how it works in runtime, and then you shall see why it can not work using that logic in the EA
 
dotmund:
i found this indicator on this site and i found it useful pls can you help me make an EA of it and make it trade immdiately when the arrow appear and close it the close of the next candle meaning it will trade just two candle and it should close if opposite arrow appear. pls
pls help me with this .
 

Hello together.

Can someone help me to add in this Channel-Indikator, how I can hide the upper Channels?!

I just need M1, M5, M15 and don´t understand this code....


 

//+------------------------------------------------------------------+
//|                                                    !channels.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Nikolay Semko SemkoNV@bk.ru"
#property link      "http://www.7ko.org" // in the development of

// praise and scold at: SemkoNV@bk.ru

#property  indicator_chart_window
#property  indicator_buffers 1


#property  indicator_width1  1
#property  indicator_minimum 0
//---- indicator parameters

extern int Start=0;
extern int BarAnaliz=400;
extern double k_shirina=4;
extern int tochnost =50;
extern double filtr = 0.55;
extern double MinShirina = 0;
extern double MaxShirina = 10000;
extern bool luch=true;
extern bool maxmin=true;
extern bool color_fill=true;

//---- indicator buffers

double     Canals[];
double     Shir[];
double     Vertikal[];

double     Shirina[];
double     ShirinaU[];
double     ShirinaD[];
double     CanalR[];
double     CanalL[];
double     Kanals[20][9];

int preBars=0;
int p[9]={43200,10080,1440,240,60,30,15,5,1};
int FinishL;
int tick=0;
int bar=0;
int b=0;
//datetime x1,x2;
double sumPlus=0;
double sumMinus=0;
double yOptR,yOptL;
int prexL=0;
int prexR=0;
double ma=0;
int  prevxR=-5;
int  prevp=0;
int prevper=-5;
double sum1=0;
double sum2=0;
double curdeltaMax=-10000;
double curdeltaMin=10000;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void deinit()
  {
   Comment("");
   for(int i=0;i<20;i++)
     {
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0));
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" UP");
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" DOWN");
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" TRIUP");
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" TRIDown");
      ObjectDelete("Vertical_9_"+DoubleToStr(i,0));
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorDigits(Digits+1);
//---- indicator buffers mapping

   LoadHist();
//---- indicator buffers mapping

//SetIndexBuffer(0,Canals);
//   IndicatorDigits(20);

//---- initialization done
   return(0);
  }
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

int start()
  {
//LoadHist();
   RefreshRates();
//return(0);
   if(preBars == Bars) return(0);
   preBars=Bars;

   int size=Bars;
   ArrayResize(Shirina,size);
   ArrayResize(ShirinaU,size);
   ArrayResize(ShirinaD,size);
   ArrayResize(CanalR,size);
   ArrayResize(CanalL,size);

   ArrayResize(Canals,size);
   ArrayResize(Shir,size);
   ArrayResize(Vertikal,size);

/*double     Shirina[2000];
double     ShirinaU[2000];
double     ShirinaD[2000];
double     CanalR[2000];
double     CanalL[2000];*/

   int j=AllCanals();
   Canals[0]=j;

   if(j>0)
     {
      for(int i=0; i<j; i++)
        {
         Canals[7*i+1] = Kanals[i][0];
         Canals[7*i+2] = Kanals[i][1];
         Canals[7*i+3] = Kanals[i][2];
         Canals[7*i+4] = Kanals[i][3];
         Canals[7*i+5] = Kanals[i][4];
         Canals[7*i+6] = Kanals[i][5]/Point;
         Canals[7*i+7] = Kanals[i][6];
         Canals[7*i+8] = Kanals[i][7];
         Canals[7*i+9] = Kanals[i][8];
        }
      BildCanals(j);
     }
   return(0);
  }
//+------------------------------------------------------------------+
///////////////////////////// Functions //////////////////////////////
//+------------------------------------------------------------------+

int BildCanals(int j)
  {
   string name;
   datetime x1,x2;
   double y1,y2;
//int  color_i[]={Red,Tomato,Yellow,LawnGreen,Green,Aqua,MediumBlue,BlueViolet,FireBrick,BurlyWood,DeepPink,SeaGreen};
   int  color_i[]={C'200,0,0',C'200,100,0',C'160,160,0',C'100,200,0',C'0,200,0',C'0,200,100',C'0,180,180',C'0,60,120',C'0,0,200',C'100,0,200',C'160,0,160',C'160,80,120'};
   int color_i2[]={C'80,0,0', C'80,40,0',  C'60,60,0',  C'40,80,0',  C'0,60,0', C'0,70,50',  C'0,50,50',  C'0,20,40', C'0,0,80', C'40,0,80',  C'50,0,60',  C'60,20,50'};
   for(int i=j;i<20;i++)
     {
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0));
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" UP");
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" DOWN");
      ObjectDelete("Vertical_9_"+DoubleToStr(i,0));
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" TRIUP");
      ObjectDelete("LineCanal9_"+DoubleToStr(i,0)+" TRIDown");
      Kanals[i][2]=0;
      Kanals[i][1]=0;
      Kanals[i][0]=0;
     }

   string comm="Number of channels = ";
   comm=comm+j;
   for(i=0; i<j; i++)
     { comm=comm+"\n"+"Channel ¹ "+DoubleToStr((i+1),0)+" : width - "+DoubleToStr(Kanals[i][0],0)+", channel length -  "+DoubleToStr(Kanals[i][6],0)+" bars on period "+DoubleToStr(Kanals[i][2],0);}
   Comment(comm);

   for(i=0; i<j; i++)
     {
      x1 = iTime(NULL,0,Start);
      y1 = Kanals[i][3];
      if(iTime(NULL,0,(Bars-1))<=iTime(NULL,Kanals[i][2],Kanals[i][1]))
        {
         x2 = iTime(NULL,Kanals[i][2],Kanals[i][1]);
         y2 = Kanals[i][4];
        }
      else
        {
         x2=iTime(NULL,0,(Bars-1));
         if(Kanals[i][6]!=0) y2=y1-((iBarShift(NULL,Kanals[i][2],x2,FALSE)-iBarShift(NULL,Kanals[i][2],x1,FALSE))/Kanals[i][6])*(y1-Kanals[i][4]);
        }

      name="LineCanal9_"+DoubleToStr(i,0);
      if(ObjectFind(name)==-1)
        {
         if(!ObjectCreate(name,OBJ_TREND,0,x2,y2,x1,y1)) Comment("Error 0 = ",GetLastError());
         ObjectSet(name,OBJPROP_RAY,FALSE);

         color col1=color_i[0];
         if((i>=0) && (i<ArraySize(color_i))) col1=color_i[i];

         color col2=color_i2[0];
         if((i>=0) && (i<ArraySize(color_i2))) col2=color_i2[i];

         ObjectSet(name,OBJPROP_COLOR,col1);
         ObjectSet(name,OBJPROP_STYLE,STYLE_DOT);
         ObjectSet(name,OBJPROP_RAY,luch);

         if(maxmin==true)
            ObjectCreate(name+" UP",OBJ_TREND,0,x2,(y2+Point*Kanals[i][7]),x1,(y1+Point*Kanals[i][7]));
         else
            ObjectCreate(name+" UP",OBJ_TREND,0,x2,(y2+k_shirina*Point*Kanals[i][0]),x1,(y1+k_shirina*Point*Kanals[i][0]));
         ObjectSet(name+" UP",OBJPROP_RAY,FALSE);
         ObjectSet(name+" UP",OBJPROP_COLOR,col1);
         ObjectSet(name+" UP",OBJPROP_STYLE,STYLE_DASH);
         ObjectSet(name+" UP",OBJPROP_RAY,luch);

         if(maxmin==true)
            ObjectCreate(name+" DOWN",OBJ_TREND,0,x2,(y2+Point*Kanals[i][8]),x1,(y1+Point*Kanals[i][8]));
         else
            ObjectCreate(name+" DOWN",OBJ_TREND,0,x2,(y2-k_shirina*Point*Kanals[i][0]),x1,(y1-k_shirina*Point*Kanals[i][0]));
         ObjectSet(name+" DOWN",OBJPROP_RAY,FALSE);
         ObjectSet(name+" DOWN",OBJPROP_COLOR,col1);
         ObjectSet(name+" DOWN",OBJPROP_STYLE,STYLE_DASH);
         ObjectSet(name+" DOWN",OBJPROP_RAY,luch);

         if(color_fill==true)
           {
            ObjectCreate(name+" TRIUP",OBJ_TRIANGLE,0,x2,(y2+Point*Kanals[i][7]),x1,(y1+Point*Kanals[i][7]),x2,(y2+Point*Kanals[i][8]));
            ObjectSet(name+" TRIUP",OBJPROP_COLOR,col2);
            ObjectCreate(name+" TRIDown",OBJ_TRIANGLE,0,x1,(y1+Point*Kanals[i][7]),x1,(y1+Point*Kanals[i][8]),x2,(y2+Point*Kanals[i][8]));
            ObjectSet(name+" TRIDown",OBJPROP_COLOR,col2);
           }

         if(!ObjectCreate("Vertical_9_"+DoubleToStr(i,0),OBJ_VLINE,0,x2,8)) Comment("Îøèáêà 0 = ",GetLastError());
         ObjectSet("Vertical_9_"+DoubleToStr(i,0),OBJPROP_COLOR,col1);
         ObjectSet("Vertical_9_"+DoubleToStr(i,0),OBJPROP_STYLE,STYLE_DOT);
        }
      else
        {
         if(!ObjectMove(name,0,x2,y2)) Comment("Îøèáêà 1 = ",GetLastError());
         if(!ObjectMove(name,1,x1,y1)) Comment("Îøèáêà 2 = ",GetLastError());

         if(maxmin==true)
           {
            ObjectMove(name+" UP",0,x2,y2+Point*Kanals[i][7]);
            ObjectMove(name+" UP",1,x1,y1+Point*Kanals[i][7]);

            ObjectMove(name+" DOWN",0,x2,y2+Point*Kanals[i][8]);
            ObjectMove(name+" DOWN",1,x1,y1+Point*Kanals[i][8]);

            if(color_fill==true)
              {
               ObjectMove(name+" TRIUP",0,x2,(y2+Point*Kanals[i][7]));
               ObjectMove(name+" TRIUP",1,x1,(y1+Point*Kanals[i][7]));
               ObjectMove(name+" TRIUP",2,x2,(y2+Point*Kanals[i][8]));

               ObjectMove(name+" TRIDown",0,x1,(y1+Point*Kanals[i][7]));
               ObjectMove(name+" TRIDown",1,x1,(y1+Point*Kanals[i][8]));
               ObjectMove(name+" TRIDown",2,x2,(y2+Point*Kanals[i][8]));
              }
           }
         else
           {
            ObjectMove(name+" UP",0,x2,y2+k_shirina*Point*Kanals[i][0]);
            ObjectMove(name+" UP",1,x1,y1+k_shirina*Point*Kanals[i][0]);

            ObjectMove(name+" DOWN",0,x2,y2-k_shirina*Point*Kanals[i][0]);
            ObjectMove(name+" DOWN",1,x1,y1-k_shirina*Point*Kanals[i][0]);
           }
        }

     }
   return(0);
  }
////////////////////////////////////////////////////////
int AllCanals()
  {
   int i1=0,i2,i3;
   int k=0;
   int i=0;
   int lastper;
   int St,Fin;
   datetime S,F,prevS,CurStart;
   int lastmin;
   double lmin;
   double premin;
//ArrayInitialize(Kanals,0);
   lastper=9;

   CurStart=iTime(NULL,Period(),Start);
   if(Start==0) CurStart=iTime(NULL,1,0);
   prevS=iTime(NULL,p[0],(iBarShift(NULL,p[0],CurStart,FALSE)+BarAnaliz));
//ArrayInitialize(Vertikal,0);
//ArrayInitialize(Shir,0);

   for(int jj=0;jj<lastper;jj++)
     {
      //ArrayInitialize(Shirina,0);
      if(jj==8)
         S = CurStart;
      else S=iTime(NULL,p[jj+1],(iBarShift(NULL,p[jj+1],CurStart,FALSE)+BarAnaliz));
      F=prevS;
      prevS=S;
      St=iBarShift(NULL,p[jj],CurStart,FALSE);
      Fin=iBarShift(NULL,p[jj],F,FALSE);

      if(St==0 && Fin==0)  return(0);
      if(jj!=8) {ArrShirina(St,Fin,(iBarShift(NULL,p[jj],S,FALSE))-St-7,p[jj]); }//Print("1111111111  ",p[jj],"   ", St,"   ", Fin,"   ",(iBarShift(NULL,p[jj],S,FALSE))-St-7);}
      else  {ArrShirina(St,Fin,0,p[jj]);}// Print("888888888  ",p[jj],"   ", St,"   ", Fin);}
      lastmin=Fin+1;
      if(jj==0) lmin=10000000;
      if(jj==0) premin=Shirina[Fin-St-1];
      // Print(Start,"  ",p[jj],"  Ñòàðò - ",(iBarShift(NULL,p[jj],S,FALSE)),"  Ôèíèø - ",Fin);
      if(Fin>iBarShift(NULL,p[jj],S,FALSE))
         for(i=Fin-1; i>(iBarShift(NULL,p[jj],S,FALSE))-1; i--)
           {
            if(iTime(NULL,0,Bars-1)<=iTime(NULL,p[jj],i))
              {
               i3=iBarShift(NULL,0,iTime(NULL,p[jj],i),FALSE);
               for(i2=0;i2<=p[jj]/Period();i2++)
                 {
                  if(((i3-i2)>=0) && ((i3-i2)<ArraySize(Shir)))
                     if(((i-St)>=0) && ((i-St)<ArraySize(Shirina)))
                       {
                        Shir[i3-i2]=Shirina[i-St];
                       }
                 }
              }

            if(((i-St)>=0) && ((i-St)<ArraySize(Shirina)))
              {
               if(Shirina[i-St]<lmin) {lmin=Shirina[i-St];lastmin=i;}
              }

            if(((i-St)>=0) && ((i-St)<ArraySize(Shirina)))
               if((((i-St-1)>=0) && ((i-St-1)<ArraySize(Shirina))) && (((i-St+1)>=0) && ((i-St+1)<ArraySize(Shirina))))
                  if(Shirina[i-St]<=Shirina[i-St-1] && Shirina[i-St]<=Shirina[i-St+1])
                    {
                     if(lastmin==i)
                       {
                        if(Shirina[i-St]<premin*filtr && Shirina[i-St]>MinShirina && Shirina[i-St]<MaxShirina)
                          {
                           if(i1>0) for(k=0; k<i1; k++)
                             {
                              if(Shirina[i-St]!=0) if((Kanals[k][0]/Shirina[i-St])<1.2 && (Kanals[k][0]/Shirina[i-St])>0.8) i1=k;
                             }
                           if(iTime(NULL,0,Bars-1)<=iTime(NULL,p[jj],i)) Vertikal[i1]=i3;
                           Kanals[i1][0]= Shirina[i-St];
                           Kanals[i1][1]= i;
                           Kanals[i1][2]= p[jj];
                           Kanals[i1][3]= CanalR[i-St];
                           Kanals[i1][4]= CanalL[i-St];
                           if((i-St)*p[jj]!=0) Kanals[i1][5]=(CanalR[i-St]-CanalL[i-St])/((i-St)*p[jj]);
                           Kanals[i1][6]= (i-St);
                           Kanals[i1][7]= ShirinaU[i-St];
                           Kanals[i1][8]= ShirinaD[i-St];
                           premin=Shirina[i-St];
                           i1++;
                          }
                       }
                    }
           }
     }
   return(i1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//////////////////////////////////////////////////////////////////////
double ArrShirina(int Start1,int Finish,int Sdvig,int per)
  {
   Shirina[0]=0;
   if(Sdvig<0) Sdvig=0;
   yOptR=iOpen(NULL,per,Start1);

   int d,i1;
   double dC,dR,dL;
   int p=0;
   int lnz=Sdvig;
//Print("Start  ",Start1,"Finish   ",Finish);
   for(int i=(1+Sdvig); i<(Finish-Start1); i++)
     {
      //x2 = iTime(NULL,per,i);
      if(tochnost!=0) p=MathFloor((i-1)/tochnost);
      i=i+p;
      Shirina[i]=MinCanal2(Start1,i+Start1,per);

      if(maxmin==true)
        {
         if( k_shirina*Shirina[i]<curdeltaMax/Point) ShirinaU[i]=(curdeltaMax/Point+k_shirina*Shirina[i])/2; else ShirinaU[i]=curdeltaMax/Point;
         if(-k_shirina*Shirina[i]>curdeltaMin/Point) ShirinaD[i]=(curdeltaMin/Point-k_shirina*Shirina[i])/2; else ShirinaD[i]=curdeltaMin/Point;
        }
      CanalL[i]  = yOptL;
      CanalR[i]  = yOptR;
      d=i-lnz;
      if(d!=0)
        {
         dC=(Shirina[i]-Shirina[lnz])/d;
         dR=(CanalR[i]-CanalR[lnz])/d;
         dL=(CanalL[i]-CanalL[lnz])/d;
        }
      if(d>1)
         for(i1=1;i1<d;i1++)
           {
            Shirina[lnz+i1] = Shirina[lnz+i1-1]+dC;
            CanalL[lnz+i1]  = CanalL[lnz+i1-1]+dL;
            CanalR[lnz+i1]  = CanalR[lnz+i1-1]+dR;
           }
      lnz=i;
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
///////////////////////////////////////////////////////
double MinCanal2(int xR,int xL,int per)
  {
   double p=xL-xR;
   double j1,j2,j3,h1,h2,yR,yL,d;

   j1 = p + 1;
   j2 = p*(p+1)/2;
   j3 = p*(p+1)*(2*p+1)/6;


   if(prevxR!=xR || prevper!=per)
     {
      prevp=0;
      sum1=0;
      sum2=0;
     }

   for(int n=prevp; n<=p; n++)
     {
      sum2+=iOpen(NULL,per,n+xR);
     }

   for(n=prevp; n<=p; n++)
     {
      sum1+=iOpen(NULL,per,n+xR)*n;
     }

   h2 = sum2;
   h1 = sum1;
   prevxR=xR;
   prevp=p+1;
   prevper=per;
   d=(j2*h2-j1*h1)/(j2*j2-j1*j3);
   yOptR = (h1-j3*d)/j2;
   yOptL = d*p+yOptR;

   return(SumPlus2(xL,xR,yOptR,yOptL,per)/j1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
///////////////////////////////////////////////////////

double SumPlus2(int xL1,int xR1,double yR1,double yL1,int per)
  {
   double curLinePrice,curdelta,curdeltaH,curdeltaL,delta;
   curdeltaMax=-100000;
   curdeltaMin=100000;
   int i = xR1;
   if(xL1==xR1)return(0);
   if((xL1-xR1)!=0) delta = (yL1-yR1)/(xL1-xR1);
   curLinePrice = yR1;
   sumPlus=0;
   while(i<=xL1)
     {
      curdelta=iOpen(NULL,per,i)-curLinePrice;
      curdeltaH = iHigh(NULL,per,i) - curLinePrice;
      curdeltaL = iLow(NULL,per,i) - curLinePrice;
      if(curdeltaMax<curdeltaH) curdeltaMax=curdeltaH;
      if(curdeltaMin>curdeltaL) curdeltaMin=curdeltaL;
      if(curdelta>0) sumPlus=sumPlus+curdelta;
      curLinePrice=curLinePrice+delta;
      i++;
     }
   return(sumPlus/Point);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
////////////////////////////////////////////////////////////////////////////////////
void LoadHist()
  {
   int iPeriod[9];
   iPeriod[0]=1;
   iPeriod[1]=5;
   iPeriod[2]=15;
   iPeriod[3]=30;
   iPeriod[4]=60;
   iPeriod[5]=240;
   iPeriod[6]=1440;
   iPeriod[7]=10080;
   iPeriod[8]=43200;
   for(int iii=0;iii<9;iii++)
     {
      datetime open=iTime(Symbol(),iPeriod[iii],0);
      //datetime open = MarketInfo(Symbol(),MODE_TIME);
      int error=GetLastError();
      //Comment("");
      while(error==4066)
        {
         Comment("Did not load historical data for ",iPeriod[iii]," period, the indicator needs to be rebooted or move on to another timeframe");
         Sleep(10000);
         open = iTime(Symbol(), iPeriod[iii], 0);
         error=GetLastError();
        }
     }
  }
//+------------------------------------------------------------------+

 

Thanks.

Best regards, oink 

Files:
mchannels.mq4  18 kb
 

Hi mntiwana/mladen,

 i found simple indicator and need EA for it ... can any of one great coder can make this to EA

that is Macd dot.. i set it to 30 , 50, 9 it is giving decent profit... so i planned to do this automate ... so i need EA for this and trading rule is simply i tell here..
1. when dot appear and stands for minimum 60 seconds to 90 seconds immediately take trade on that direction red - sell , blue -buy at market order..... no waiting for the candle close time...
2. after taken trade placing sl and this sl is trigger price+/-(trigger price*0.5/100) and this sl price is till that candle close with that dot.... suppose before candle close the dot disappears means no worry the trade is on board with sl. bu then candle close with dot then change sl to dot price ....
suppose some times sl will take place.. but no fresh dot appears.. so if sl hits by any time then wait for the candle close and if next candle comes to the initial trigger price take trade again with same mentioning rules
of entry sl and sl change and tp...
3. take profit is 1 is trigger price+/-(trigger price*1.6/100)
[for example suppose price is 100 and sell dot means our tp 1 is 100-(100*1.6/100) if buy dot means 100+ (100*1.6/100) ]
and tp 2 is trigger price+/-(trigger price*2.5/100)
tp 3 is trigger price+/-(trigger price*4.4/100)
at booking stage 1 trail sl to [ trigger price+/-(trigger price*1/100)]
at booking stage 2 trail sl to[ trigger price+/-(trigger price*2.1/100)]
at booking stage 3 trail sl to [trigger price+/-(trigger price*3..9/100)]
on this conditions not meet out ...then book fully at next dot appearance and do trade as per that next dot.

i am planning to do in indian market so make the lot size is 1 and multiples of 1 ..not like 0.01, 0.1 

Files:
MACD_Dot.mq4  3 kb
MACD_Dot.JPG  87 kb
 
nishhhan:

Hi mntiwana/mladen,

 i found simple indicator and need EA for it ... can any of one great coder can make this to EA

that is Macd dot.. i set it to 30 , 50, 9 it is giving decent profit... so i planned to do this automate ... so i need EA for this and trading rule is simply i tell here..
1. when dot appear and stands for minimum 60 seconds to 90 seconds immediately take trade on that direction red - sell , blue -buy at market order..... no waiting for the candle close time...
2. after taken trade placing sl and this sl is trigger price+/-(trigger price*0.5/100) and this sl price is till that candle close with that dot.... suppose before candle close the dot disappears means no worry the trade is on board with sl. bu then candle close with dot then change sl to dot price ....
suppose some times sl will take place.. but no fresh dot appears.. so if sl hits by any time then wait for the candle close and if next candle comes to the initial trigger price take trade again with same mentioning rules
of entry sl and sl change and tp...
3. take profit is 1 is trigger price+/-(trigger price*1.6/100)
[for example suppose price is 100 and sell dot means our tp 1 is 100-(100*1.6/100) if buy dot means 100+ (100*1.6/100) ]
and tp 2 is trigger price+/-(trigger price*2.5/100)
tp 3 is trigger price+/-(trigger price*4.4/100)
at booking stage 1 trail sl to [ trigger price+/-(trigger price*1/100)]
at booking stage 2 trail sl to[ trigger price+/-(trigger price*2.1/100)]
at booking stage 3 trail sl to [trigger price+/-(trigger price*3..9/100)]
on this conditions not meet out ...then book fully at next dot appearance and do trade as per that next dot.

i am planning to do in indian market so make the lot size is 1 and multiples of 1 ..not like 0.01, 0.1 

That is a simple macd. You can use any EA that uses macd for that (even the macd sample that comes with the metatrader when you install it)

The 60 to 90 seconds condition in not possible (you can not have when exactly a signal happens, what is usually done instead is looking for a signal on a closed bar to avoid false signals). All the rest is fairly usual in any EA (except the "trigger price" is no doable - you can not fix the prices for an EA, that is why the tp and sl are used, but they are relative to the open price not art some fix price levels)

 

Hi dear programmers.

 

Im experimenting with mql4 to hopefully be a good programmer some day. My problem now has to do with measuring ticks/pips.

 

Im having a 5 digit broker and are using the following code:

 

 High[i] > iCustom(NULL, PERIOD_CURRENT, "BBands", 20, 2, 1.00, 1, 1, 1000, 5, i) - 15 * myPoint //Candlestick High > BBands - fixed value

 where: 

 

myPoint = Point();
   if(Digits() == 5)
     {
      myPoint *= 10;
     }

 

Of course this works on majors, but for example gold this will give me 1.5 pip instead of 15 and for dax it will give me 0.15pip instead

 

So I would want to multiply by 100 if the instrument is XAU/USD and by 1000 if the instrument is DE30.

 

How can I attack this problem?