FanSimple8-1bEnL

Author: Copyright � 2006, MetaQuotes Software Corp.
FanSimple8-1bEnL

This script is a visual analysis tool designed to help traders track market trends across multiple timeframes simultaneously. It functions by creating a "Fan" of moving averages and providing real-time status updates on how the current price relates to those averages.

Core Functionality

Multi-Timeframe Analysis The tool allows you to monitor several different timeframes (such as 1-minute, 5-minute, Hourly, Daily, etc.) at the same time. Instead of jumping between different charts, the script pulls data from these various intervals and displays the results in a centralized dashboard on your main chart.

The Moving Average "Fan" The script calculates a series of moving averages—customizable by period, type (e.g., Simple or Exponential), and price source. These are displayed as lines on your chart. By looking at these lines together, you can see the "fan" of momentum; when the lines are spread apart and moving in a specific direction, it indicates a stronger trend.

Real-Time Status Dashboard The most distinct feature of this script is its automated status labeling. It creates an on-screen dashboard that tracks three specific pieces of information for every timeframe you choose to monitor:

  • Price Position: A visual indicator showing whether the current price is currently trading above or below the "Fan" of averages.
  • Fan Status: An automated check of the moving averages' orientation. It determines if the averages are trending upward, downward, or if they are currently neutral/flat.
  • Dynamic Tracking: The script includes a "Tracking" feature. You can set a specific point in time (a specific bar on the chart) to monitor. As new price data comes in, the dashboard updates specifically for that point in time, allowing you to analyze historical data as if it were live.

User Experience Features

  • Visual Alerts: The script uses distinct symbols (like arrows or diamonds) and colors to represent different market states. For example, it can use blue arrows for upward trends and red for downward trends, making it easy to read the "health" of the market at a glance.
  • Sliding Tracking: If enabled, the tracking point moves automatically with each new candle, allowing you to see a continuous stream of status updates as the market evolves in real-time.
  • Customization: Every element—from the colors and font sizes of the dashboard to the specific moving averages used in the "Fan"—is fully configurable by the user. You can turn specific averages on or off depending on your preferred trading strategy.

Summary of Logic Flow

  1. Initialization: The script identifies which timeframes and moving averages you want to see and sets up the visual labels on your chart.
  2. Data Collection: It constantly gathers price data for all requested timeframes and calculates the required moving averages.
  3. Comparison Engine: It compares the current price against the "Fan" and checks the direction of the averages.
  4. Update: It refreshes the on-screen dashboard symbols and colors instantly whenever a new price tick occurs or the tracking point moves.
Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alerts
12 Views
0 Downloads
0 Favorites
FanSimple8-1bEnL
//+------------------------------------------------------------------+
//|                                                FanSimple8-1a.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|FanSimple8-1bEnL                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
// FanSimple8-1bEnL : TF_Lables    added
//
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window

#property indicator_buffers 8

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/* Here we can change values, used by default /Çäåñü ìîæíî èñïðàâèòü çíà÷åíèÿ, ýòè çíà÷åíèÿ èñïîëüçóþòñÿ ïî óìîë÷àíèþ ïðè ïîäêëþ÷åíèè èíäèêàòîðà */

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/* Colors of a set of averages (MAs);  (put cursor on a name of the color, press F1 to see names of other colors)Öâåòà íàáîðà ñðåäíèõ ïî óìîë÷àíèþ (âñòàâ êóðñîðîì íà èìåíè öâåòà, íàæàòü F1 è óâèäåòü èìåíà îñòàëüíûõ öâåòîâ) */
#property indicator_color1 RoyalBlue
#property indicator_color2 Green
#property indicator_color3 Chartreuse
#property indicator_color4 Yellow
#property indicator_color5 Orange
#property indicator_color6 OrangeRed
#property indicator_color7 Magenta
#property indicator_color8 Magenta
/*Styles of a set of averages (MAs);  (put cursor on a name of the style, press F1 to see names of other styles)//Ñòèëü íàáîðà ñðåäíèõ ïî óìîë÷àíèþ (âñòàâ êóðñîðîì íà èìåíè ñòèëÿ, íàæàòü F1 è óâèäåòü èìåíà îñòàëüíûõ ñòèëåé) */
#property indicator_style1 DRAW_LINE
#property indicator_style2 DRAW_LINE
#property indicator_style3 DRAW_LINE
#property indicator_style4 DRAW_LINE
#property indicator_style5 DRAW_LINE
#property indicator_style6 DRAW_LINE
#property indicator_style7 DRAW_LINE
#property indicator_style8 STYLE_DOT
/*/*Width of a set of averages (MAs);  (put cursor on a name of the style(width), press F1 to see other names )Òîëùèíà íàáîðà ñðåäíèõ ïî óìîë÷àíèþ (âñòàâ êóðñîðîì íà èìåíè òîëùèíû, íàæàòü F1 è óâèäåòü èìåíà îñòàëüíûõ òîëùèí) */
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 1
#property indicator_width8 1

