Author: Copyright � 2007, Xupypr
Fibo_auto
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Fibo_auto
//+------------------------------------------------------------------+
//|                                                    Fibo_auto.mq4 |
//|                                         Copyright © 2007, Xupypr |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Xupypr"

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Aqua
#property indicator_color2 Yellow
#property indicator_color3 Yellow
#property indicator_color4 Yellow
#property indicator_color5 Yellow
#property indicator_color6 Yellow
#property indicator_color7 Magenta
//---- input parameters
extern int Days=35; // êîëëè÷åñòâî äíåé äëÿ ðàñ÷¸òà

int AllBars,DW;
double F[7],Level;
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
 SetIndexBuffer(0, ExtMapBuffer1);
 SetIndexStyle(0, DRAW_LINE, 0, 2);
 SetIndexLabel(0,"Óðîâåíü 100%");
 SetIndexBuffer(1, ExtMapBuffer2);
 SetIndexStyle(1, DRAW_LINE, 0, 1);
 SetIndexLabel(1,"Óðîâåíü 76.0%");
 SetIndexBuffer(2, ExtMapBuffer3);
 SetIndexStyle(2, DRAW_LINE, 0, 1);
 SetIndexLabel(2,"Óðîâåíü 61.8%");
 SetIndexBuffer(3, ExtMapBuffer4);
 SetIndexStyle(3, DRAW_LINE, 0, 1);
 SetIndexLabel(3,"Óðîâåíü 50.0%");
 SetIndexBuffer(4, ExtMapBuffer5);
 SetIndexStyle(4, DRAW_LINE, 0, 1);
 SetIndexLabel(4,"Óðîâåíü 38.2%");
 SetIndexBuffer(5, ExtMapBuffer6);
 SetIndexStyle(5, DRAW_LINE, 0, 1);
 SetIndexLabel(5,"Óðîâåíü 23.6%");
 SetIndexBuffer(6, ExtMapBuffer7);
 SetIndexStyle(6, DRAW_LINE, 0, 2);
 SetIndexLabel(6,"Óðîâåíü 0.0%");
 ObjectCreate("F0",OBJ_TEXT,0,Time[0]+180*Period(),0);
 ObjectSetText("F0","100%",8,"Arial",indicator_color1);
 ObjectCreate("F1",OBJ_TEXT,0,Time[0]+180*Period(),0);
 ObjectSetText("F1","76.0%",8,"Arial",indicator_color2);
 ObjectCreate("F2",OBJ_TEXT,0,Time[0]+180*Period(),0);
 ObjectSetText("F2","61.8%",8,"Arial",indicator_color3);
 ObjectCreate("F3",OBJ_TEXT,0,Time[0]+180*Period(),0);
 ObjectSetText("F3","50.0%",8,"Arial",indicator_color4);
 ObjectCreate("F4",OBJ_TEXT,0,Time[0]+180*Period(),0);
 ObjectSetText("F4","38.2%",8,"Arial",indicator_color5);
 ObjectCreate("F5",OBJ_TEXT,0,Time[0]+180*Period(),0);
 ObjectSetText("F5","23.6%",8,"Arial",indicator_color6);
 ObjectCreate("F6",OBJ_TEXT,0,Time[0]+180*Period(),0);
 ObjectSetText("F6","0.0%",8,"Arial",indicator_color7);
 //---- indicator short name
 IndicatorShortName("Fibo_auto ("+Days+" days)");
 return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
 Comment("");
 for (int i=0;i<7;i++) if (ObjectFind("F"+i)!=-1) ObjectDelete("F"+i);
 return(0);
}

int start()
{
 if (Period()>PERIOD_D1)
 {
  Comment("WARNING: Invalid timeframe! Valid value < W1.");
  return(0);
 }
 
 if (TimeDayOfWeek(Time[0])!=DW)
 {
  int bar_high,bar_low,bar_end;
  double day_high;
  double day_low;
  int bars=Days*(PERIOD_D1/Period());
  
  bar_high=iHighest(NULL,0,MODE_HIGH,bars,0);
  day_high=High[bar_high];
  bar_low=iLowest(NULL,0,MODE_LOW,bars,0);
  day_low=Low[bar_low];
  if (bar_high<bar_low)
  {
   bar_end=bar_low;
   F[0]=day_low;
   F[1]=day_high-0.76*(day_high-day_low);
   F[2]=day_high-0.618*(day_high-day_low);
   F[3]=day_high-0.5*(day_high-day_low);
   F[4]=day_high-0.382*(day_high-day_low);
   F[5]=day_high-0.236*(day_high-day_low);
   F[6]=day_high;
  }
  else
  {
   bar_end=bar_high;
   F[0]=day_high;
   F[1]=day_low+0.76*(day_high-day_low);
   F[2]=day_low+0.618*(day_high-day_low);
   F[3]=day_low+0.5*(day_high-day_low);
   F[4]=day_low+0.382*(day_high-day_low);
   F[5]=day_low+0.236*(day_high-day_low);
   F[6]=day_low;
  }
  DW=TimeDayOfWeek(Time[0]);
 }
 int i,Limit;
 int counted_bars=IndicatorCounted();
 if (counted_bars>0) Limit=Bars-counted_bars-1; else Limit=bar_end;
 for (i=Limit;i>=0;i--)
 {
  ExtMapBuffer1[i]=NormalizeDouble(F[0],Digits);
  ExtMapBuffer2[i]=NormalizeDouble(F[1],Digits);
  ExtMapBuffer3[i]=NormalizeDouble(F[2],Digits);
  ExtMapBuffer4[i]=NormalizeDouble(F[3],Digits);
  ExtMapBuffer5[i]=NormalizeDouble(F[4],Digits);
  ExtMapBuffer6[i]=NormalizeDouble(F[5],Digits);
  ExtMapBuffer7[i]=NormalizeDouble(F[6],Digits);
 }
 if (AllBars!=Bars) 
 {
  for (i=0;i<7;i++) ObjectMove("F"+i,0,Time[0]+180*Period(),F[i]);
  AllBars=Bars;
 } 
 for (i=0;i<7;i++) if (High[0]>=F[i] && Low[0]<=F[i] && Level!=F[i])
 {
  Alert("Ïåðåñå÷åíèå óðîâíÿ ",ObjectDescription("F"+i)," - ",F[i]);
  Level=F[i];
 } 
}
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---