Download MetaTrader 5
To add comments, please log in or register
You sell neither signals nor apps? No problem, everyone can make profit!
ThemBonez
37
ThemBonez 2014.12.22 01:36 

Hi,

I created this custom indicator to draw an arrow at Swing Hi's and Lo's.

Can't figure out why it is not drawing the arrows when I apply it to a chart.

Any ideas?

ThemBonez

//+------------------------------------------------------------------+
//|                                                 SwingHighLow.mq4 |
//|                                   Dream Reality Productions, LLC |
//|                           http://www.dreamrealityproductions.com |
//+------------------------------------------------------------------+
#property copyright "Dream Reality Productions, LLC"
#property link      "http://www.dreamrealityproductions.com"

#property indicator_chart_window

#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Aqua

double SwingHiBar[];
double SwingLoBar[];

double pips;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1);

   SetIndexArrow(1,233);
   SetIndexArrow(0,234);

   SetIndexBuffer(0,SwingHiBar);
   SetIndexBuffer(1,SwingLoBar);

   
   
   double ticksize = MarketInfo (Symbol(),MODE_TICKSIZE);
      if (ticksize == .00001 || ticksize == .001)
         pips = ticksize * 10;
         else pips = ticksize;
         
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
for (int i=1;i<=300;i++)
   {
      if (High[i] < High [i+3] )
         if (High[i+1] < High[i+3] )
            if (High [i+2] < High [i+3] )
               if (High [i+3] > High [i+4] )
                  if (High [i+3] > High [i+5])
                     if (High [i+3] > High [i+6])
                        SwingHiBar[i] = iHighest(Symbol(),0,MODE_HIGH,i+6,i);
                         
                    
                         
      if (Low[i] > Low [i+3])
         if (Low[i+1] > Low[i+3])
            if (Low [i+2] > Low [i+3])
               if (Low [i+3] < Low [i+4])
                  if (Low [i+3] < Low [i+5])
                     if (Low[i+3] < Low [i+6])
                     SwingLoBar[i] = iLowest(Symbol(),0,MODE_LOW,i+6,i);
                     
    }
   return(0);
  }
//+------------------------------------------------------------------+
whroeder1
13644
whroeder1 2014.12.22 02:21  
ThemBonez: Can't figure out why it is not drawing the arrows when I apply it to a chart.
  1. for (int i=1;i<=300;i++)
    Your look back is 6. what happens if you don't have 306 bars available? Why recalculate all 300 bars every tick? Only the current bar is changing. Do it right.
    int counted = IndicatorCounted();
    for (int i=Bars - 1 - MathMax(counted,6); i >= 0; i--)

  2. SwingLoBar[i] = iLowest(Symbol(),0,MODE_LOW,i+6,i);
    
    Why do you want to know the lowest bar from [0 .. 5] (6 bars) for bar 0, [1 .. 7] (7 bars) for bar 1, [2 .. 9] (eight bars) for bar 2, [100 .. 205] (106 bars) for bar 100, etc.?
  3. Why do you expect to see the bar number (1, 2, 100 ... ) on a price chart (1.2345+-0.0100?)
Keith Watford
Moderator
8014
Keith Watford 2014.12.23 01:27  

This

for (int i=1;i<=300;i++)
   {
      if (High[i] < High [i+3] )
         if (High[i+1] < High[i+3] )
            if (High [i+2] < High [i+3] )
               if (High [i+3] > High [i+4] )
                  if (High [i+3] > High [i+5])
                     if (High [i+3] > High [i+6])
                        SwingHiBar[i] = iHighest(Symbol(),0,MODE_HIGH,i+6,i);
                         
                    

 Seems a long winded way to do it as you simply appear to be checking that the highest high is simply the middle of 7

I believe that you are attempting something like this

#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot SwingHiBar
#property indicator_label1  "SwingHiBar"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrDodgerBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot SwingLoBar
#property indicator_label2  "SwingLoBar"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrLimeGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters

//--- indicator buffers
double         SwingHiBar[];
double         SwingLoBar[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,SwingHiBar);
   SetIndexBuffer(1,SwingLoBar);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   SetIndexArrow(0,234);
   SetIndexArrow(1,233);
   
//---
   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[])
  {
  if(rates_total<8)
     return(0);
  int x;
  if(prev_calculated==0)
     x=rates_total-8;
  else
     x=1;
  
  for(;x>=1;x--)
     {
     if(iHighest(Symbol(),0,MODE_HIGH,7,x)==x+3)
        SwingHiBar[x+3]=High[x+3];
     if(iLowest(Symbol(),0,MODE_LOW,7,x)==x+3)
        SwingLoBar[x+3]=Low[x+3];
     }
  
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
/
To add comments, please log in or register