/******************************************************************************
  Indicator parameters
*/

/* indicator's prefix */
extern string Prefix = "";

/* Main switch of display of a fan direction, allows to cut off display of all  periods set //Îáùèé ðóáèëüíèê îòîáðàæåíèÿ ïðàâèëüíîñòè âååðà, ïîçâîëÿåò îòðóáèòü ðàçîì îòîáðàæåíèå íàáîðà âñåõ ïåðèîäîâ */
extern bool DisplayFanStatus = true;
extern bool Display_TF_Lables = true;

/*  Main switch of display of averages, allows to cut off display of all set of averages //Îáùèé ðóáèëüíèê îòîáðàæåíèÿ ñðåäíèõ, ïîçâîëÿåò îòðóáèòü ðàçîì îòîáðàæåíèå íàáîðà ñðåäíèõ */
extern bool DisplayFan = true;

/*Values of the periods of set timeframes, from left to right (reacurrences are possible, "0" and wrong values will not be included in a set) Çíà÷åíèÿ ïåðèîäîâ íàáîðà timeframe'îâ â ïîðÿäêå ñëåäîâàíèÿ ñëåâà íàïðàâî (âîçìîæíû ïîâòîðåíèÿ, 0-âûå è íåïðàâèëüíûå çíà÷åíèÿ âêëþ÷åíû â íàáîð íå áóäóò) */
extern int Timeframe1 = PERIOD_M1;
extern int Timeframe2 = PERIOD_M5;
extern int Timeframe3 = PERIOD_M15;
extern int Timeframe4 = PERIOD_M30;
extern int Timeframe5 = PERIOD_H1;
extern int Timeframe6 = PERIOD_H4;
extern int Timeframe7 = PERIOD_D1;
extern int Timeframe8 = PERIOD_W1;
extern int Timeframe9 = PERIOD_MN1;

/* Date and time for which correctness of a fan displayed Äàòà è âðåìÿ, äëÿ êîòîðîãî èíäèöèðóåòñÿ ïðàâèëüíîñòü âååðà */
extern datetime TrackingTime = 0;

/* to draw (or not) a vertical line through a traced bar Ðèñîâàòü ëè âåðòèêàëüíóþ ëèíèþ ÷åðåç îòñëåæèâàåìûé áàð */
extern bool Tracking = false;

/*  to shift (or not) a point of tracking with formation of a next bar Ñäâèãàåì ëè òî÷êó ñëåæåíèÿ ñ îáðàçîâíèåì ñëåäóùåãî áàðà */
extern bool Sliding = true;

/* Name of a soundfile played at shift of a tracking point //Èìÿ ôàéëà çâóêà, âîñïðîèçâîäèìîãî ïðè ñäâèãå òî÷êè ñëåæåíèÿ */
extern string SlidingSound = "";

