Re: Coding Help

453
Hey,

I am trying to develop an indicator myself and got a question. I am using an daily open line indicator and currently grab the Price of the daily open via ist buffer, could some of the more advanced coders maybe take a quick look and maybe Show me how I can save the value to a normal double instead of a buffer ?

If yes here is the Code of the daily open line indicator:

Code: Select all

//*
//* my_DailyOpen_indicator
//*
//* Revision 1.1  2005/11/13 Midnite
//* Initial DailyOpen indicator
//* based pm  
//*
#property copyright "Midnite"
#property link      "me@home.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 White
#property indicator_style1 2
#property indicator_width1 1

double TodayOpenBuffer[];
extern int TimeZoneOfData= 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	SetIndexStyle(0,DRAW_LINE);
	SetIndexBuffer(0,TodayOpenBuffer);
	SetIndexLabel(0,"Open");
	SetIndexEmptyValue(0,0.0);
	return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int lastbar;
   int counted_bars= IndicatorCounted();
   
   if (counted_bars>0) counted_bars--;
   lastbar = Bars-counted_bars;	
   DailyOpen(0,lastbar);
   
   return (0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int DailyOpen(int offset, int lastbar)
{
   int shift;
   int tzdiffsec= TimeZoneOfData * 3600;
   double barsper30= 1.0*PERIOD_M30/Period();
   bool ShowDailyOpenLevel= True;
   // lastbar+= barsperday+2;  // make sure we catch the daily open		 
   lastbar= MathMin(Bars-20*barsper30-1, lastbar);

	for(shift=lastbar;shift>=offset;shift--){
	  TodayOpenBuffer[shift]= 0;
     if (ShowDailyOpenLevel){
       if(TimeDay(Time[shift]-tzdiffsec) != TimeDay(Time[shift+1]-tzdiffsec)){      // day change
         TodayOpenBuffer[shift]= Open[shift];         
         TodayOpenBuffer[shift+1]= 0;                                                           // avoid stairs in the line
       }
       else{
         TodayOpenBuffer[shift]= TodayOpenBuffer[shift+1];
       }
	  }
   }
   return(0);
}
I want to do it also like above and not like this: iOpen(NULL,PERIOD_D1,i);

Re: Coding Help

454
salexes wrote: Mon Jul 31, 2017 3:07 am Hey,

I am trying to develop an indicator myself and got a question. I am using an daily open line indicator and currently grab the Price of the daily open via ist buffer, could some of the more advanced coders maybe take a quick look and maybe Show me how I can save the value to a normal double instead of a buffer ?

If yes here is the Code of the daily open line indicator:

Code: Select all

//*
//* my_DailyOpen_indicator
//*
//* Revision 1.1  2005/11/13 Midnite
//* Initial DailyOpen indicator
//* based pm  
//*
#property copyright "Midnite"
#property link      "me@home.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 White
#property indicator_style1 2
#property indicator_width1 1

double TodayOpenBuffer[];
extern int TimeZoneOfData= 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	SetIndexStyle(0,DRAW_LINE);
	SetIndexBuffer(0,TodayOpenBuffer);
	SetIndexLabel(0,"Open");
	SetIndexEmptyValue(0,0.0);
	return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int lastbar;
   int counted_bars= IndicatorCounted();
   
   if (counted_bars>0) counted_bars--;
   lastbar = Bars-counted_bars;	
   DailyOpen(0,lastbar);
   
   return (0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int DailyOpen(int offset, int lastbar)
{
   int shift;
   int tzdiffsec= TimeZoneOfData * 3600;
   double barsper30= 1.0*PERIOD_M30/Period();
   bool ShowDailyOpenLevel= True;
   // lastbar+= barsperday+2;  // make sure we catch the daily open		 
   lastbar= MathMin(Bars-20*barsper30-1, lastbar);

	for(shift=lastbar;shift>=offset;shift--){
	  TodayOpenBuffer[shift]= 0;
     if (ShowDailyOpenLevel){
       if(TimeDay(Time[shift]-tzdiffsec) != TimeDay(Time[shift+1]-tzdiffsec)){      // day change
         TodayOpenBuffer[shift]= Open[shift];         
         TodayOpenBuffer[shift+1]= 0;                                                           // avoid stairs in the line
       }
       else{
         TodayOpenBuffer[shift]= TodayOpenBuffer[shift+1];
       }
	  }
   }
   return(0);
}
I want to do it also like above and not like this: iOpen(NULL,PERIOD_D1,i);
Why not like that when it is the simplest and fastest method?


Re: Coding Help

456
salexes wrote: Mon Jul 31, 2017 5:27 am

I don’t want to make use of external indicators, I want to have everything calculated inside my indicator if that is possible.

Regards,
Salexes
Salexes

That is not using external indicators
That is using strict built in metatrader functions

Re: Coding Help

457
How do I need to change the following code if my indicator is checking the bars this way for(i=limit; i>=0; i--) {} while the indicator I want to integrate in my own indicator uses for (int i = 0; i <= limit; i++) ?

Code: Select all

int start() 
{
   double SUM, MVA, ATR;
   int limit, countedBars;
    
   countedBars = IndicatorCounted();
   limit= Bars - countedBars - 1;  
   if (limit> BarsHistory - 1)
   {  
      limit= BarsHistory - 1;
   } 

   for (int i = 0; i <= limit; i++) 
   {  
      SUM = 0;
      for (int k = i; k < NumBars + i; k++)                                                                                                                                                                                                                                                                                                                                                                                                                  
      {
         SUM += (High[k] + Low[k]) / 2.0;
      }
      MVA = SUM / NumBars;
      
      SUM = 0;
      for (k = i; k < NumBars + i; k++) 
      {
         SUM += High[k] - Low[k];
      }
      ATR = 0.2 * (SUM / NumBars);

      HH[i] = (High[i] - MVA) / ATR;
      LL[i] = (Low[i] - MVA) / ATR;
      OO[i] = (Open[i] - MVA) / ATR;
      CC[i] = (Close[i] - MVA) / ATR;
     
   return (0);
}
And this is my indi

Code: Select all

int start()
{
    int i,counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit = fmin(Bars-counted_bars,Bars-1); 
   for(i=limit; i>=0; i--)
   {//DO THINGS HERE}

Re: Coding Help

458
salexes wrote: Mon Jul 31, 2017 9:30 pm How do I need to change the following code if my indicator is checking the bars this way for(i=limit; i>=0; i--) {} while the indicator I want to integrate in my own indicator uses for (int i = 0; i <= limit; i++) ?

Code: Select all

int start() 
{
   double SUM, MVA, ATR;
   int limit, countedBars;
    
   countedBars = IndicatorCounted();
   limit= Bars - countedBars - 1;  
   if (limit> BarsHistory - 1)
   {  
      limit= BarsHistory - 1;
   } 

   for (int i = 0; i <= limit; i++) 
   {  
      SUM = 0;
      for (int k = i; k < NumBars + i; k++)                                                                                                                                                                                                                                                                                                                                                                                                                  
      {
         SUM += (High[k] + Low[k]) / 2.0;
      }
      MVA = SUM / NumBars;
      
      SUM = 0;
      for (k = i; k < NumBars + i; k++) 
      {
         SUM += High[k] - Low[k];
      }
      ATR = 0.2 * (SUM / NumBars);

      HH[i] = (High[i] - MVA) / ATR;
      LL[i] = (Low[i] - MVA) / ATR;
      OO[i] = (Open[i] - MVA) / ATR;
      CC[i] = (Close[i] - MVA) / ATR;
     
   return (0);
}
And this is my indi

Code: Select all

int start()
{
    int i,counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit = fmin(Bars-counted_bars,Bars-1); 
   for(i=limit; i>=0; i--)
   {//DO THINGS HERE}
No need to change anything (if the indicator you are using is not repainting)

Re: Coding Help

460
I have a strange problem regarding rounding numbers.

I was using the Buy Sell Volume V 1.0 indicator via iCustom but now I wanted to integrate it directly into my indicator.... So I did that.
Below you will find the sourcecode of the indicator and my integration into my indicator.

Here is a picture of the strange rounding:
If I round it via NormalizeDouble it Roundsup 76.5 to 77.0 and 25.5 to 26.
Why are the values different ?
What do I need to do to get the exact same values? ("Note: I can not use IndicatorDigits(0); because for the other buffers i do need the numbers behind the . )

BuySellVolume SourceCode:

Code: Select all

//+-------------------------------------------------------------------+
//|                                        Buy_Sell_Volumes_v1.0.mq4  |
//|                                            Copyright © 2013, Pip  |
//|                                    http://www.pricemasterpro.com  |
//| This indicator is for personal use only.                          |
//| Please respect the intellectual rights of the original programmer |
//| and the work of others that contributed to this indicator         |
//| under no circumstances is this indicator to be sold for money or  |
//| to be repackged into a commercial package or to be distributed as |
//| original work by anyone else.                                     |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, Pip; admin@pricemasterpro.com"
#property link      "http://www.pricemasterpro.com/"
//---- indicator settings
#property  indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 6
#property indicator_color1  White
#property indicator_color2  White
#property indicator_color3  Red
#property indicator_color4  Red
#property indicator_color5  Green
#property indicator_color6  Green
#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 buffers
double ExtVolumesBufferHisto[];
double ExtVolumesBufferLine[];
double ExtVolumesUpBufferHisto[];
double ExtVolumesUpBufferLine[];
double ExtVolumesDownBufferHisto[];
double ExtVolumesDownBufferLine[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtVolumesBufferHisto);       
   SetIndexBuffer(1,ExtVolumesBufferLine);
   SetIndexBuffer(2,ExtVolumesUpBufferHisto);
   SetIndexBuffer(3,ExtVolumesUpBufferLine);       
   SetIndexBuffer(4,ExtVolumesDownBufferHisto);
   SetIndexBuffer(5,ExtVolumesDownBufferLine);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexStyle(5,DRAW_LINE);
//---- sets default precision format for indicators visualization
   IndicatorDigits(0);   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Buy_Sell Volume Pressure");
   SetIndexLabel(0,"Total Volume");      
   SetIndexLabel(1,"Buy Volume");
   SetIndexLabel(2,"Sell Volume");
//---- sets drawing line empty value
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(3,0.0); 
   SetIndexEmptyValue(5,0.0);      
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Volumes                                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,nLimit,nCountedBars;
//---- bars count that does not changed after last indicator launch.
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted
   if(nCountedBars>0) nCountedBars--;
   nLimit=Bars-nCountedBars;
//----
   for(i=0; i<nLimit; i++)
     {
    double bullp   = MathAbs(iBullsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double bearp   = MathAbs(iBearsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double vol     = iVolume(Symbol(), 0, i);
    double Buyers  = (bullp * vol) / MathMax((bullp + bearp),0.000001);
    double Sellers = (bearp * vol) / MathMax((bullp + bearp),0.000001);
   
         ExtVolumesBufferHisto[i]=vol;
         ExtVolumesBufferLine[i]=vol;
         ExtVolumesUpBufferHisto[i]=Buyers;
         ExtVolumesUpBufferLine[i]=Buyers;
         ExtVolumesDownBufferHisto[i]=Sellers; 
         ExtVolumesDownBufferLine[i]=Sellers;       
     
     }        
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

The calculation is exactly the same:

Code: Select all

int BuySellVolume(int offset, int limit){
   for(int i=offset; i<limit; i++)
     {
    double bullp   = MathAbs(iBullsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double bearp   = MathAbs(iBearsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double vol     = iVolume(Symbol(), 0, i);
    double Buyers  = (bullp * vol) / MathMax((bullp + bearp),0.000001);
    double Sellers = (bearp * vol) / MathMax((bullp + bearp),0.000001);
   
         ExtVolumesBufferHisto[i]=NormalizeDouble(vol,0);
         ExtVolumesUpBufferLine[i]=NormalizeDouble(Buyers,0);
         ExtVolumesDownBufferHisto[i]=NormalizeDouble(Sellers,0);  
     }        
   return(0);
}


Who is online

Users browsing this forum: No registered users and 5 guests