//+------------------------------------------------------------------+
//| AlertPriceMovement.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
input int InpMovementPoints = 50;
double MovementValue;
int OnInit() {
MovementValue = InpMovementPoints * SymbolInfoDouble(Symbol(), SYMBOL_POINT);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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[]) {
static datetime currentBarTime = 0;
static double highTarget = 0;
static double lowTarget = 0;
// Get out if bars are still loading
if (rates_total != prev_calculated) return(rates_total);
if (currentBarTime != time[0]) {
currentBarTime = time[0];
highTarget = open[0] + MovementValue;
lowTarget = open[0] - MovementValue;
}
if (highTarget > 0 && close[0] >= highTarget) {
AlertMe(highTarget, close[0], "High", TimeCurrent() - time[0]);
highTarget = 0;
}
if (lowTarget > 0 && close[0] <= lowTarget) {
AlertMe(lowTarget, close[0], "Low", TimeCurrent() - time[0]);
lowTarget = 0;
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertMe(double targetPrice, double currrentPrice, string type, int seconds) {
string msg = StringFormat("Current price %f has passed %s target price of %f in %i seconds", currrentPrice, type, targetPrice, seconds);
Alert(msg);
}
//+------------------------------------------------------------------+
暂无评论