/* Values of the periods of a set of  averages combined into a fan, correctness of which is traced ("0" and wrong values will not be included in a set) Çíà÷åíèÿ ïåðèîäîâ íàáîðà ñðåäíèõ, ñîñòàâëÿþùèõ âååð, ïðàâèëüíîñòü êîòîðîãî îòñëåæèâàåòñÿ (0-âûå è íåïðàâèëüíûå çíà÷åíèÿ âêëþ÷åíû â íàáîð íå áóäóò) */
extern int MA1 = 233;
extern int MA2 = 144;
extern int MA3 = 89;
extern int MA4 = 55;
extern int MA5 = 34;
extern int MA6 = 21;
extern int MA7 = 8;
extern int MA8 = 3 ;

/* Individual    display switch of each average Èíäèâèäóàëüíûé ðóáèëüíèê îòîáðàæåíèÿ íà êàæäóþ ñðåäíþþ */
extern bool DisplayMA1 = true;
extern bool DisplayMA2 = true;
extern bool DisplayMA3 = true;
extern bool DisplayMA4 = true;
extern bool DisplayMA5 = true;
extern bool DisplayMA6 = true;
extern bool DisplayMA7 = true;
extern bool DisplayMA8 = true;

/* individual set of type of each average    Èíäèâèäóàëüíîå çàäàíèå òèïà êàæäîé ñðåäíåé */
extern int TypeOfMA1 = MODE_EMA;
extern int TypeOfMA2 = MODE_EMA;
extern int TypeOfMA3 = MODE_EMA;
extern int TypeOfMA4 = MODE_EMA;
extern int TypeOfMA5 = MODE_EMA;
extern int TypeOfMA6 = MODE_EMA;
extern int TypeOfMA7 = MODE_EMA;
extern int TypeOfMA8 = MODE_EMA;

/* individual set of applyed price type of each average / Èíäèâèäóàëüíîå çàäàíèå òèïà öåíû äëÿ êàæäîé ñðåäíåé */
extern int PriceOfMA1 = PRICE_CLOSE;
extern int PriceOfMA2 = PRICE_CLOSE;
extern int PriceOfMA3 = PRICE_CLOSE;
extern int PriceOfMA4 = PRICE_CLOSE;
extern int PriceOfMA5 = PRICE_CLOSE;
extern int PriceOfMA6 = PRICE_CLOSE;
extern int PriceOfMA7 = PRICE_CLOSE;
extern int PriceOfMA8 = PRICE_CLOSE;

/* Font Name /Èìÿ ôîíòà ñèìâîëîâ */
extern string FontName = "Wingdings";

/* Font Size  /Ðàçìåð ñèìâîëîâ */
extern int FontSize = 10;

/* Symbols of the drawn and erased   position index of the price in regard to a fan //Ñèìâîëû íàðèñîâàííîãî è ñò¸ðòîãî óêàçàòåëÿ ïîëîæåíèÿ öåíû îòíîñèòåëüíî âååðà */
extern int PriceOnSymbol = 108; // Circle
extern int PriceOffSymbol = 32; // Space

/* Colors of the drawn index of position of the price relative to a fan /Öâåòà íàðèñîâàííîãî óêàçàòåëÿ ïîëîæåíèÿ öåíû îòíîñèòåëüíî âååðà */
extern color PriceColor = LimeGreen;

/*  Symbols of the index of correctness of a fan direction Ñèìâîëû óêàçàòåëÿ ïðàâèëüíîñòè âååðà */
extern int FanWrongSymbol = 117; // Diamond /176
extern int FanUpSymbol = 233; // Up Arrow
extern int FanDownSymbol = 234; // Down Arrow

/* Öâåòà óêàçàòåëÿ ïðàâèëüíîñòè âååðà */
extern color FanWrongColor = DarkSlateGray;
extern color FanUpColor = DodgerBlue;
extern color FanDownColor = OrangeRed;

