0
Views
0
Downloads
0
Favorites
Color_Spread
ÿþ//+------------------------------------------------------------------+
//| Color_Spread.mq5 |
//| Copyright © 2017, SelfTraders |
//| http://www.stfx.tk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, SelfTraders"
#property link "http://www.stfx.tk"
#property description ""
//---- =><5@ 25@A88 8=48:0B>@0
#property version "1.60"
//+------------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 8=48:0B>@0 |
//+------------------------------------------------+
//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//+------------------------------------------------+
//| 1JO2;5=85 :>=AB0=B |
//+------------------------------------------------+
#define INDICATOR_NAME "Color_Spread" // <O 8=48:0B>@0
#define RESET 0 // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AG5B 8=48:0B>@0
#define NAMES_SYMBOLS_FONT "Georgia" // (@8DB 4;O =0720=8O 8=48:0B>@0
//+------------------------------------------------+
//| 5@5G8A;5=85 4;O >B>1@065=8O A?@540 |
//+------------------------------------------------+
enum SpreadMode
{
ENUM_POINT_SPREAD=0, // 2 ?C=:B0E
ENUM_TRUE_SPREAD // 2 548=8F0E F5=>2>3> 3@0D8:0
};
//+------------------------------------------------+
//| E>4=K5 ?0@0<5B@K 8=48:0B>@0 |
//+------------------------------------------------+
input SpreadMode Spread_Mode=ENUM_TRUE_SPREAD; // 20@80=B 8=48:0F88 A?@540
input string Symbols_Sirname="Color_Spread_"; // 0720=85 4;O <5B>: 8=48:0B>@0
input color Spread_Color=clrLime; // &25B A?@540
input color Right_Color=clrDarkBlue; // &25B ?@02>9 G0AB8 8=48:0B>@0
input color Left_Color=clrDodgerBlue; // &25B ;52>9 G0AB8 8=48:0B>@0
input uint Font_Size=15; // 07<5@ H@8DB0 4;O >B>1@065=O A?@540
//+-----------------------------------+
//---- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE
int min_rates_total;
//---- >1JO2;5=85 3;>10;L=KE ?5@5<5==KE
string RightName,LeftName,SpreadName;
int PerSec5,PerSec10,PerSec400;
//+------------------------------------------------------------------+
//| !>740=85 B5:AB>2>9 <5B:8 |
//+------------------------------------------------------------------+
void CreateText(long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time, // 2@5<O F5=>2>3> C@>2=O
double price, // F5=>2>9 C@>25=L
string text, // B5:AB
string textTT, // B5:AB 2A?;K20NI59 ?>4A:07:8
color Color, // F25B B5:AB0
string Font, // H@8DB B5:AB0
int Size) // @07<5@ H@8DB0
{
//----
ObjectCreate(chart_id,name,OBJ_TEXT,nwin,time,price);
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
ObjectSetString(chart_id,name,OBJPROP_FONT,Font);
ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,Size);
ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,textTT);
ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); //>1J5:B =0 704=5< ?;0=5
//----
}
//+------------------------------------------------------------------+
//| 5@5CAB0=>2:0 B5:AB>2>9 <5B:8 |
//+------------------------------------------------------------------+
void SetText(long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time, // 2@5<O F5=>2>3> C@>2=O
double price, // F5=>2>9 C@>25=L
string text, // B5:AB
string textTT, // B5:AB 2A?;K20NI59 ?>4A:07:8
color Color, // F25B B5:AB0
string Font, // H@8DB B5:AB0
int Size) // @07<5@ H@8DB0
{
//----
if(ObjectFind(chart_id,name)==-1)
{
CreateText(chart_id,name,nwin,time,price,text,textTT,Color,Font,Size);
}
else
{
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectMove(chart_id,name,nwin,time,price);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,Size);
}
//----
}
//+------------------------------------------------------------------+
//| !>740=85 B@5=4>2>9 ;8=88 |
//+------------------------------------------------------------------+
void CreateRectangle
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
string text // B5:AB
)
//----
{
//----
ObjectCreate(chart_id,name,OBJ_RECTANGLE,nwin,time1,price1,time2,price2);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);
ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);
ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true);
ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true);
ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true);
ObjectSetInteger(chart_id,name,OBJPROP_FILL,true);
//----
}
//+------------------------------------------------------------------+
//| 5@5CAB0=>2:0 B@5=4>2>9 ;8=88 |
//+------------------------------------------------------------------+
void SetRectangle
(
long chart_id, // 845=B8D8:0B>@ 3@0D8:0
string name, // 8<O >1J5:B0
int nwin, // 8=45:A >:=0
datetime time1, // 2@5<O 1 F5=>2>3> C@>2=O
double price1, // 1 F5=>2>9 C@>25=L
datetime time2, // 2@5<O 2 F5=>2>3> C@>2=O
double price2, // 2 F5=>2>9 C@>25=L
color Color, // F25B ;8=88
int style, // AB8;L ;8=88
int width, // B>;I8=0 ;8=88
string text // B5:AB
)
//----
{
//----
if(ObjectFind(chart_id,name)==-1) CreateRectangle(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,text);
else
{
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectMove(chart_id,name,0,time1,price1);
ObjectMove(chart_id,name,1,time2,price2);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
}
//----
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- 8=8F80;870F8O ?5@5<5==KE =0G0;0 >BAG5B0 40==KE
min_rates_total=300;
//---- 8=8F80;870F8O ?5@5<5==KE
RightName=Symbols_Sirname+"Right";
LeftName=Symbols_Sirname+"Left";
SpreadName=Symbols_Sirname+"Lable";
PerSec5=5*PeriodSeconds();
PerSec10=10*PeriodSeconds();
PerSec400=400*PeriodSeconds();
//--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5
IndicatorSetString(INDICATOR_SHORTNAME,INDICATOR_NAME);
//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- 7025@H5=85 8=8F80;870F88
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//----
ObjectsDeleteAll(0,Symbols_Sirname,-1,-1);
//----
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5
const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5
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 bar0=rates_total-1;
int bar1=rates_total-MathMin(300,bar0);
double Bid=close[bar0];
double Spread=spread[bar0]*_Point;
double Ask=Bid+Spread;
double dSpread=Bid+Spread/1.05;
string sSpread;
if(Spread_Mode==ENUM_TRUE_SPREAD) sSpread=DoubleToString(Spread,_Digits);
else sSpread=string(spread[bar0]);
//---- 8AC5< =0 3@0D8:5 ;52K9 ?@O<>C3>;L=8: A?@540
SetRectangle(0,LeftName,0,time[0],Bid,time[bar0]+PerSec5,Ask,Left_Color,STYLE_SOLID,1,LeftName);
//---- 8AC5< =0 3@0D8:5 ?@02K9 ?@O<>C3>;L=8: A?@540
SetRectangle(0,RightName,0,time[bar0]+PerSec5,Bid,time[bar0]+PerSec400,Ask,Right_Color,STYLE_SOLID,1,RightName);
//---- 8AC5< =0 3@0D8:5 B5:AB>2CN <5B:C A?@540
SetText(0,SpreadName,0,time[bar0]+PerSec10,dSpread,sSpread,sSpread,Spread_Color,NAMES_SYMBOLS_FONT,Font_Size);
//----
ChartRedraw(0);
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---