チャートにうまく描画できないのを修正したい

 
//+------------------------------------------------------------------+
//|                                                   Snake_alfa.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.02"
#property strict
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrWhite

// パラメーター
input int Snake_HalfCycle = 7;    // Snake_HalfCycle
input int InpBars         = 1000; // Custom_Bars

// バッファ
double Snake_Buffer[];
double TempBuffer[];

// グローバル変数
double Snake_Sum, Snake_Weight, Snake_Sum_Minus, Snake_Sum_Plus;
int Snake_FullCycle;
int draw_begin;

//+------------------------------------------------------------------+
//| LWMA(線形加重移動平均)の計算関数                               |
//+------------------------------------------------------------------+
double CalculateLWMA(int shift, const double &price_array[], int period)
{
    double sum = 0.0, weight_sum = 0.0;
    for (int i = 0; i < period; i++)
    {
        double weight = period - i; // 重み付け
        sum += price_array[shift - i] * weight; // 価格に重みを掛ける
        weight_sum += weight; // 総重みを計算
    }
    return sum / weight_sum; // LWMAの結果を返す
}

//+------------------------------------------------------------------+
//| Snakeの最初の計算                                                |
//+------------------------------------------------------------------+
double SnakeFirstCalc(int shift, const double &close_array[], const double &high_array[], const double &low_array[])
{
    int period = Snake_HalfCycle * 2 + 1; // LWMAの計算期間
    double price_array[];

    // 配列にデータをコピー(close, high, lowを合成)
    ArrayResize(price_array, period);
    for (int i = 0; i < period; i++)
    {
        price_array[i] = (2 * close_array[shift - i] + high_array[shift - i] + low_array[shift - i]) / 4;
    }

    return CalculateLWMA(shift, price_array, period); // LWMA計算結果を返す
}

//+------------------------------------------------------------------+
//| Snakeの次の計算                                                  |
//+------------------------------------------------------------------+
double SnakeNextCalc(int shift, const double &close_array[], const double &high_array[], const double &low_array[])
{
    int period = Snake_HalfCycle * 2 + 1; // LWMAの計算期間
    double price_array[];

    // 配列にデータをコピー(close, high, lowを合成)
    ArrayResize(price_array, period);
    for (int i = 0; i < period; i++)
    {
        price_array[i] = (2 * close_array[shift - i] + high_array[shift - i] + low_array[shift - i]) / 4;
    }

    return CalculateLWMA(shift, price_array, period); // LWMA計算結果を返す
}

//+------------------------------------------------------------------+
//| インジケーター初期化関数                                         |
//+------------------------------------------------------------------+
int OnInit()
{
    // バッファ設定
    SetIndexBuffer(0, Snake_Buffer, INDICATOR_DATA);
    SetIndexBuffer(1, TempBuffer, INDICATOR_CALCULATIONS);

    // バッファ初期化
    ArrayInitialize(Snake_Buffer, EMPTY_VALUE);
    ArrayInitialize(TempBuffer, EMPTY_VALUE);

    // その他設定
    Snake_FullCycle = Snake_HalfCycle * 2 + 1;
    draw_begin = Snake_FullCycle + 1;

    PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin);
    PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
    PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 2);

    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| インジケーター計算関数                                           |
//+------------------------------------------------------------------+
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[])
{
    int FirstPos, ExtCountedBars = 0;

    if(rates_total <= Snake_HalfCycle) return(0);

    ExtCountedBars = prev_calculated;

    if (ExtCountedBars < 0) return(-1);
    if (ExtCountedBars > 0) ExtCountedBars--;
    FirstPos = rates_total - ExtCountedBars - 1;

    if(FirstPos > rates_total - Snake_HalfCycle - 1)
    {
        FirstPos = rates_total - Snake_HalfCycle - 1;
    }

    // Snake計算関数を呼び出し
    Snake(FirstPos, rates_total, close, high, low);

    // 古い表示データを削除
    for(int i = 0; i < rates_total - InpBars; i++)
    {
        Snake_Buffer[i] = EMPTY_VALUE;
    }

    return(rates_total);
}

//+------------------------------------------------------------------+
//| Snakeの計算ロジック                                              |
//+------------------------------------------------------------------+
void Snake(int Pos, int rates_total, const double &close_array[], const double &high_array[], const double &low_array[])
{
    // 初回計算
    for (int i = Pos; i >= Snake_HalfCycle; i--)
    {
        Snake_Buffer[i] = SnakeFirstCalc(i, close_array, high_array, low_array);
    }

    // 次の計算
    for (int i = Pos - 1; i >= 0; i--)
    {
        Snake_Buffer[i] = SnakeNextCalc(i, close_array, high_array, low_array);
    }
}

上記のように修正してみましたが、いまだになおりません。。。

ファイル:
 
クリティカルエラーが発生し、デバックをストップしましたとなります、、お手上げ、、何がどう悪いのか、もう僕ではわかりません、なんとかならないでしょうか、、よろしくお願いします、
 

プログラムが完全に別物になっています。

これに構っていると私はトレードができないので、私が以前作成したプログラムをアップロードしておきます。

ファイル:
Snake.mq5  7 kb
 

ありがとうございます。ちゃんと描画するのが不思議で仕方がないほどの知識しかありませが、これからも勉強を続けてみようと思います。

ほんとうに重ね重ねありがとうございます。