/* Displacement(shift) to the left  (XY) from the right top corner  Ñìåùåíèå âëåâî (X) è âïðàâî (Y) îò ïðàâîãî âåðõíåãî óãëà */
extern int X = 10;
extern int Y = 0;

extern color TF_Lbl_color = LightSlateGray;

string Obj0001,Obj0002,Obj0003,Obj0004,Obj0005,Obj0006,Obj0007,Obj0008,Obj0009;  

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/******************************************************************************
  Tracking vertical line label and color
*/
#define TRACKING_NAME     "Bar, traced by indicator FanSimple" //"Áàð, îòñëåæèâàåìûé èíäèêàòîðîì FanSimple"
#define TRACKING_COLOR DarkGray

/*****************************************************************************
string RowName[3] = { "Öåíà âûøå âååðà",
                      "Ñòàòóñ âååðà",
                      "Öåíà íèæå âååðà" };*/

string RowName[3]={ "Price above the Fan",
                    "Fan Status",
                    "Price below the Fan" };
/******************************************************************************/
/******************************************************************************/
/******************************************************************************

/*** À âîò ñþäà ëàçèòü óæå íå ñëåäóåò **** À âîò ñþäà ëàçèòü óæå íå ñëåäóåò ***/
/*** À âîò ñþäà ëàçèòü óæå íå ñëåäóåò **** À âîò ñþäà ëàçèòü óæå íå ñëåäóåò ***/
/*** À âîò ñþäà ëàçèòü óæå íå ñëåäóåò **** À âîò ñþäà ëàçèòü óæå íå ñëåäóåò ***/
/*** not good to  mess with this one  ****  not good to  mess with this one 
/******************************************************************************/
/******************************************************************************/
/******************************************************************************
  Type of rendering codes
*/
#define is_down    0
#define is_none    1
#define is_up      2

/******************************************************************************/
int Timeframe[9];
string TimeframeNames[9];
int TimeframeInUse = 0;

/******************************************************************************/
int MAs[8];
int TypeOfMAs[8];
int PriceOfMAs[8];

int Xlat[8];
int MAsInUse = 0;

/******************************************************************************/
double MA1Buf[], MA2Buf[], MA3Buf[], MA4Buf[], MA5Buf[], MA6Buf[], MA7Buf[], MA8Buf[];

/******************************************************************************/
string LabelName(int i, int j) { return(Prefix + RowName[j] + "(" + (i + 1) + "): " + TimeframeNames[i]); }

/******************************************************************************/
int symcolor[3][2];
int syms[3][2];

/******************************************************************************/
void UpdateFanStatus(int i, int how)
{
  string s = " ";

  ObjectSetText(LabelName(i, 1), StringSetChar(s, 0, symcolor[how][0]), FontSize, FontName, symcolor[how][1]);
}

/******************************************************************************/
void UpdatePriceStatus(int i, int how)
{
  string s = " ";

  ObjectSetText(LabelName(i, 0), StringSetChar(s, 0, syms[how][0]), FontSize, FontName, PriceColor);
  ObjectSetText(LabelName(i, 2), StringSetChar(s, 0, syms[how][1]), FontSize, FontName, PriceColor);
}

/******************************************************************************/
void InitTimeframe(int &P[], int PV)
{
  if(PV != 0)
  {
    switch(PV)
    {
    case PERIOD_M1:  TimeframeNames[TimeframeInUse] = "M1";  break;
    case PERIOD_M5:  TimeframeNames[TimeframeInUse] = "M5";  break;
    case PERIOD_M15: TimeframeNames[TimeframeInUse] = "M15"; break;
    case PERIOD_M30: TimeframeNames[TimeframeInUse] = "M30"; break;
    case PERIOD_H1:  TimeframeNames[TimeframeInUse] = "H1";  break;
    case PERIOD_H4:  TimeframeNames[TimeframeInUse] = "H4";  break;
    case PERIOD_D1:  TimeframeNames[TimeframeInUse] = "D1";  break;
    case PERIOD_W1:  TimeframeNames[TimeframeInUse] = "W1";  break;
    case PERIOD_MN1: TimeframeNames[TimeframeInUse] = "MN"; break;
    default: return;
    }

    P[TimeframeInUse] = PV; TimeframeInUse++;
  }
}

/******************************************************************************/
bool __CheckMA(int MA, int TypeOfMA, int PriceOfMA)
{
  return(MA > 0 &&
        (TypeOfMA == MODE_SMA || TypeOfMA == MODE_EMA || TypeOfMA == MODE_SMMA || TypeOfMA == MODE_LWMA) &&
        (PriceOfMA == PRICE_CLOSE || PriceOfMA == PRICE_OPEN || PriceOfMA == PRICE_HIGH || PriceOfMA == PRICE_LOW || PriceOfMA == PRICE_MEDIAN || PriceOfMA == PRICE_TYPICAL || PriceOfMA == PRICE_WEIGHTED));
}

/******************************************************************************/
bool CheckMA(int MA)
{
  switch(MA)
  {
  case 1: return(__CheckMA(MA1, TypeOfMA1, PriceOfMA1)); break;
  case 2: return(__CheckMA(MA2, TypeOfMA2, PriceOfMA2)); break;
  case 3: return(__CheckMA(MA3, TypeOfMA3, PriceOfMA3)); break;
  case 4: return(__CheckMA(MA4, TypeOfMA4, PriceOfMA4)); break;
  case 5: return(__CheckMA(MA5, TypeOfMA5, PriceOfMA5)); break;
  case 6: return(__CheckMA(MA6, TypeOfMA6, PriceOfMA6)); break;
  case 7: return(__CheckMA(MA7, TypeOfMA7, PriceOfMA7)); break;
  case 8: return(__CheckMA(MA8, TypeOfMA8, PriceOfMA8)); break;
  }

  return(false);
}

/******************************************************************************/
void __InitMAs(int MA, int TypeOfMA, int PriceOfMA)
{
  if(__CheckMA(MA, TypeOfMA, PriceOfMA))
  {
    MAs[MAsInUse] = MA;
    TypeOfMAs[MAsInUse] = TypeOfMA;
    PriceOfMAs[MAsInUse] = PriceOfMA;
    MAsInUse++;
  }
}

/******************************************************************************/
void InitMAs(int MA)
{
  switch(MA)
  {
  case 1: __InitMAs(MA1, TypeOfMA1, PriceOfMA1); break;
  case 2: __InitMAs(MA2, TypeOfMA2, PriceOfMA2); break;
  case 3: __InitMAs(MA3, TypeOfMA3, PriceOfMA3); break;
  case 4: __InitMAs(MA4, TypeOfMA4, PriceOfMA4); break;
  case 5: __InitMAs(MA5, TypeOfMA5, PriceOfMA5); break;
  case 6: __InitMAs(MA6, TypeOfMA6, PriceOfMA6); break;
  case 7: __InitMAs(MA7, TypeOfMA7, PriceOfMA7); break;
  case 8: __InitMAs(MA8, TypeOfMA8, PriceOfMA8); break;
  }
}

/******************************************************************************/
int init()
{
  int i, j;

  if(DisplayFanStatus)
  {
    syms[0][0] = PriceOffSymbol; syms[0][1] = PriceOnSymbol;
    syms[1][0] = PriceOffSymbol; syms[1][1] = PriceOffSymbol;
    syms[2][0] = PriceOnSymbol; syms[2][1] = PriceOffSymbol;

    symcolor[0][0] = FanDownSymbol; symcolor[0][1] = FanDownColor;
    symcolor[1][0] = FanWrongSymbol; symcolor[1][1] = FanWrongColor;
    symcolor[2][0] = FanUpSymbol; symcolor[2][1] = FanUpColor;

    InitTimeframe(Timeframe, Timeframe1); InitTimeframe(Timeframe, Timeframe2);
    InitTimeframe(Timeframe, Timeframe3); InitTimeframe(Timeframe, Timeframe4);
    InitTimeframe(Timeframe, Timeframe5); InitTimeframe(Timeframe, Timeframe6);
    InitTimeframe(Timeframe, Timeframe7); InitTimeframe(Timeframe, Timeframe8);
    InitTimeframe(Timeframe, Timeframe9);

    InitMAs(1); InitMAs(2); InitMAs(3); InitMAs(4);
    InitMAs(5); InitMAs(6); InitMAs(7); InitMAs(8);

    for(i = 0; i < MAsInUse; i++) Xlat[i] = i;

    for(i = 0; i < MAsInUse - 1; i++)
      for(j = i + 1; j < MAsInUse; j++)
        if(MAs[Xlat[i]] > MAs[Xlat[j]]) { int k = Xlat[j]; Xlat[j] = Xlat[i]; Xlat[i] = k; }

    for(i = 0; i < TimeframeInUse; i++)
      for(j = 0; j < 3; j++)
      {
        string s = LabelName(i, j);

        ObjectCreate(s, OBJ_LABEL, 0, 0, 0);   
        ObjectSet(s, OBJPROP_XDISTANCE, (TimeframeInUse - i - 1) * 13 * FontSize / 10 + 2 * FontSize / 10 + X);
        ObjectSet(s, OBJPROP_YDISTANCE, j * 16 * FontSize / 10 + 3 * FontSize / 10 + Y);
        ObjectSet(s, OBJPROP_BACK, true);
        ObjectSet(s, OBJPROP_CORNER, 1);
        ObjectSetText(s, " ", FontSize, FontName, Black);
      }

    if(Tracking)
    {
      ObjectCreate(Prefix + TRACKING_NAME, OBJ_VLINE, 0, TrackingTime, 0);
      ObjectSet(Prefix + TRACKING_NAME, OBJPROP_COLOR, TRACKING_COLOR);
    }
  }

  if(DisplayFan)
  {
    string IndicatorName = Prefix + "FanSimple(";

    if(DisplayMA1 && CheckMA(1)) IndicatorName = IndicatorName + MA1;
    if(DisplayMA2 && CheckMA(2)) IndicatorName = IndicatorName + ", " + MA2;
    if(DisplayMA3 && CheckMA(3)) IndicatorName = IndicatorName + ", " + MA3;
    if(DisplayMA4 && CheckMA(4)) IndicatorName = IndicatorName + ", " + MA4;
    if(DisplayMA5 && CheckMA(5)) IndicatorName = IndicatorName + ", " + MA5;
    if(DisplayMA6 && CheckMA(6)) IndicatorName = IndicatorName + ", " + MA6;
    if(DisplayMA7 && CheckMA(7)) IndicatorName = IndicatorName + ", " + MA7;
    if(DisplayMA8 && CheckMA(8)) IndicatorName = IndicatorName + ", " + MA8;

    IndicatorShortName(IndicatorName + ")");

    IndicatorBuffers(8);

    SetIndexBuffer(0, MA1Buf); SetIndexBuffer(1, MA2Buf); SetIndexBuffer(2, MA3Buf); SetIndexBuffer(3, MA4Buf);
    SetIndexBuffer(4, MA5Buf); SetIndexBuffer(5, MA6Buf); SetIndexBuffer(6, MA7Buf); SetIndexBuffer(7, MA8Buf);
   
    SetIndexLabel(0, Prefix + "Fan, MA(" + MA1 + ")");
    SetIndexLabel(1, Prefix + "Fan, MA(" + MA2 + ")");
    SetIndexLabel(2, Prefix + "Fan, MA(" + MA3 + ")");
    SetIndexLabel(3, Prefix + "Fan, MA(" + MA4 + ")");
    SetIndexLabel(4, Prefix + "Fan, MA(" + MA5 + ")");
    SetIndexLabel(5, Prefix + "Fan, MA(" + MA6 + ")");
    SetIndexLabel(6, Prefix + "Fan, MA(" + MA7 + ")");
    SetIndexLabel(7, Prefix + "Fan, MA(" + MA8 + ")");
//  SetIndexLabel(7, Prefix + "Âååð, " + MA8 + "-ÿ ñðåäíÿÿ");

    for(i = 0; i < 7; i++)
    {
      SetIndexStyle(i, DRAW_LINE);
      SetIndexEmptyValue(i, 0);
    }

    ArraySetAsSeries(MA1Buf, true); ArraySetAsSeries(MA2Buf, true); ArraySetAsSeries(MA3Buf, true); ArraySetAsSeries(MA4Buf, true);
    ArraySetAsSeries(MA5Buf, true); ArraySetAsSeries(MA6Buf, true); ArraySetAsSeries(MA7Buf, true); ArraySetAsSeries(MA8Buf, true);

    for(i = Bars - 1; i >= 0; i--)
    {
      MA1Buf[i] = 0; MA2Buf[i] = 0; MA3Buf[i] = 0; MA4Buf[i] = 0; MA5Buf[i] = 0; MA6Buf[i] = 0; MA7Buf[i] = 0; MA8Buf[i] = 0;
    }
  }

  return(0);
}
void deleteObject()
  { 
ObjectDelete(Obj0001);  
ObjectDelete(Obj0002); 
ObjectDelete(Obj0003); 
ObjectDelete(Obj0004); 
ObjectDelete(Obj0005); 
ObjectDelete(Obj0006); 
ObjectDelete(Obj0007); 
ObjectDelete(Obj0008); 
ObjectDelete(Obj0009); 
 
  }
