Skip to content

Instantly share code, notes, and snippets.

@notmii
Last active July 13, 2017 23:28
Show Gist options
  • Save notmii/e31ad0a0806b9eba416003b82e9e0343 to your computer and use it in GitHub Desktop.
Save notmii/e31ad0a0806b9eba416003b82e9e0343 to your computer and use it in GitHub Desktop.
//+------------------------------------------------------------------+
//| Acceleration.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
double previousPrice;
bool isFirstEvent = true;
string lastAlert = "---";
double lastDiff = 0;
int try = 0;
double spread = 0;
double pips = 0;
double difference = 0;
input int timer = 1000;
input int targetSpeed = 10;
input int targetSpeedLvl2 = 20;
input int targetSpeedLvl3 = 30;
int OnInit() {
EventSetMillisecondTimer(timer);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) {
EventKillTimer();
}
void OnTick(){
spread = MathRound((Ask - Bid) / Point);
displayComments();
}
void OnTimer(){
if (isFirstEvent) {
isFirstEvent = false;
previousPrice = Close[0];
return;
}
try += 1;
difference = Close[0] - previousPrice;
pips = MathRound(difference / Point);
spread = MathRound((Ask - Bid) / Point);
displayComments();
if (try >= 30) {
lastAlert = "---";
lastDiff = 0;
}
if (MathAbs(pips) >= targetSpeed) {
try = 0;
PlaySound("alert.wav");
if (MathAbs(pips) >= targetSpeedLvl2)
PlaySound("alert.wav");
if (MathAbs(pips) >= targetSpeedLvl3)
PlaySound("alert.wav");
if (pips > 0) {
lastAlert = "BUY";
lastDiff = pips;
}
if (pips < 0) {
lastAlert = "SELL";
lastDiff = pips;
}
}
previousPrice = Close[0];
}
void displayComments() {
Comment(
"Diff: ", pips,
" | Last: ", lastAlert, " ", lastDiff,
" | Spread: ", spread
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment