Download MetaTrader 5
To add comments, please log in or register
Having questions? Ask them on the Forum - traders will help you!
Robert Browne
88
Robert Browne 2015.06.05 13:14 

So I'm pretty simple. But I tried this and nothing. Just indicator buffer#1 detached???

 

//+------------------------------------------------------------------+
//|                                           bobstrailing stops.mq4 |
//|                         Copyright © 2015 Bob All rights reserved |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015"
#property link      "Bob"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 6
#property  indicator_color1  Blue
#property  indicator_color2  Magenta
#property  indicator_color3  Green
#property  indicator_color4  Blue
#property  indicator_color5  Red
#property  indicator_color6  LimeGreen
#property  indicator_width1  1
#property  indicator_width2  1
#property  indicator_width3  1
#property  indicator_width4  1
#property  indicator_width5  1
#property  indicator_width6  1

//---- indicator parameters
extern int Highest=50;
extern int Middle=24;
extern int Lowest=12;

//---- indicator buffers
double     highest[];
double     lowest[];
double     fastest[];
double     slowest[];
double     trail1[];
double     trail2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   
//---- indicator buffers mapping
   SetIndexBuffer(0,highest);
   SetIndexBuffer(1,lowest);
   SetIndexBuffer(2,fastest);
   SetIndexBuffer(3,lowest);
   SetIndexBuffer(4,trail1);
   SetIndexBuffer(5,trail2);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Stop levels");
   SetIndexLabel(0,"Highest");
   SetIndexLabel(1,"Lowest");
   SetIndexLabel(2,"Fastest");
   SetIndexLabel(3,"Slowest");
   SetIndexLabel(4,"Trail1");
   SetIndexLabel(5,"Trail2");
    
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

//---- calculate values
   for(int i=0; i<limit; i++)
    { 
      highest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i))/2),Digits);
      lowest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i))/2),Digits);
      fastest[i]=NormalizeDouble((((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i))/2)+((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i))/2))/2,Digits);
      lowest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Highest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Highest,i))/2),Digits);
      trail1[i]=NormalizeDouble((((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i+Middle))/2)+((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i+Middle))/2))/2,Digits);
      trail2[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Highest,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Highest,i+Middle))/2),Digits);
    }
   return(0);
  }
//+------------------------------------------------------------------+  
Robert Browne
88
Robert Browne 2015.06.05 13:18  
forexbob1970:

So I'm pretty simple. But I tried this and nothing. Just indicator buffer#1 detached???

 

Apart from this

//---- calculate values
   for(int i=0; i<limit; i++)
    { 
      highest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i))/2),Digits);
      lowest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i))/2),Digits);
      fastest[i]=NormalizeDouble((((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i))/2)+((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i))/2))/2,Digits);
      lowest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Highest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Highest,i))/2),Digits);
      trail1[i]=NormalizeDouble((((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i+Middle))/2)+((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i+Middle))/2))/2,Digits);
      trail2[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Highest,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Highest,i+Middle))/2),Digits);
    }

 Which should read this

//---- calculate values
   for(int i=0; i<limit; i++)
    { 
      highest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i))/2),Digits);
      lowest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i))/2),Digits);
      fastest[i]=NormalizeDouble((((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i))/2)+((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i))/2))/2,Digits);
      slowest[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Highest,i))+(iLowest(Symbol(),Period(),MODE_LOW,Highest,i))/2),Digits);
      trail1[i]=NormalizeDouble((((iHighest(Symbol(),Period(),MODE_HIGH,Middle,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Middle,i+Middle))/2)+((iHighest(Symbol(),Period(),MODE_HIGH,Lowest,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Lowest,i+Middle))/2))/2,Digits);
      trail2[i]=NormalizeDouble(((iHighest(Symbol(),Period(),MODE_HIGH,Highest,i+Middle))+(iLowest(Symbol(),Period(),MODE_LOW,Highest,i+Middle))/2),Digits);
    }
Alain Verleyen
Moderator
28658
Alain Verleyen 2015.06.05 14:11  

Array out of range error. Check your logs when something doesn't work.

whroeder1
13641
whroeder1 2015.06.05 18:04  
  1. Do you think integer values in the [0 .. 100] range are going to be visiable on a pair in the [1.52 .. 1.54] range
  2. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
  3. MODE_HIGH,Highest,i+Middle)
    Your look back is Highest+Middle-1. Contradictory information on IndicatorCounted() - MQL4 forum Do it right.
       int counted_bars=IndicatorCounted();
    //---- last counted bar will be recounted
       if(counted_bars>0) counted_bars--;
       limit=Bars-counted_bars;
       int counted_bars=IndicatorCounted();
       int lookback = Highest+Middle-1;
       limit=Bars-MathMax(lookback,counted_bars);
Robert Browne
88
Robert Browne 2015.06.06 00:52  
Thanks lads especially for the links. 
/
To add comments, please log in or register