/******************************************************************************/
int deinit()
{
  for(int i = 0; i < TimeframeInUse; i++)
    for(int j = 0; j < 3; j++)
      ObjectDelete(LabelName(i, j));

  if(Tracking)
ObjectDelete(Prefix + TRACKING_NAME);
ObjectsDeleteAll(0,OBJ_HLINE);
ObjectsDeleteAll(0,OBJ_TEXT);
ObjectsDeleteAll(0,OBJ_LABEL);
deleteObject();  

  return(0);
}

/******************************************************************************/
int start()
{
  
  string LabelTime="";
  if (LabelTime=="") {LabelTime=TimeToStr(TimeLocal(),TIME_SECONDS); }

   if (DisplayFanStatus) 
    {
     if  ( Display_TF_Lables) 
       {       
      string Obj0001 = "FanTFs" + LabelTime ; 
      string TF_Labl = "    M1  M5  M15 M30 H1  H4   D1 W1" ;
 
      ObjectCreate (Obj0001, OBJ_LABEL, 0, 0, 0);
      ObjectSetText(Obj0001, TF_Labl , 6, "Tahoma Narrow", TF_Lbl_color);
      ObjectSet    (Obj0001, OBJPROP_CORNER, 1);
      ObjectSet    (Obj0001, OBJPROP_XDISTANCE, X+2);
      ObjectSet    (Obj0001, OBJPROP_YDISTANCE, Y+13); 
       } 
     }
  
  int i;
  datetime NewTrackingTime = TrackingTime;

  static datetime time = 0;

  if(time == 0)
  {
    if(TrackingTime == 0)
      TrackingTime = Time[0];

    i = ((TimeDay(TrackingTime) * 24 + TimeHour(TrackingTime)) * 60 + TimeMinute(TrackingTime)) * 60 + TimeSeconds(TrackingTime);
    TrackingTime -= i;

    i /= 60;
    i -= i % Period();

    TrackingTime += i * 60;

    if(Tracking)
      ObjectSet(Prefix + TRACKING_NAME, OBJPROP_TIME1, TrackingTime);
    else
      NewTrackingTime = TrackingTime;
  }

  if(Tracking)
    NewTrackingTime = ObjectGet(Prefix + TRACKING_NAME, OBJPROP_TIME1);

  /* User shifted the tracking point or tracking point- the last bar or a new bar appeared //Ïîëüçîâàòåëü ñäâèíóë òî÷êó ñëåæåíèÿ èëè òî÷êà ñëåæåíèÿ - ïîñëåäíèé áàð èëè ïîÿâèëñÿ íîâûé áàð */
  if(NewTrackingTime != TrackingTime || (CurTime() - TrackingTime) / 60  < Period() || time != Time[0])
  {
    if(DisplayFanStatus)
      for(i = 0; i < TimeframeInUse; i++)
      {
        bool Up = true, Down = true;
        bool PriceUp = true, PriceDown = true;

        int LocalShift = iBarShift(Symbol(), Timeframe[i], NewTrackingTime + (Period() - 1) * 60);

        double PrevMA = 0;

        for(int j = 0; j < MAsInUse; j++)
        {
          double MA = iMA(NULL, Timeframe[i], MAs[Xlat[j]], 0, TypeOfMAs[Xlat[j]], PriceOfMAs[Xlat[j]], LocalShift);

          if(j > 0) { if(Up && PrevMA < MA) Up = false; if(Down && PrevMA > MA) Down = false; }

          if(PriceUp && MA > iClose(Symbol(), Timeframe[i], LocalShift)) PriceUp = false;
          if(PriceDown && MA < iClose(Symbol(), Timeframe[i], LocalShift)) PriceDown = false;

          PrevMA = MA;
        }

        if(Up && !Down) UpdateFanStatus(i, is_up); else if(!Up && Down) UpdateFanStatus(i, is_down); else UpdateFanStatus(i, is_none);
        if(PriceUp && !PriceDown) UpdatePriceStatus(i, is_up); else if(!PriceUp && PriceDown) UpdatePriceStatus(i, is_down); else UpdatePriceStatus(i, is_none);
      }

    if(DisplayFan)
      for(i = Bars - IndicatorCounted() - 1; i >= 0; i--)
      {
        if(DisplayMA1 && CheckMA(1)) MA1Buf[i] = iMA(NULL, 0, MA1, 0, TypeOfMA1, PriceOfMA1, i);
        if(DisplayMA2 && CheckMA(2)) MA2Buf[i] = iMA(NULL, 0, MA2, 0, TypeOfMA2, PriceOfMA2, i);
        if(DisplayMA3 && CheckMA(3)) MA3Buf[i] = iMA(NULL, 0, MA3, 0, TypeOfMA3, PriceOfMA3, i);
        if(DisplayMA4 && CheckMA(4)) MA4Buf[i] = iMA(NULL, 0, MA4, 0, TypeOfMA4, PriceOfMA4, i);
        if(DisplayMA5 && CheckMA(5)) MA5Buf[i] = iMA(NULL, 0, MA5, 0, TypeOfMA5, PriceOfMA5, i);
        if(DisplayMA6 && CheckMA(6)) MA6Buf[i] = iMA(NULL, 0, MA6, 0, TypeOfMA6, PriceOfMA6, i);
        if(DisplayMA7 && CheckMA(7)) MA7Buf[i] = iMA(NULL, 0, MA7, 0, TypeOfMA7, PriceOfMA7, i);
        if(DisplayMA8 && CheckMA(8)) MA8Buf[i] = iMA(NULL, 0, MA8, 0, TypeOfMA8, PriceOfMA8, i);
      }

    if(time != Time[0])
    {
      if(Sliding && time != 0)
        NewTrackingTime += Time[0] - time;

      time = Time[0];
    }

    if(Tracking && NewTrackingTime != TrackingTime)
      ObjectSet(Prefix + TRACKING_NAME, OBJPROP_TIME1, NewTrackingTime);

    if(StringLen(SlidingSound) != 0 && NewTrackingTime != TrackingTime)
      PlaySound(SlidingSound);

    TrackingTime = NewTrackingTime;
  }

  return(0);
}

Comments