Snippets
Created by
nicholishen
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | //+------------------------------------------------------------------+
//| SymbolOnChart.mq4 |
//| nicholishen |
//| www.reddit.com/u/nicholishenFX |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link "www.reddit.com/u/nicholishenFX"
#property version "1.00"
#property strict
#property indicator_chart_window
#define MAX_FONT 100
#include <ChartObjects\ChartObjectsTxtControls.mqh>
input color LabelColor = clrDarkSlateGray;
CChartObjectLabel *label;
long x_distance;
long y_distance;
int OnInit()
{
Comment("");
ObjectDelete(0,"symbol_on_chart");
label = new CChartObjectLabel();
if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance))
{
Print("Failed to get the chart width! Error code = ",GetLastError());
return INIT_FAILED;
}
if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance))
{
Print("Failed to get the chart height! Error code = ",GetLastError());
return INIT_FAILED;
}
int font_size = (int)x_distance/10;
font_size = font_size > MAX_FONT ? MAX_FONT : font_size;
string name = Symbol()+IntegerToString(GetMicrosecondCount());
if(!label.Create(0,"symbol_on_chart",0,(int)x_distance/2,(int)y_distance/2))
{
Print("FAILED");
return INIT_FAILED;
}
label.Description(Symbol());
label.Anchor(ANCHOR_CENTER);
label.FontSize(font_size);
label.Font("Arial Black");
label.Background(true);
label.Color(LabelColor);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
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[])
{
return(rates_total);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
if( id == CHARTEVENT_CHART_CHANGE)
{
if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance))
{
Print("Failed to get the chart width! Error code = ",GetLastError());
}
if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance))
{
Print("Failed to get the chart height! Error code = ",GetLastError());
}
int font_size = (int)x_distance/10;
font_size = font_size > MAX_FONT ? MAX_FONT : font_size;
label.FontSize(font_size);
label.X_Distance((int)x_distance/2);
label.Y_Distance((int)y_distance/2);
}
}
void OnDeinit(const int reason)
{
delete label;
}
//+------------------------------------------------------------------+
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.