刚写的一个多空力量消长的指标 ;(只写了多方的)不知对不对请看!

 
   代码在下一贴
 
//+------------------------------------------------------------------+
//|                                                  Liu's--20--.mq4 |
//|                       Copyright ?2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net/"
 
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 Red
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexDrawBegin(0,1);
   IndicatorShortName("Lius-test-");
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom 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;
//---- macd counted in the 1-st buffer
   double a0,b0,c0,d0,a1,b1,c1,d1;
   for(int i=0; i<limit; i++)
   {
  a0=iOpen(NULL,0,i);
  b0=iClose(NULL,0,i);
  c0=iHigh(NULL,0,i);
  d0=iLow(NULL,0,i);
  a1=iOpen(NULL,0,i-1);
  b1=iClose(NULL,0,i-1);
  c1=iHigh(NULL,0,i-1);
  d1=iLow(NULL,0,i-1);
  if(b0>a0)
  //阳烛
{
if(a0-b1>0)
{
ExtMapBuffer1[i]=MathRound(((a0-b1)+(c0-d0))/Point);
}
if (a0-b1<=0)
{
ExtMapBuffer1[i]=MathRound((c0-d0)/Point);
}
}
//阴烛
if(b0<a0)
{
if(a0-b1>0)
{
ExtMapBuffer1[i]=MathRound(((c0-a0)+(b0-d0)+(a0-b1))/Point);
}
if (a0-b1<=0)
{
ExtMapBuffer1[i]=MathRound(((c0-a0)+(b0-d0))/Point);
}
}
//十字
else 
{
if(a0-b1>0)
{
ExtMapBuffer1[i]=MathRound(((c0-d0)+(a0-b1))/Point);
}
if(a0-b1<=0)
{
ExtMapBuffer1[i]=MathRound((c0-d0)/Point);
}
}
} 
//
//----
   
//----
   return(0);
  }
//+-------------------------------------------http://hi.baidu.com/shangwujuhttp://hi.baidu.com/shangwujuhttp://hi.baidu.com/shangwuju-----------------------+
 
Your code has an error. See
 a1=iOpen(NULL,0,i-1);
  b1=iClose(NULL,0,i-1);
  c1=iHigh(NULL,0,i-1);
  d1=iLow(NULL,0,i-1);
Which value these variables will be when I==0 ? Negative index of bar is not allowed.
 
hello Rosh can you give me a ringt case? thanks!
 

Rosh 你好“请问我前面代码中i和bars用法对吗?谢谢!

 
I think you mean similar that
//+------------------------------------------------------------------+
//|                                                  Liu's--20--.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                    '刚写的一个多空力量消长的指标 ;(只写了多方的)不知对不对请看!' |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "'刚写的一个多空力量消长的指标 ;(只写了多方的)不知对不对请看!'"
 
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 Red
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexDrawBegin(0,1);
   IndicatorShortName("Lius-test-");
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom 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;
//---- macd counted in the 1-st buffer
   double a0,b0,c0,d0,a1,b1,c1,d1;
   for(int i=limit; i>=0; i--)
      {
      a0=Open[i];
      b0=Close[i];
      c0=High[i];
      d0=Low[i];
      a1=Open[i+1];
      b1=Close[i+1];
      c1=High[i+1];
      d1=Low[i+1];
      if(b0>a0)
         //??
         {
         if(a0-b1>0)
            {
            ExtMapBuffer1[i]=MathRound(((a0-b1)+(c0-d0))/Point);
            }
         if (a0-b1<=0)
            {
            ExtMapBuffer1[i]=MathRound((c0-d0)/Point);
            }
         }
      //??
      if(b0<a0)
         {
         if(a0-b1>0)
            {
            ExtMapBuffer1[i]=MathRound(((c0-a0)+(b0-d0)+(a0-b1))/Point);
            }
         if (a0-b1<=0)
            {
            ExtMapBuffer1[i]=MathRound(((c0-a0)+(b0-d0))/Point);
            }
         }
      //??
      else 
         {
         if(a0-b1>0)
            {
            ExtMapBuffer1[i]=MathRound(((c0-d0)+(a0-b1))/Point);
            }
         if(a0-b1<=0)
            {
            ExtMapBuffer1[i]=MathRound((c0-d0)/Point);
            }
         }
      } 
//
//----
   
//----
   return(0);
  }
//+-------------------------------------------


Picture
 

Rosh:

I got it!

thank you very much!

have a good day!