zhoutao!!! 发表于 2014-10-23 12:12:20

这段代码有什么错误的地方吗,为什么数组b[] 里没有被赋...

int a,d,b[];
   int i,c=100;
for(a=0;a<c;a++){
b=a+100;}
Print(b);
这段代码有什么错误的地方吗,为什么数组b[] 里没有被赋值,输出全是0的啊,求高手解答。(编译的时候没有出现错误的)

bapi 发表于 2014-10-23 15:09:30

Array 需要定义大小后再使用.

int a,d,b[];
   int i,c=100;
   ArrayResize(b,c);
for(a=0;a<c;a++){
b=a+100;}
Print(b);

zhoutao!!! 发表于 2014-10-23 18:01:36

本帖最后由 zhoutao!!! 于 2014-10-23 18:08 编辑

bapi 发表于 2014-10-23 15:09
Array 需要定义大小后再使用.

int a,d,b[];


嗯嗯,要定义范围的吗,这样也可以的吗



int a,d,b;
    int i,c=100;
   for(a=0;a<c;a++){
   b=a+100;}
   Print(b);
我始终没明白 我看有些指标没有定义数组范围,比如MT4自带的RSI指标:
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int RSIPeriod=14;
//---- buffers
double RSIBuffer[];{:soso_e135:}
double PosBuffer[];{:soso_e118:}
double NegBuffer[];{:soso_e118:}

else
      {
         //---- smoothed moving average
         rel=Close-Close;
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(PosBuffer*(RSIPeriod-1)+sump)/RSIPeriod;
         negative=(NegBuffer*(RSIPeriod-1)+sumn)/RSIPeriod;
      }
      PosBuffer【i】=positive;   {:soso_e117:}
      NegBuffer【i】=negative;   {:soso_e117:}
      if(negative==0.0) RSIBuffer=0.0;
      else RSIBuffer=100.0-100.0/(1+positive/negative);
      i--;
   }
这是怎么回事的 ,大哥说下嘛

zhoutao!!! 发表于 2014-10-23 18:05:26

本帖最后由 zhoutao!!! 于 2014-10-23 18:06 编辑

zhoutao!!! 发表于 2014-10-23 18:01
嗯嗯,要定义范围的吗,这样也可以的吗




PosBuffer
      NegBuffer
上面的是这个怎么没发显示【】这个括号的啊{:soso_e117:}

zhoutao!!! 发表于 2014-10-23 18:12:57

在帮看下下面这个事怎么回事的 。
#property copyright "369外汇(www.369fx.com)"
#property link      "http://www.369fx.com";

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 LimeGreen
#property indicator_color2 FireBrick
#property indicator_color3 DodgerBlue
#property indicator_color4 Red
#property indicator_color5 Black

extern string separator1 = "*** OSMA Settings ***";
extern int fastEMA = 12;
extern int slowEMA = 26;
extern int signal = 9;
extern string separator2 = "*** Indicator Settings ***";
extern double positiveSensitivity = 0.0001;
extern double negativeSensitivity = -0.0001;
extern double historyBarsCount = 0.0;
extern bool drawDivergenceLines = TRUE;
extern bool displayAlert = TRUE;
double g_ibuf_136[];
double g_ibuf_140[];
double g_ibuf_144[];
double g_ibuf_148[];
double g_ibuf_152[];
datetime g_time_156;

void ads() {
   SetLab("ads01", 1, 10, 3, "www.51rbz.com 24H咨询QQ1668636566", 11, "Arial", Red);
}

void SetLab(string a_name_0, int a_x_8, int a_y_12, int a_corner_16, string a_text_20, int a_fontsize_28, string a_fontname_32, color a_color_40 = -1) {
   ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0);
   ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8);
   ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12);
   ObjectSet(a_name_0, OBJPROP_CORNER, a_corner_16);
   ObjectSetText(a_name_0, a_text_20, a_fontsize_28, a_fontname_32, a_color_40);
}

int init() {
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexStyle(4, DRAW_NONE);
   SetIndexBuffer(0, g_ibuf_136);
   SetIndexBuffer(1, g_ibuf_140);
   SetIndexBuffer(2, g_ibuf_144);
   SetIndexBuffer(3, g_ibuf_148);
   SetIndexBuffer(4, g_ibuf_152);
   SetIndexArrow(2, 233);
   SetIndexArrow(3, 234);
   IndicatorDigits(Digits + 2);
   IndicatorShortName("FX5_Divergence_v2.0(" + fastEMA + "," + slowEMA + "," + signal + ")");
   return (0);
}

int deinit() {
   string l_name_4;
   ads();
   for (int li_0 = ObjectsTotal() - 1; li_0 >= 0; li_0--) {
      l_name_4 = ObjectName(li_0);
      if (StringSubstr(l_name_4, 0, 14) == "DivergenceLine") ObjectDelete(l_name_4);
   }
   return (0);
}

int start() {
   int l_ind_counted_0 = IndicatorCounted();
   if (l_ind_counted_0 < 0) l_ind_counted_0 = 1;
   CalculateIndicator(l_ind_counted_0);
   return (0);
}


void CalculateIndicator(int ai_1) {
   for (int li_4 = Bars - ai_1; li_4 > 0; li_4--) {
      CalculateOsMA(li_4);
   // CatchBullishDivergence(li_4 + 2);
      //CatchBearishDivergence(li_4 + 2);
   }
}

void CalculateOsMA(int ai_0) {
:Q:Qg_ibuf_152 = iOsMA(NULL, 0, fastEMA, slowEMA, signal, PRICE_CLOSE, ai_0);
   if (g_ibuf_152 > 0.0) {
      g_ibuf_136 = g_ibuf_152;
      g_ibuf_140 = 0;

上面有表情的哪行代码加载图表时 ,出现 数组越界提示,,指标加不上图表,求解答

bapi 发表于 2014-10-23 21:49:50

SetIndexBuffer 函数会自动设定动态大小数组, 所以不用另外设大小

zhoutao!!! 发表于 2014-10-24 15:14:57

bapi 发表于 2014-10-23 21:49
SetIndexBuffer 函数会自动设定动态大小数组, 所以不用另外设大小

哦哦 懂了 。
可不可以看看上面的代码。我在这个网站下载的指标,加载图表的时候,没有显示 ,查看日志 出现数组越界提示,就是上面有表情哪行代码,我查看代码感觉没错 ,编译也通过了的 没错误提示。

ajfy666 发表于 2014-10-25 13:30:55

新手学习 多多关照

zhoutao!!! 发表于 2014-10-25 17:35:01

ajfy666 发表于 2014-10-25 13:30
新手学习 多多关照

{:soso_e113:} 一样 都新手的

kuangren90 发表于 2017-2-5 18:27:36

谢谢分享,学编程,学交易,实现程序化交易。
页: [1]
查看完整版本: 这段代码有什么错误的地方吗,为什么数组b[] 里没有被赋...