/*******************************************************************************
 * Name         : システムトレード 
 * System       : 
 * type         : 
 * Function     : 
 * References   : 
 * Remarks      : 
 * Version      : 
 * History      :
 * Ver.-----Date--------Name------------Comment---------------------------------
 * 1.00     2007/xx/xx  xxxxxx          新規作成
 ******************************************************************************/
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Magenta
#property indicator_color2 Magenta
#property indicator_color3 Magenta

/*******************************************************************************
 * 入力変数
 ******************************************************************************/
extern double p_period = 15;


/*******************************************************************************
 * グローバル変数
 ******************************************************************************/
double high_line[];
double low_line[];
double sma_line[];

/*******************************************************************************
 * 関数定義
 ******************************************************************************/
/*******************************************************************************
 * 
 * 初期化
 *
 ******************************************************************************/
int init()
{
    string short_name;

    // バッファの設定
    IndicatorBuffers(3);

    SetIndexStyle(0, DRAW_LINE);
    SetIndexBuffer(0, high_line);
    SetIndexLabel(0, "high_line");
    SetIndexEmptyValue(0, 0.0);

    SetIndexStyle(1, DRAW_LINE);
    SetIndexBuffer(1, low_line);
    SetIndexLabel(1, "low_line");
    SetIndexEmptyValue(1, 0.0);

    SetIndexStyle(2, DRAW_LINE);
    SetIndexBuffer(2, sma_line);
    SetIndexLabel(2, "sma_line");
    SetIndexEmptyValue(2, 0.0);

    SetIndexDrawBegin(0, Bars - 1000);
    SetIndexDrawBegin(1, Bars - 1000);
    SetIndexDrawBegin(2, Bars - 1000);

    return(0);
}


/*******************************************************************************
 * 
 * メイン
 *
 ******************************************************************************/
int start()
{
    drawLines();
    return(0);
}


/*******************************************************************************
 * 
 * 描画
 *
 ******************************************************************************/
int drawLines()
{
    int i;
    int counted_bars = IndicatorCounted();

    int pos;

    int num = Bars - counted_bars;
    if(num > 1000){
        num = 1000;
    }

    for(i = num - 1; i >= 0; i--){

        // 高値・安値描画
        pos = iHighest(Symbol(), 0, MODE_HIGH, p_period, i+1); 
        high_line[i] = iHigh(Symbol(), 0, pos);
        pos = iLowest(Symbol(), 0, MODE_LOW, p_period, i+1); 
        low_line[i] = iLow(Symbol(), 0, pos);
        sma_line[i] =iMA(Symbol(), 0, p_period, 0, MODE_SMA, PRICE_CLOSE, i);
    }
    return(0);

}

