View Single Post
  #14 (permalink)  
Old 06-29-2006, 08:51 PM
Aaragorn's Avatar
Aaragorn Aaragorn is offline
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
ok this one looks like it might fit the purpose from looking at it on the chart...

PHP Code:
//+------------------------------------------------------------------+
//|                                                  Trend Bands.mq4 |
//|                                              Dwt5 and adoleh2000 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 Black
#property indicator_color3 Blue

#property indicator_color4 Red
#property indicator_color5 Blue


double upper[], middle1[], middle2lower[];
double Xup[], Xdown[];

extern int period 34;


int init()
  {
   
SetIndexStyle(0,DRAW_LINE,EMPTY,2);
   
SetIndexShift(0,0);
   
SetIndexDrawBegin(0,0);
   
SetIndexBuffer(0,upper);

   
SetIndexStyle(1,DRAW_LINE,EMPTY,2);
   
SetIndexShift(1,0);
   
SetIndexDrawBegin(1,0);
   
SetIndexBuffer(1,middle1);
   
   
SetIndexStyle(2,DRAW_LINE,EMPTY,2);
   
SetIndexShift(2,0);
   
SetIndexDrawBegin(2,0);
   
SetIndexBuffer(2,lower);
    
   
SetIndexStyle(3,DRAW_ARROW,EMPTY,2);
   
SetIndexArrow(3162);
   
SetIndexShift(3,0);
   
SetIndexDrawBegin(3,0);
   
SetIndexBuffer(3,Xdown);

   
SetIndexStyle(4,DRAW_ARROW,EMPTY,2);
   
SetIndexArrow(4162);
   
SetIndexShift(4,0);
   
SetIndexDrawBegin(4,0);
   
SetIndexBuffer(4,Xup);

//---- indicators
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   
int limit;
   
int counted_bars=IndicatorCounted();
   if(
counted_bars<0) return(-1);
   if(
counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;
   
   
double avg;
   
   for(
int x=0x<limitx++) {
      
Xdown[x] = 0Xup[x] = 0;
      
middle1[x] = iMA(NULL0period0MODE_EMAPRICE_TYPICALx);// drawn line
      
middle2iMA(NULL0period0MODE_SMAPRICE_TYPICALx);// only used to calculate outer bands

      
avg  findAvg(periodx);
      
upper[x] = middle2 + (3.5*avg);
      
lower[x] = middle2 - (3.5*avg);
      
      if (
MathAbs(upper[x] - High[x]) < 2*Point)
      {
         
Xdown[x] = upper[x];
         if (
NewBar() && == 0)
            
Alert(Symbol()," ",Period()," reach upper edge");
      }   
      if (
MathAbs(lower[x] - Low[x]) < 2*Point)
      {
         
Xup[x] = lower[x];
         if (
NewBar() && == 0)
            
Alert(Symbol()," ",Period()," reach lower edge");
      }
   }
   return(
0);
  }
//+------------------------------------------------------------------+


   
double findAvg(int periodint shift) {
      
double sum=0;
      for (
int x=shift;x<(shift+period);x++) {     
         
sum += High[x]-Low[x];
      }
      
sum sum/period;
      return (
sum);
   }
   
bool NewBar()
{
   static 
datetime dt 0;
   if (
dt != Time[0])
   {
      
dt Time[0];
      return(
true);
   }
   return(
false);

which variables are the lines I see on the chart? upper [x] and lower [x]? what ones do I use to embed this in the EA? could I just use the alert lines to modify the EA rather than give alerts?

Last edited by Aaragorn; 06-29-2006 at 09:02 PM.
Reply With Quote