Fractal_Level_Xrust

Download script
Author: #Copyright � 2008, XrustSolution.#
Fractal_Level_Xrust

This script is designed as a visual trading tool for MetaTrader 4 that automatically identifies and displays key support and resistance levels based on "fractals." In technical analysis, fractals are specific price points where the market has reached a local peak or valley, helping traders visualize where the price might face future turning points.

Core Functionality

The script automatically scans the current chart to find the most recent fractal high (peak) and fractal low (valley). Once identified, it draws two distinct horizontal lines on your chart:

  • Upper Level (Resistance): This line identifies a recent price peak. The script allows you to set a specific "Distance" (in points) to offset this line above the actual fractal point.
  • Lower Level (Support): This line identifies a recent price valley. Similarly, it can be adjusted by a set distance in points below the fractal point.

Dynamic Updating

The logic is designed to be reactive. The script constantly monitors the price action:

  1. It searches backward through recent history to find the nearest confirmed fractals.
  2. If a new fractal is formed that changes the previous level, the script automatically deletes the old horizontal line and draws a new one at the updated price point.
  3. This ensures that your chart always reflects the most current structural boundaries of the market without manual intervention.

User Interface & Information

To provide a comprehensive overview for the trader, the script includes several user-friendly features:

  • Visual Customization: You can choose the colors for the upper and lower lines (e.g., Blue for resistance and Red for support) to make them easily distinguishable.
  • On-Screen Data: If the "comment" feature is enabled, the script displays a real-time summary in the corner of your chart. This includes the current timeframe, the exact price levels for both the upper and lower lines, and the total distance (the "Fractal Channel") between the two levels measured in points.
  • Automatic Naming: The script automatically assigns unique names to the lines based on the timeframe, preventing conflicts with other indicators or manual drawings on your chart.

Summary for the Trader

This tool simplifies market analysis by automating the identification of "price floors" and "price ceilings." By instantly projecting these levels onto your screen, it helps you visualize the trading range and potential zones where price action may stall or reverse.

Indicators Used
Fractals
11 Views
0 Downloads
0 Favorites
Fractal_Level_Xrust
//+------------------------------------------------------------------+
//|                                          Fractal_Level_Xrust.mq4 |
//|                                 Copyright © 2008, XrustSolution. |
//|                                            http://xrust.ucoz.net |
//+------------------------------------------------------------------+
#property copyright "#Copyright © 2008, XrustSolution.#"
#property link      "#xrust.ucoz.net#"

#property indicator_chart_window
extern int    TimeFrame=0;//Åñëè=0, òî òåêóøèé
extern int    Distanse=0;//Äèñòàíöèÿ ëèíèè îò ôðàêòàëà â ïóíêòàõ
extern string FrApNam="Ap";//Èìÿ ëèíèè ñîîòâ.Ôðàêòàëó ââåðõ
extern string FrDnNam="Dn";//Èìÿ ëèíèè ñîîòâ.Ôðàêòàëó âíèç
extern color  ClAp=Blue;//Öâåò ëèíèè ñîîòâ.Ôðàêòàëó ââåðõ
extern color  ClDn=Red;//Öâåò ëèíèè ñîîòâ.Ôðàêòàëó âíèç
extern bool   comment=true;//Ðàçðåùåíèå íà êîììåíòàðèé
//-----------------------------------------------------------------------------+
double FrPrise;
double FrApPrise=0,FrDnPrise=0;
//+----------------------------------------------------------------------------+
void init(){
  if(TimeFrame==0){TimeFrame=Period();}
  IndicatorShortName("Factal_Level_Xrust"+TimeFrame);
  FrApNam=StringConcatenate(FrApNam,TimeFrame);
  FrDnNam=StringConcatenate(FrDnNam,TimeFrame);
  return;}
void deinit(){
  ObjectDelete(FrDnNam);
  ObjectDelete(FrApNam);
  Comment(" ");
  return;}
//+----------------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit;
   double tmp;
   int i, j,k;
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//-----------------------------------------------------------------------------+
   LineAp();
   LineDn();
   string FAP=DoubleToStr((FrApPrise-Distanse*Point),Digits);
   string FDP=DoubleToStr((FrDnPrise+Distanse*Point),Digits);
   int diap=MathRound((FrApPrise-FrDnPrise)/Point);
   if(comment){Comment("TimeFrame="+TimeFrame+
                       "\nApPrise ="+FAP+
                       "\nDnPrise ="+FDP+
                       "\nFractal Channel ="
                       +diap+"Point");}

   return(0);
  }
