Indicators Used
Miscellaneous
2
Views
0
Downloads
0
Favorites
breaktrend
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2;
#property indicator_color1 clrDeepSkyBlue
#property indicator_color2 clrTomato
enum CountMode
{
WithLastBar = 0, // Including current bar
ClosedBars // Closed bars only
};
enum Choice
{
NO = 0, // No
YES = 1 // Yes
};
// inputs
input int i_nPriceDistance = 500; // Price difference
input int i_nNumberOfBars = 18; // Bars to analyse
input CountMode i_eMode = ClosedBars; // Mode
input Choice i_bAlerts = YES; // Alerts
input Choice i_bMail = NO; // E-mail notifications
input Choice i_bPush = NO; // Push-notifications
input color i_UpColor = clrDeepSkyBlue; // Up color
input color i_DownColor = clrTomato; // Down color
// buffers
double ArrUpBuffer[], ArrDownBuffer[];
// çíà÷åíèÿ ñòàíäàðòíûõ èíäèêàòîðîâ
double g_fHHV, g_fLLV, g_fATR;
// ñèãíàëû
bool g_bBuySignal = false;
bool g_bSellSignal = false;
// ôëàãè ñîñòîÿíèÿ àëåðòîâ
bool g_bBuyAlertActive = true;
bool g_bSellAlertActive = true;
bool g_bBuyMailActive = true;
bool g_bSellMailActive = true;
bool g_bBuyPushActive = true;
bool g_bSellPushActive = true;
// âðåìÿ ïîñëåäíåãî ðàññ÷èòàííîãî áàðà
datetime g_dtLastBarTime = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// èíèöèàëèçàöèÿ
// çíà÷åíèÿ ñòàíäàðòíûõ èíäèêàòîðîâ
g_fHHV = 0;
g_fLLV = 0;
g_fATR = 0;
// ñèãíàëû
g_bBuySignal = false;
g_bSellSignal = false;
// ôëàãè ñîñòîÿíèÿ àëåðòîâ
g_bBuyAlertActive = true;
g_bSellAlertActive = true;
g_bBuyMailActive = true;
g_bSellMailActive = true;
g_bBuyPushActive = true;
g_bSellPushActive = true;
// âðåìÿ ïîñëåäíåãî ðàññ÷èòàííîãî áàðà
g_dtLastBarTime = 0;
// áóôåðû
SetIndexStyle (0, DRAW_ARROW, STYLE_SOLID, 1, i_UpColor);
SetIndexArrow (0, 233);
SetIndexBuffer(0, ArrUpBuffer);
SetIndexLabel (0, NULL);
SetIndexStyle (1, DRAW_ARROW, STYLE_SOLID, 1, i_DownColor);
SetIndexArrow (1, 234);
SetIndexBuffer(1, ArrDownBuffer);
SetIndexLabel (1, NULL);
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[])
{
int nStartIndex = rates_total - prev_calculated;
if(nStartIndex > rates_total - i_nNumberOfBars - 1)
nStartIndex = rates_total - i_nNumberOfBars - 1;
for(int i = nStartIndex; i >= 0; i--)
{
// ñ ïðèõîäîì íîâîãî áàðà ðàññ÷èòûâàåì ìàêñèìóìû è ìèíèìóìû öåíû è ATR
if(time[i] != g_dtLastBarTime)
{
g_fHHV = high[iHighest(_Symbol, _Period, MODE_HIGH, i_nNumberOfBars, i+1)];
g_fLLV = low[iLowest(_Symbol, _Period, MODE_LOW, i_nNumberOfBars, i+1)];
g_fATR = iATR(_Symbol, _Period, 50, i+1);
}
// ------------------- Ñèãíàëû -------------------------
g_bBuySignal = low[i] <= (g_fHHV - i_nPriceDistance * _Point);
g_bSellSignal = high[i] >= (g_fLLV + i_nPriceDistance * _Point);
// ------------------- Ñòðåëêè -------------------------
// ââåðõ
if(g_bBuySignal)
{
ArrUpBuffer[i] = low[i] - g_fATR;
if(ArrUpBuffer[i] <= 0)
ArrUpBuffer[i] = low[i];
}
else
ArrUpBuffer[i] = 0;
// âíèç
if(g_bSellSignal)
ArrDownBuffer[i] = high[i] + g_fATR;
else
ArrDownBuffer[i] = 0;
// ------------------- Àëåðòû --------------------------
if(i_bAlerts && i == (int) i_eMode)
{
// àëåðò Buy
if(g_bBuySignal)
{
if(g_bBuyAlertActive)
{
Alert("Break trend", _Symbol, ": signal \"Buy\" at ", TimeToString(time[i]));
g_bBuyAlertActive = false;
}
}
else
g_bBuyAlertActive = true;
// àëåðò Sell
if(g_bSellSignal)
{
if(g_bSellAlertActive)
{
Alert("Break trend ", _Symbol, ": signal \"Sell\" at ", TimeToString(time[i]));
g_bSellAlertActive = false;
}
}
else
g_bSellAlertActive = true;
}
// ------------------- E-Mail ------------------------
if(i_bMail && i == (int) i_eMode)
{
// e-Mail Buy
if(g_bBuySignal)
{
if(g_bBuyMailActive)
{
SendMail("Break trend", "Break trend: signal \"Buy\" at " + TimeToString(time[i]));
g_bBuyMailActive = false;
}
}
else
g_bBuyMailActive = true;
// e-Mail Sell
if(g_bSellSignal)
{
if(g_bSellMailActive)
{
SendMail("Break trend", "Break trend: signal \"Sell\" at " + TimeToString(time[i]));
g_bSellMailActive = false;
}
}
else
g_bSellMailActive = true;
}
// --------------- Push-óâåäîìëåíèÿ --------------------
if(i_bPush && i == (int) i_eMode)
{
// Push Buy
if(g_bBuySignal)
{
if(g_bBuyPushActive)
{
SendNotification("Break trend " + _Symbol + ": signal \"Buy\" at " + TimeToString(time[i]));
g_bBuyPushActive = false;
}
}
else
g_bBuyPushActive = true;
// e-Mail Sell
if(g_bSellSignal)
{
if(g_bSellPushActive)
{
SendNotification("Break trend " + _Symbol + ": signal \"Sell\" at " + TimeToString(time[i]));
g_bSellPushActive = false;
}
}
else
g_bSellPushActive = true;
}
}
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
---