
フラクタルラインの構築
はじめに
フラクタルはすべてのトレーダーによって実践的に使用されています。ただし、彼らのフラクタルとは何かと尋ねたら、ビルウィリアムシステムのインディケータだと答えるのが関の山でしょう。上級トレーダーだと、それは5本の連続したバーで、そこでシーケンスで真ん中のバーの高値が他のバーのよりも高ければ、それは上昇フラクタルで、真ん中のバーの安値が他のバーのよりも低ければ、それは下降フラクタルである、と言うでしょう。俗に言うように、「これが戦争について伝えることのできるすべてなのです」。
フラクタルについての簡単な説明、とりわけその性質と用途、はビル・ウィリアム著 "New Trading Dimensions: How to Profit from Chaos in Stocks, Bonds, and Commodities" に書かれています。Chekulaev の記事"Fractals"(ロシア語)でもなんらかの情報は得られるでしょう。Shiryaev 著の"Fundamentals of Stochastic Mathematics"(ロシア語)では数式についてよく説明されています。
フラクタルの用途
お伝えすべきフラクタル浸透は2種類あります。価格が上昇フラクタルレベルを超える(下降フラクタルレベルより下に落ちる)のが簡単なフラクタル浸透です。この場合、終値を待ち、次のバーのオープンでポジションをオープンした方がよいでしょう。
シンプルなフラクタル浸透を考察する上図ではそれぞれ売りと買いのフラクタルが矢印で印がつけられています。複雑な浸透にはフラクタルが2とおりあります。最後のものと最後から二つ目です。それらは終値による浸透が予想される直線によってつながります。
フラクタルラインが浸透されるとき、エンターポイントは青と赤の矢印で印がつけられます。開発環境である MQL4 はフラクタルイデオロギーを理解するのに役立ちます。
フラクタルをテストする課題を明確にします。
- 売り/買いのフラクタルを描く
- 水平浸透レベルを描く
- フラクタルラインを描く
- 予想エンターポイントを矢印でマークする
売り/買いフラクタル
これは最も基本の部分です。また、で利用可能なインディケータ iF についても考察します(Omega では、このインディケータを自分で書かなければなりませんでした。そしてそれは Omega の特性のためかなりむつかしいものでした)。このインディケータの書き方例はCode Baseにあります。
浸透の水平レベル
標準的な水平ラインを使用します。フラクタルの価格を価格座標、フラクタル形成日として指定し、現時刻は時間座標とします。
ObjectCreate("SimpleUp"+Up,OBJ_TREND,0,bufUpDate[Up], bufUpPrice[Up],Time[i-1],bufUpPrice[Up]); ObjectSet("SimpleUp"+Up,OBJPROP_COLOR,Aqua); ObjectSet("SimpleUp"+Up,OBJPROP_RAY,True);
フラクタルライン
もっとも簡単な方法は 2 点を通ってトレンドラインを引くことのようです。ライン線を作り、浸透を待ちます。ただ実際のところ、終値とフラクタルライン上の価格値を比較することはできなさそうです。というのも、関数 ObjectGet はフラクタルラインを形成するポイント値を返すだけだからです。ではどうすればよいでしょうか?
解析幾何学を思い出す必要があります。. 点が2点あります。よって直線方程式を取得します。そして、時間座標がわかっているので、直線方程式から価格値を簡単に取得することができます。標準的な直線方程式は以下のようなものです。
х と у の代わりに価格と時刻を代入します。実行は浸透レベルを計算する関数 LevelCalculate によって行われ、これと共に関数 ObjectSet によって設定するべきフラクタルの新しい座標を決めます。
ObjectCreate("LineUp"+Up,OBJ_TREND,0,bufUpDate[Up], bufUpPrice[Up],bufUpDate[Up-1],bufUpPrice[Up-1]); ObjectSet("LineUp"+Up,OBJPROP_COLOR,Blue); ObjectSet("LineUp"+Up,OBJPROP_RAY,False);
矢印設定
必要なラインはすべてループ内に作成し、現行価格と比較します。それがシンプルなラインを浸透すれば、黄色の矢印をつけます。フラクタルラインを浸透すれば、買いの矢印はブルー、売りの矢印は赤とします。
これはすべてインディケータFractalLines.mq4 として実行されます。
//+------------------------------------------------------------------+ //| FractalLines.mq4 | //| Copyright © 2006, MetaQuotes Software Corp. | //| https://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, MetaQuotes Software Corp." #property link "https://www.metaquotes.net/" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red //---- input parameters extern int lines=5; //The amount of visible fractal lines extern int MaxFractals=10000; // :) extern bool ShowHorisontalLines=true; extern bool ShowFractalLines=true; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; //--- my variables double bufUpPrice[10000]; //price array of Up fractals double bufUpDate[10000]; //date array of Up fractals double bufDownPrice[10000]; //price array of Down fractals double bufDownDate[10000]; //date array of Down fractals int Up = 0; //counter of Up fractals int Down = 0; //counter of Down fractals //The function calculates the price value of penetration of the fractal line by the simplest //equations of analytic geometry double LevelCalculate(double Price1, double Time1, double Price2, double Time2, double NewTime) { double level; if (Time2!=Time1)// Just in case, to avoid zero divide. { level=(NewTime-Time1)*(Price2-Price1)/(Time2-Time1)+Price1; } else { return(Price2); } return(level); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,217); SetIndexBuffer(0,ExtMapBuffer1); SetIndexEmptyValue(0,0.0); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,218); SetIndexBuffer(1,ExtMapBuffer2); SetIndexEmptyValue(1,0.0); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- the last calculated bar will be recalculated if(counted_bars > 0) counted_bars--; int limit = Bars - counted_bars; // We will rather place arrows at the moment of penetration of fractal lines, // estimate efficiency // The idea was borrowed from Rosh, hopefully he will not be offended by this :) string arrowName; // here, we will give the arrow a unique name //The number of the penetrated fractal //Penetration of the fractal line int FractalUp = 0; int FractalDown = 0; //Simple penetration of a fractal int SimpleFractalUp = 0; int SimpleFractalDown = 0; double BuyFractalLevel = 0; //penetration level of the Up fractal line double SellFractalLevel = 0; //penetration level of the Down fractal line double buf = 0; // buffer value of fractal being available; if it is 0, there is no fractal at all //---- the main loop for(int i = limit; i>0; i--) { //Draw simple fractal levels //Define the current fractal levels BuyFractalLevel=LevelCalculate(bufUpPrice[Up],bufUpDate[Up], bufUpPrice[Up-1],bufUpDate[Up-1],Time[i]); //Move the second coordinate of the Up fractal line ObjectSet("LineUp"+Up,OBJPROP_TIME1,Time[i]); ObjectSet("LineUp"+Up,OBJPROP_PRICE1,BuyFractalLevel); SellFractalLevel=LevelCalculate(bufDownPrice[Down], bufDownDate[Down],bufDownPrice[Down-1], bufDownDate[Down-1],Time[i]); //Move the second coordinate of the Down fractal line ObjectSet("LineDown"+Down,OBJPROP_TIME1,Time[i]); ObjectSet("LineDown"+Down,OBJPROP_PRICE1,SellFractalLevel); //Search for a simple penetration if (Close[i]>ObjectGet("SimpleUp"+Up,OBJPROP_PRICE1)&& (Up>SimpleFractalUp)) { arrowName="SimleUpArrow"+Up; ObjectCreate(arrowName,OBJ_ARROW,0,Time[i-1], Low[i-1]-Point*10); ObjectSet(arrowName,OBJPROP_ARROWCODE,241); ObjectSet(arrowName,OBJPROP_COLOR,Yellow); SimpleFractalUp=Up; } if (Close[i]<ObjectGet("SimpleDown"+Down,OBJPROP_PRICE1)&& (Down>SimpleFractalDown)) { arrowName="SimleUpArrow"+Down; ObjectCreate(arrowName,OBJ_ARROW,0,Time[i-1], High[i-1]+Point*10); ObjectSet(arrowName,OBJPROP_ARROWCODE,242); ObjectSet(arrowName,OBJPROP_COLOR,Yellow); SimpleFractalDown=Down; } //Search for a complex penetration if ((Close[i]>BuyFractalLevel)&&(Up>FractalUp)) { //Put an up-arrow arrowName="UpArrow"+Up; ObjectCreate(arrowName,OBJ_ARROW,0,Time[i-1], Low[i-1]-Point*10); ObjectSet(arrowName,OBJPROP_ARROWCODE,241); ObjectSet(arrowName,OBJPROP_COLOR,Blue); FractalUp=Up; } if ((Close[i]<SellFractalLevel)&&(Down>FractalDown)) { //Put a down-arrow arrowName="DownArrow"+Down; ObjectCreate(arrowName,OBJ_ARROW,0,Time[i-1], High[i-1]+Point*10); ObjectSet(arrowName,OBJPROP_ARROWCODE,242); ObjectSet(arrowName,OBJPROP_COLOR,Red); FractalDown=Down; } //Draw the Up fractal itself ExtMapBuffer1[i] = iFractals(NULL, 0, MODE_UPPER, i); //If it is available, place it in the array of fractals buf = iFractals(NULL, 0, MODE_UPPER, i); if (buf!=0) { Up++; bufUpPrice[Up]=iFractals(NULL, 0, MODE_UPPER, i); bufUpDate[Up]=Time[i]; //The current fractal penetration level - fractal itself BuyFractalLevel=bufUpPrice[Up]; if (Up>1) { //Simple fractal ObjectCreate("SimpleUp"+Up,OBJ_TREND,0,bufUpDate[Up], bufUpPrice[Up],Time[i-1],bufUpPrice[Up]); ObjectSet("SimpleUp"+Up,OBJPROP_COLOR,Aqua); ObjectSet("SimpleUp"+Up,OBJPROP_RAY,True); //Draw fractal lines on 2 coordinates ObjectCreate("LineUp"+Up,OBJ_TREND,0,bufUpDate[Up], bufUpPrice[Up],bufUpDate[Up-1],bufUpPrice[Up-1]); ObjectSet("LineUp"+Up,OBJPROP_COLOR,Blue); ObjectSet("LineUp"+Up,OBJPROP_RAY,False); //Remove the outdated lines if (Up>lines+1) { ObjectDelete("LineUp"+(Up-lines)); ObjectDelete("SimpleUp"+(Up-lines)); } } } //A similar block, but for Down fractals ExtMapBuffer2[i] = iFractals(NULL, 0, MODE_LOWER, i); buf = iFractals(NULL, 0, MODE_LOWER, i); if (buf!=0) { Down++; bufDownPrice[Down]=iFractals(NULL, 0, MODE_LOWER, i); bufDownDate[Down]=Time[i]; SellFractalLevel=bufDownPrice[Down]; if (Down>1) { ObjectCreate("SimpleDown"+Down,OBJ_TREND,0,bufDownDate[Down], bufDownPrice[Down],Time[i-1],bufDownPrice[Down]); ObjectSet("SimpleDown"+Down,OBJPROP_COLOR,LightCoral); ObjectSet("SimpleDown"+Down,OBJPROP_RAY,True); ObjectCreate("LineDown"+Down,OBJ_TREND,0, bufDownDate[Down],bufDownPrice[Down], bufDownDate[Down-1],bufDownPrice[Down-1]); ObjectSet("LineDown"+Down,OBJPROP_COLOR,Red); ObjectSet("LineDown"+Down,OBJPROP_RAY,False); if (Down>lines+1) { ObjectDelete("LineDown"+(Down-lines)); ObjectDelete("SimpleDown"+(Down-lines)); } } } if (!ShowHorisontalLines) { ObjectDelete("SimpleDown"+Down); ObjectDelete("SimpleUp"+Up); } if (!ShowFractalLines) { ObjectDelete("LineDown"+Down); ObjectDelete("LineUp"+Up); } } //---- return(0); } //+-----------------------------------------------------------------
古いラインは消去されます。そうでなければ、チャートは絵具のパレットのようになってしまいます。インディケータ内に、ラインの可視性、その数量といった2~3追加の設定を行います。インディケータ処理の結果は以下に提供しています。
これはフラクタルが好きな人に役立つものです。
MetaQuotes Ltdによってロシア語から翻訳されました。
元の記事: https://www.mql5.com/ru/articles/1429



- 無料取引アプリ
- 8千を超えるシグナルをコピー
- 金融ニュースで金融マーケットを探索