//-----------------------------------------------------------------------------+
// Èùåò ãîðèçîíòàëüíóþ ëèíèþ ïî èìåíè ïåðåðèñîâûâàåò åñëè èçìåíèëàñü öåíà      |   
//-----------------------------------------------------------------------------+
   void LineDn(){
   FrPrise=NormalizeDouble(FindNearFractal(0,TimeFrame,MODE_LOWER),MarketInfo(Symbol(),MODE_DIGITS));
   FrPrise=NormalizeDouble(FrPrise-Distanse*Point,MarketInfo(Symbol(),MODE_DIGITS));
   //Comment(FrPrise);
   if(ObjectFind(FrDnNam)==0){
     if(ObjectGet(FrDnNam,OBJPROP_PRICE1)==FrPrise){return;}}
   FrDnPrise=FrPrise;  
   ObjectDelete(FrDnNam);
   SetHLine(ClDn,FrDnNam,FrDnPrise,0,1);
   WindowRedraw();
   return;} 
//-----------------------------------------------------------------------------+
// Èùåò ãîðèçîíòàëüíóþ ëèíèþ ïî èìåíè ïåðåðèñîâûâàåò åñëè èçìåíèëàñü öåíà      | 
//-----------------------------------------------------------------------------+
   void LineAp(){
   FrPrise=NormalizeDouble(FindNearFractal(0,TimeFrame,MODE_UPPER),MarketInfo(Symbol(),MODE_DIGITS));
   FrPrise=NormalizeDouble(FrPrise+Distanse*Point,MarketInfo(Symbol(),MODE_DIGITS));
   if(ObjectFind(FrApNam)==0){
     if(ObjectGet(FrApNam,OBJPROP_PRICE1)==FrPrise){return;}}
   FrApPrise=FrPrise; 
   ObjectDelete(FrApNam); 
   SetHLine(ClAp,FrApNam,FrApPrise,0,1);
   WindowRedraw();
   return;}
//-----------------------------------------------------------------------------+   
//   Êèìó Ðåñïåêò è óâàæóõà !!!                                                |       
//+----------------------------------------------------------------------------+
//|  Àâòîð    : Êèì Èãîðü Â. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Âåðñèÿ   : 07.10.2006                                                     |
//|  Îïèñàíèå : Ïîèñê áëèæàéøåãî ôðàêòàëà. Âîçâðàùàåò öåíîâîé óðîâåíü.         |
//+----------------------------------------------------------------------------+
//|  Ïàðàìåòðû:                                                                |
//|    sy   - íàèìåíîâàíèå èíñòðóìåíòà      ("" èëè NULL - òåêóùèé ñèìâîë)     |
//|    tf   - òàéìôðåéì                     (    0       - òåêóùèé ÒÔ)         |
//|    mode - òèï ôðàêòàëà                  (MODE_LOWER|MODE_UPPER)            |
//+----------------------------------------------------------------------------+
double FindNearFractal(string sy="0", int tf=0, int mode=MODE_LOWER) {
  if (sy=="" || sy=="0") sy=Symbol();
  double f=0;
  int    d=MarketInfo(sy, MODE_DIGITS), s;
  if (d==0) if (StringFind(sy, "JPY")<0) d=4; else d=2;

  for (s=2; s<100; s++) {
    f=iFractals(sy, tf, mode, s);
    if (f!=0) return(NormalizeDouble(f, d));
  }
  Print("FindNearFractal(): Ôðàêòàë íå íàéäåí");
  return(0);
}
//+----------------------------------------------------------------------------+
//|  Àâòîð    : Êèì Èãîðü Â. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Âåðñèÿ   : 30.03.2008                                                     |
//|  Îïèñàíèå : Óñòàíîâêà îáúåêòà OBJ_HLINE ãîðèçîíòàëüíàÿ ëèíèÿ               |
//+----------------------------------------------------------------------------+
//|  Ïàðàìåòðû:                                                                |
//|    cl - öâåò ëèíèè                                                         |
//|    nm - íàèìåíîâàíèå               ("" - âðåìÿ îòêðûòèÿ òåêóùåãî áàðà)     |
//|    p1 - öåíîâîé óðîâåíü            (0  - Bid)                              |
//|    st - ñòèëü ëèíèè                (0  - ïðîñòàÿ ëèíèÿ)                    |
//|    wd - øèðèíà ëèíèè               (0  - ïî óìîë÷àíèþ)                     |
//+----------------------------------------------------------------------------+
void SetHLine(color cl, string nm="", double p1=0, int st=0, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (p1<=0) p1=Bid;
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_HLINE, 0, 0,0);
  ObjectSet(nm, OBJPROP_PRICE1, p1);
  ObjectSet(nm, OBJPROP_COLOR , cl);
  ObjectSet(nm, OBJPROP_STYLE , st);
  ObjectSet(nm, OBJPROP_WIDTH , wd);
}

Comments