[Custom indicator] Problems reading ChandelierExit.mq4 values (solved)

Point Zero
799
Point Zero  

Hello,

I am having a little trouble reading ChandelierExit.mq4 values. ChandelierExit is a custom indicator that calculates and draws stoploss based on the volatilty of the market. It's code it's the following.

I want to read the short and long stops to update the SL of my positions. I know that sometimes EMPTY_VALUE is returned, but I don't know which buffer is holding the information I need.

Which buffer is holding the long stoploss? Which buffer is holding the long stoploss? I am a newbie. Thank you very much!!

//+------------------------------------------------------------------+
//|                                               ChandelierExit.mq4 |
//|                                                       MQLService |
//|                                           scripts@mqlservice.com |
//+------------------------------------------------------------------+
//mod2008fxtsd
#property copyright "MQLService"
#property link      "scripts@mqlservice.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Orange
#property indicator_color2 Magenta
//#property indicator_color3 Blue
//#property indicator_color4 Red


//---- input parameters
extern int       Range=7;
extern int       Shift=0;
extern int       ATRPeriod=9;
extern double    ATRMultipl=2.5;
//---- buffers
double ExtMapBuffer1[];  
double ExtMapBuffer2[]; 
double ExtMapBuffer3[];    
double ExtMapBuffer4[];    
double direction[];
double ATRvalue;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorBuffers(5);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer3);  
   SetIndexEmptyValue(2,0.0);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer4); 
   SetIndexEmptyValue(3,0.0);
   
   SetIndexBuffer(2,ExtMapBuffer1); 
   SetIndexBuffer(3,ExtMapBuffer2);
   SetIndexBuffer(4,direction);


   //SetIndexStyle(2,DRAW_LINE);
   //SetIndexStyle(3,DRAW_LINE);
   //SetIndexEmptyValue(2,0.0);
   //SetIndexEmptyValue(3,0.0);

   string shortnme;
   shortnme = "("+Range+",ATR("+ATRPeriod+","+DoubleToStr(ATRMultipl,2)+") ";
   
   IndicatorShortName("Chandelier "+shortnme);  
   SetIndexLabel(0, "Chandlr "+shortnme);
   SetIndexLabel(1, "Chandlr "+shortnme);


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   int limit, counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;

   for(int i=limit; i>=0; i--)
   {
         ExtMapBuffer1[i]= EMPTY_VALUE;   ExtMapBuffer2[i]= EMPTY_VALUE;

         ATRvalue=iATR(NULL,0,ATRPeriod,i+Shift)*ATRMultipl;
         ExtMapBuffer1[i]=High[Highest(NULL,0,MODE_HIGH,Range,i+Shift)] -ATRvalue; 
         ExtMapBuffer2[i]=Low[Lowest(NULL,0,MODE_LOW,Range,i+Shift)]    +ATRvalue; 
         
         ExtMapBuffer3[i]= EMPTY_VALUE;   ExtMapBuffer4[i]= EMPTY_VALUE;


   direction[i] =direction[i+1];
            
         
             if(Close[i]>ExtMapBuffer2[i+1])direction[i]=  1;
             if(Close[i]<ExtMapBuffer1[i+1])direction[i]= -1;

   if (direction[i]>0)
            {
             if      (  ExtMapBuffer1[i]< ExtMapBuffer1[i+1])
             
                                          ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
                                          ExtMapBuffer3[i]=ExtMapBuffer1[i];
                                          ExtMapBuffer4[i]=EMPTY_VALUE;   
             }                 

   if (direction[i]<0)
            {                    
             if      (  ExtMapBuffer2[i]>ExtMapBuffer2[i+1])
             
                                          ExtMapBuffer2[i]=ExtMapBuffer2[i+1];
                                          ExtMapBuffer4[i]=ExtMapBuffer2[i];  
                                          ExtMapBuffer3[i]=EMPTY_VALUE; 
                                 
            }  

   }
   return(0);
}
//+------------------------------------------------------------------+
qjol
3201
qjol  
flaab:

Which buffer is holding the long stoploss? 0

Which buffer is holding the long stoploss? also 0 I am a newbie. Thank you very much!!

Point Zero
799
Point Zero  
Thank you. However, I am going to need to program something like that myself, the indicator does not work as I wished.
[Deleted]  
I've installed MteTrader 4 & 5 but do not know how to use them. e.g. set limit loss/profit. I'm in demo environment but can't set to trade i.e. placed a new order but keeps getting a sound and no trades executed. Can someone please help me or point me to somewhere where I can get help. Thanks in advance.
Point Zero
799
Point Zero  

Issue solved. You must set an auxiliary stop method in case Chandelier returns EMPTY_VALUE or a value not suitable for the position you want to take.

Make sure the value retrieved is below current price if you are long or otherwise if short.