Problem knowing how to write yesturday's high close opens continuously as indicator?

Back to topics list To post a new topic, please log in or register
avatar
52
renzbub 2015.12.03 23:53
 

In the following code im trying to create an indicator that writes the previous days close, high and lows so as it displays all previous days on chart at once instead of only one at a time.  The code below writes close, high and low okay but its only for the previous day.

 I cant figure out how to display all previous days?

   int bars = rates_total - 1; 
   if(prev_calculated > 0) bars = rates_total - prev_calculated; 
   
   for(int i = bars; i >= 0; i--)  // -- Counts down from last bar on chart EG 99th
  {
   ycloseBuffer[i] = iClose(_Symbol,PERIOD_D1,1);   // I replaced = high[ArrayMaximum(high,i,HighLowBars)]; with yclose and its worked!!!
   yhighBuffer[i] = iHigh(_Symbol,PERIOD_D1,1); 
   ylowBuffer[i] = iLow(_Symbol,PERIOD_D1,1); 

   datetime timeStart = CreateDateTime(0,0);    
   datetime timeEnd = CreateDateTime(23,0);

   string ob_yc = "ycloseline "+TimeToStr(timeStart);    
   string ob_yh = "yhighline "+TimeToStr(timeStart);   
   string ob_yl = "ylowline "+TimeToStr(timeStart); 

   ObjectCreate(ob_yc,OBJ_TREND,0,timeStart,yclose,timeEnd,yclose); 
   ObjectCreate(ob_yh,OBJ_TREND,0,timeStart,yhigh,timeEnd,yhigh); 
   ObjectCreate(ob_yl,OBJ_TREND,0,timeStart,ylow,timeEnd,ylow);    

   ObjectSet(ob_yc,OBJPROP_STYLE,STYLE_DASH); // This edits the lines regardless 
   ObjectSet(ob_yh,OBJPROP_STYLE,STYLE_DASH);  
   ObjectSet(ob_yl,OBJPROP_STYLE,STYLE_DASH); 
   
   ObjectSet(ob_yc,OBJPROP_RAY,false);  
   ObjectSet(ob_yh,OBJPROP_RAY,false);  
   ObjectSet(ob_yl,OBJPROP_RAY,false);         
  }  

 

avatar
Moderator
3427
GumRai 2015.12.04 00:30 #
 

It is not clear whether you intend to draw your lines with a trend line or a buffer

   ycloseBuffer[i] = iClose(_Symbol,PERIOD_D1,1);
   yhighBuffer[i] = iHigh(_Symbol,PERIOD_D1,1); 
   ylowBuffer[i] = iLow(_Symbol,PERIOD_D1,1); 

 These will all get values for index 1 on the daily chart, not related to i at all

   datetime timeStart = CreateDateTime(0,0);    
   datetime timeEnd = CreateDateTime(23,0);

 We don't know what these functions do, but again do not appear to relate to i

   ObjectCreate(ob_yc,OBJ_TREND,0,timeStart,yclose,timeEnd,yclose); 
   ObjectCreate(ob_yh,OBJ_TREND,0,timeStart,yhigh,timeEnd,yhigh); 
   ObjectCreate(ob_yl,OBJ_TREND,0,timeStart,ylow,timeEnd,ylow);    

 Where do the values for yclose etc come from?

 

avatar
52
renzbub 2015.12.04 11:43 #
 
GumRai:

It is not clear whether you intend to draw your lines with a trend line or a buffer

 These will all get values for index 1 on the daily chart, not related to i at all

 We don't know what these functions do, but again do not appear to relate to i

 Where do the values for yclose etc come from?

 

Ive included the whole code so as you can see where the values come from. Im trying to use iClose(_Symbol,PERIOD_D1,1); to draw a trend line as a buffer setting.  

The datetime timeStart = CreateDateTime(0,0); is found in an include file and sets the time coordinates for the parameters at ObjectCreate(ob_yc,OBJ_TREND,0,timeStart,yclose,timeEnd,yclose);    

yclose  is set at start of code as double yclose = iClose(_Symbol,PERIOD_D1,1);  

 

#include <Mql4Book\Timer.mqh>
CTimer Timer;

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 3

//--- buffers
double ycloseBuffer[];     
double yhighBuffer[];     
double ylowBuffer[];
                          
double yclose = iClose(_Symbol,PERIOD_D1,1); 
double yhigh = iHigh(_Symbol,PERIOD_D1,1); 
double ylow = iLow(_Symbol,PERIOD_D1,1); 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---indicator buffer mapping
   SetIndexBuffer(0,ycloseBuffer);
   SetIndexBuffer(1,yhighBuffer);   
   SetIndexBuffer(2,ylowBuffer);     
//---
   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[])
   {
//---  
   ArraySetAsSeries(ycloseBuffer,true); 
   ArraySetAsSeries(yhighBuffer,true);      
   ArraySetAsSeries(ylowBuffer,true);    

   int bars = rates_total - 1; 
   if(prev_calculated > 0) bars = rates_total - prev_calculated; 
   
   for(int i = bars; i >= 0; i--) 
  {
   ycloseBuffer[i] = iClose(_Symbol,PERIOD_D1,1);   
   yhighBuffer[i] = iHigh(_Symbol,PERIOD_D1,1); 
   ylowBuffer[i] = iLow(_Symbol,PERIOD_D1,1); 

   datetime timeStart = CreateDateTime(0,0);    
   datetime timeEnd = CreateDateTime(23,0);

   string ob_yc = "ycloseline "+TimeToStr(timeStart);    
   string ob_yh = "yhighline "+TimeToStr(timeStart);   
   string ob_yl = "ylowline "+TimeToStr(timeStart); 

   ObjectCreate(ob_yc,OBJ_TREND,0,timeStart,yclose,timeEnd,yclose); 
   ObjectCreate(ob_yh,OBJ_TREND,0,timeStart,yhigh,timeEnd,yhigh); 
   ObjectCreate(ob_yl,OBJ_TREND,0,timeStart,ylow,timeEnd,ylow);    

   ObjectSet(ob_yc,OBJPROP_STYLE,STYLE_DASH); // This edits the lines regardless 
   ObjectSet(ob_yh,OBJPROP_STYLE,STYLE_DASH);  
   ObjectSet(ob_yl,OBJPROP_STYLE,STYLE_DASH); 
   
   ObjectSet(ob_yc,OBJPROP_RAY,false);  
   ObjectSet(ob_yh,OBJPROP_RAY,false);  
   ObjectSet(ob_yl,OBJPROP_RAY,false);         
  }    
     
//--- return value of prev_calculated for next call
   return(rates_total);
   }

//+------------------------------------------------------------------+






 

Back to topics list  

To add comments, please log in or register