インディケータ: AutoTrendLines - ページ 2

 
ショー
 
Autotrendlinesは最高の無料インジケーターの一つです。このインジケータの作成者に感謝します。しかし、大きな問題があります!ユーザー自身が引いたトレンドラインを 削除してしまうのです。この問題が修正されるのを長い間待っていました。新しいアップデートでこの問題が解決されれば、とてもありがたいです。
 
Autotrendlinesは最高の無料インジケーターの一つです。このインジケータの作成者に感謝します。しかし、大きな問題があります!ユーザー自身が引いたトレンドラインを 削除してしまうのです。この問題が修正されるのを長い間待っていました。新しいアップデートでこの問題が解決されれば、とてもありがたいです。
 
ここでは、インジケータによって作成されたラインのみを削除し、チャート上に他のトレンドを残すレビュー //+------------------------------------------------------------------------+ //| AutoTrendLines.mq5 | //| Copyright 2012, Rone.| //| rone.sergey@gmail.com | //+--------------------------------------------------------------------------+// https://www.mql5.com/ja/code/1220//+--------------------------------------------------------------------------+ //| 自動トレンドライン。| //| タイプ 1。2つの極値を持つ。| //| 1) 現在のバーから左に "移動 "し、両側の InpRightExmSide バーで最初の | //| (右) 極値ポイントを探します。| //| 2) 最初のポイントから再び左へ「移動」し、両側のInpLeftExmSideバーで2番目の(左)極値ポイントを探します。| 3) トレンド線を引く。| タイプ2。極値とデルタを使用。| //| 1) 現在のバーから左に "移動 "し、両側のInpLeftExmSideバーで2番目の|//|(左)極値ポイントを探す。| //| 3) トレンドラインを引く。| //| 注意: | //| 1) 線は、新しいバーが表示された時のみ再計算される | //| 2) 現在の形成されていないバーは計算に含まれない | //| 3) 極値とは、左と右の | //| N 本のバーが、上に最小値、下に最大値を持つバーを意味する。| //+------------------------------------------------------------------------+ #property copyright "Copyright 2012, Rone." #property link "rone.sergey@gmail.com" #property version "1.00" #property description "自動トレンドライン" //--- #property indicator_chart_window //--- string prefisso="AUTO_TRND"; enum ENUM_LINE_TYPE { EXM_EXM, // 1: 2つの極値による EXM_DELTA // 2: 極値とデルタ }; //++--------------------------------------------------+ //| Class CPoint | //++--------------------------------------------------+ class CPoint { private: double price; datetime time; public:CPoint(); CPoint(const double p, const datetime t); ~CPoint() {}; void setPoint(const double p, const datetime t); bool operator==(const CPoint &other) const; bool operator!=(const CPoint &other) const; void operator=(const CPoint &other); double getPrice() const; datetime getTime() const; }; //--- CPoint::CPoint(void) { price = 0; time = 0; } //--- CPoint::CPoint(const double p, const datetime t) { price = p; time = t; } //--- void CPoint::setPoint(const double p, const datetime t) { price = p; time = t; } //--- bool CPoint::operator==(const CPoint &other) const { return price == other.price && time == other.time; } //--- bool CPoint::operator!=(const CPoint &other) const { return !operator==(other); } //--- void CPoint::operator=(const CPoint &other) { price = other.price; time = other.time; } //--- double CPoint::getPrice(void) const { return(price); } //--- datetime CPoint::getTime(void) const { return(time); } //+------------------------------------------------------------------+ //| | //+--------------------------------------------------+ CPoint curLeftSup, curRightSup, curLeftRes, curRightRes, nullPoint; //+----------------------------------------------------------+ //| 入力パラメータ | //+----------------------------------------------------------+ input ENUM_LINE_TYPE InpLineType = EXM_DELTA;// ラインタイプ input int InpLeftExmSide = 10; // 左端側(タイプ1, 2) input int InpRightExmSide = 3; // 右端側(タイプ1) input int InpFromCurrent = 3;// 現在のバーからのオフセット (Type 2) input bool InpPrevExmBar = false; // 極値より前のバーを考慮 (Type 2) //--- input int InpLinesWidth = 2; // ライン幅 input color InpSupColor = clrRed; // サポートラインの色 input color InpResColor = clrBlue; // 抵抗ラインの色 //--- global variables int minRequiredBars; //+------------------------------------------------------------------+ //| カスタムインジケータ初期化関数 | //+------------------------------------------------------------------+ int OnInit() { //--- minRequiredBars = InpLeftExmSide * 2 + MathMax(InpRightExmSide, InpFromCurrent) * 2; //--- インジケータバッファのマッピング //--- return(0); } //+------------------------------------------------------------------+ //| カスタムインジケータ初期化関数 | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- int obj_total = ObjectsTotal(0,0);for(int i=obj_total -1; i>=0; i--) { string name= ObjectName(0,i); if(StringFind(name,prefisso,0) == 0) ObjectDelete(0, name);} //--- } //+------------------------------------------------------------------------+ //| カスタムインジケータ繰り返し関数 | //+--------------------------------------------------------+ 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 leftIndex, rightIndex;double delta, tmpDelta; //--- if ( rates_total < minRequiredBars ) { Print("Not enough data to calculate"); return(0); } //--- if ( prev_calculated != rates_total ) { switch ( InpLineType ) { case EXM_DELTA: //--- 左ポイントをサポート leftIndex = rates_total - InpLeftExmSide - 2; for ( ;isLowestLow(leftIndex, InpLeftExmSide, low) && leftIndex > minRequiredBars; leftIndex-- ); curLeftSup.setPoint(low[leftIndex], time[leftIndex]); //--- 右ポイントをサポート rightIndex = rates_total - InpFromCurrent - 2; delta = (low[rightIndex] - low[leftIndex]) / (rightIndex - leftIndex); if ( !InpPrevExmBar ) { leftIndex += 1; } for ( int tmpIndex = rightIndex - 1; tmpIndex > leftIndex; tmpIndex-- ) { tmpDelta = (low[tmpIndex] - curLeftSup.getPrice()) / (tmpIndex - leftIndex); if ( tmpDelta < delta ) { delta = tmpDelta; rightIndex = tmpIndex; }.} curRightSup.setPoint(low[rightIndex], time[rightIndex]); //--- 抵抗左ポイント leftIndex = rates_total - InpLeftExmSide - 2; for ( ;isHighestHigh(leftIndex, InpLeftExmSide, high) && leftIndex > minRequiredBars; leftIndex-- ); curLeftRes.setPoint(high[leftIndex], time[leftIndex]); //---抵抗右ポイント rightIndex = rates_total - InpFromCurrent - 2; delta = (high[leftIndex] - high[rightIndex]) / (rightIndex - leftIndex); if ( !InpPrevExmBar ) { leftIndex += 1; } for ( int tmpIndex = rightIndex - 1; tmpIndex > leftIndex; tmpIndex-- ) { tmpDelta = (curLeftRes.getPrice() - high[tmpIndex]) / (tmpIndex - leftIndex); if ( tmpDelta < delta ) { delta = tmpDelta; rightIndex = tmpIndex; }.} curRightRes.setPoint(high[rightIndex], time[rightIndex]); //--- break; case EXM_EXM: デフォルト://--- サポート右ポイント rightIndex = rates_total - InpRightExmSide - 2; for ( ;isLowestLow(rightIndex, InpRightExmSide, low) && rightIndex > minRequiredBars; rightIndex-- ); curRightSup.setPoint(low[rightIndex], time[rightIndex]); //---サポート左ポイント leftIndex = rightIndex - InpRightExmSide; for ( ;isLowestLow(leftIndex, InpLeftExmSide, low) && leftIndex > minRequiredBars; leftIndex-- ); curLeftSup.setPoint(low[leftIndex], time[leftIndex]); //---抵抗右ポイント rightIndex = rates_total - InpRightExmSide - 2; for ( ;isHighestHigh(rightIndex, InpRightExmSide, high) && rightIndex > minRequiredBars; rightIndex-- ); curRightRes.setPoint(high[rightIndex], time[rightIndex]); //--- Resistance Left Point leftIndex = rightIndex - InpRightExmSide; for ( ; !isHighestHigh(leftIndex, InpLeftExmSide, high) && leftIndex > minRequiredBars; leftIndex-- ); curLeftRes.setPoint(high[leftIndex], time[leftIndex]); //--- break; }//--- もし ( curLeftSup != nullPoint && curRightSup != nullPoint ) { drawLine(prefisso+"Current_Support", curRightSup, curLeftSup, InpSupColor); } if ( curLeftRes != nullPoint && curRightRes != nullPoint ) { drawLine(prefisso+"Current_Resistance", curRightRes, curLeftRes, InpResColor); } } //--- pre_supportの値を返す。} //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| The Local Low search function | //+------------------------------------------------------------------+ bool isLowestLow(int bar, int side, const double &Low[]) { //--- for ( int i = 1; i <= side; i++ ) { if ( Low[bar] > Low[bar-i] || Low[bar] > Low[bar+i] ) { return(false); }} //--- return(true); } //+------------------------------------------------------------------+ //| The Local High search function | //+------------------------------------------------------------------+ bool isHighestHigh(int bar, int side, const double &High[]) { //--- for ( int i = 1; i <= side; i++ ) { if ( High[bar] < High[bar-i] || High[bar] < High[bar+i] ) { return(false); }} //--- return(true); } //+------------------------------------------------------------------+ //| トレンドラインの描画関数| //+--------------------------------------------------+ void drawLine(string name, CPoint &right, CPoint &left, color clr) { //--- ObjectDelete(0, name); //--- ObjectCreate(0, name, OBJ_TREND, 0, right.getTime(), right.getPrice(), left.getTime(), left.getPrice()); ObjectSetInteger(0, name, OBJPROP_WIDTH, InpLinesWidth); ObjectSetInteger(0, name, OBJPROP_COLOR, clr); ObjectSetInteger(0, name, OBJPROP_RAY_LEFT, true); ObjectSetInteger(0, name, OBJPROP_SELECTABLE, true); //--- } //+-----------------------------------------------------------------------------------------------+
 
素敵なコードですが、トレンドラインが頻繁に動いていて、下降トレンドの場合は負のスロープ、上昇トレンドの場合は正のスロープになるはずです。