サインツールについて質問

 

私は先週からサインツールを作り始めた初心者です。

現在サインツールを作成していて以下のようなコードを書きました。

こちらを実行すると足にサインが出るのですが、足が確定したらサインが出る為エントリーがサインの次の足となります。

したい事としては

①足がコードの条件を満たしたらその足にサインを出すようにしたい。そしてその次足でエントリー。

要は一個前に条件、サインを出したいのですがどこをどう修正したらよいのでしょうか?

#property copyright "R_test"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 6
#property indicator_color1 clrBlue
#property indicator_color2 clrRed
#property indicator_color3 clrAqua
#property indicator_color4 clrDarkOrange
#property indicator_color5 clrLightSkyBlue
#property indicator_color6 clrMagenta

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2

double Buffer_0[], Buffer_1[], Buffer_2[], Buffer_3[], Buffer_4[], Buffer_5[];
int maxlimit = 1000;

//パラメーター設定  
input int RSI_Period = 14; //RSIの期間
input int CCI_Period = 14; //CCIの期間
input double RSI_Upper_Level = 80.0; //RSIの上限
input double RSI_Lower_Level = 25.0; //RSIの下限
input double CCI_Upper_Level = 220.0; //CCIの上限
input double CCI_Lower_Level = -220.0; //CCIの下限

int OnInit()
{
    IndicatorBuffers(6);
  
    SetIndexBuffer(0, Buffer_0);
    SetIndexBuffer(1, Buffer_1);
    SetIndexBuffer(2, Buffer_2);
    SetIndexBuffer(3, Buffer_3);
    SetIndexBuffer(4, Buffer_4);
    SetIndexBuffer(5, Buffer_5);
  
    SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
    SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
    SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID);
    SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID);
    SetIndexStyle(4, DRAW_ARROW, STYLE_SOLID);
    SetIndexStyle(5, DRAW_ARROW, STYLE_SOLID);
  
    SetIndexArrow(0, 233);
    SetIndexArrow(1, 234);
    SetIndexArrow(2, 233);
    SetIndexArrow(3, 234);
    SetIndexArrow(4, 233);
    SetIndexArrow(5, 234);
   
    return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
    ObjectsDeleteAll();
}

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[])
{
    double dRsiNow,dRsiBak,dCciNow,dCciBak;
   
    for(int i=maxlimit; i>=1; i--){
        dRsiNow = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i);
        dRsiBak = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i+1);
        dCciNow = iCCI(NULL,0,CCI_Period,PRICE_CLOSE,i);
        dCciBak = iCCI(NULL,0,CCI_Period,PRICE_CLOSE,i+1);
      
        Buffer_0[i] = EMPTY_VALUE;
        Buffer_1[i] = EMPTY_VALUE;
        Buffer_2[i] = EMPTY_VALUE;
        Buffer_3[i] = EMPTY_VALUE;
        Buffer_4[i] = EMPTY_VALUE;
        Buffer_5[i] = EMPTY_VALUE;
 
        //RSIのサイン
        if(dRsiBak <= RSI_Lower_Level && dRsiNow > RSI_Lower_Level){
            Buffer_0[i] = Low[i];
        }else if(dRsiBak >= RSI_Upper_Level && dRsiNow < RSI_Upper_Level){
            Buffer_1[i] = High[i];
        }
       //CCIのサイン     
        if(dCciBak <= CCI_Lower_Level && dCciNow > CCI_Lower_Level){
            Buffer_2[i] = Low[i];
        }else if(dCciBak >= CCI_Upper_Level && dCciNow < CCI_Upper_Level){
            Buffer_3[i] = High[i];
        }

        // RSIとCCIが両方とも条件を満たした場合のサイン
        if((dRsiBak <= RSI_Lower_Level && dRsiNow > RSI_Lower_Level && dCciBak <= CCI_Lower_Level && dCciNow > CCI_Lower_Level)){
            Buffer_4[i] = Low[i];
        }else if((dRsiBak >= RSI_Upper_Level && dRsiNow < RSI_Upper_Level && dCciBak >= CCI_Upper_Level && dCciNow < CCI_Upper_Level)){
            Buffer_5[i] = High[i];
        }
    }
   
    return(rates_total);
}
ファイル:
km9dcn.png  244 kb
 

矢印の位置をずらすのは簡単です。インデックスをiからi+1に変更するだけです。

Buffer_0[i + 1] = Low[i + 1];

ただしこのようにしたからといって、1本分早く結果が得られるわけではありません。

サインは条件が満たされた時に出るのですから、結局変更前と何も変わりません。

足が確定する前にサインを出したいのなら

for(int i=maxlimit; i>=0; i--){

とすれば可能ですが、確定時には消えている場合もあり得ます。

と、言うわけでこれは無理な注文です。

 
Shino Unada #:

矢印の位置をずらすのは簡単です。インデックスをiからi+1に変更するだけです。

ただしこのようにしたからといって、1本分早く結果が得られるわけではありません。

サインは条件が満たされた時に出るのですから、結局変更前と何も変わりません。

足が確定する前にサインを出したいのなら

とすれば可能ですが、確定時には消えている場合もあり得ます。

と、言うわけでこれは無理な注文です。

やはり無理になってしまいますか...

一度こちらも試してみようと思います!

ありがとうございます!

理由: