Snarl
Download scriptThis script functions as an automated monitoring and notification tool for MetaTrader users who need to receive real-time alerts based on specific visual markers placed on their trading charts. Instead of just being a static drawing, it turns your chart's horizontal and vertical lines into active "triggers."
Core Functionality
The primary purpose of this script is to detect when market prices (the Bid and Ask) cross specific price levels or time periods that you have manually marked on your chart. When these conditions are met, the script automatically sends a formatted notification to an external application.
How the Logic Works
1. Visual Recognition The script constantly scans your active trading chart for two types of objects:
- Horizontal Lines: Used to represent specific price levels.
- Vertical Lines: Used to represent specific points in time.
It identifies these lines based on the color you assign to them. By using different colors, you can tell the script which logic to apply to which line (for example, one color might trigger a "small" alert while another triggers a "large" alert).
2. Trigger Conditions The script monitors for two main events:
- Price Crossings: For horizontal lines, the script checks if the current market price has moved past the price level of the line. Depending on the color setting, it looks for the price moving above or below that specific mark.
- Time Events: For vertical lines, the script checks if the current market time has reached or passed the specific time associated with that line.
3. Notification System (The "Snarl" Connection) When a trigger condition is met (a price cross or a time hit), the script performs the following actions:
- External Alert: It sends a data packet to an external program (specified in the settings). This packet includes the symbol name, the current Bid/Ask prices, the current time, and any custom notes you have written into the line's description.
- Cool-down Period: To prevent your computer from being flooded with constant alerts while the price is hovering near a line, it uses a "Time Out" logic. It records the time of the last alert and will ignore further triggers for that specific line until the designated delay period has passed.
- Visual Update: The script automatically updates the text on your chart to reflect the timestamp of the most recent alert.
Summary for the User
Essentially, this tool allows you to "set and forget" your alerts. You can draw lines on your chart to mark important support/resistance levels or key news times; the script then watches those lines for you, sending a notification to your desktop or external device the moment the market hits your target, while ensuring you aren't spammed with repeated messages for the same event.
//+------------------------------------------------------------------+
//| Snarl.mq4 |
//| Roffild |
//| http://codebase.mql4.com/ru/5670 |
//+------------------------------------------------------------------+
// Íåîáõîäèìî "Ðàçðåøèòü èìïîðò DLL"
#property copyright "Roffild"
#property link "http://codebase.mql4.com/ru/5670"
#property indicator_chart_window
//---------------------------------------
#import "kernel32.dll"
int WinExec(string cmd, int showConsole);
#import
//---------------------------------------
extern color HLine_small_BID = CornflowerBlue;
extern color HLine_big_BID = SkyBlue;
extern color HLine_small_ASK = Coral;
extern color HLine_big_ASK = LightCoral;
//---------------------------------------
extern color VLine = Orchid;
extern color VLine_big = HotPink;
//---------------------------------------
// Trendline.......... no
extern int TimeOut = 15;
extern string Snarl_Title = "MetaTrader";
extern string Snarl_CMD = "\"c:\\program files\\full phat\\snarl\\snarl_cmd.exe\"";
int start()
{
//Print("HLine_small_BID=",HLine_small_BID,", HLine_big_BID=",HLine_big_BID,", HLine_small_ASK=",HLine_small_ASK,", HLine_big_ASK=",HLine_big_ASK,", VLine=",VLine,", VLine_big=",VLine_big,", TimeOut=",TimeOut);
int obj_total=ObjectsTotal();
string objname, objdesc="";
for(int i=0;i<obj_total;i++)
{
objname = ObjectName(i);
if (ObjectType(objname) == OBJ_HLINE)
{
//Print(TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS)," < ",(GetLastTime(ObjectDescription(objname)) + TimeOut));
if (TimeCurrent() < (GetLastTime(ObjectDescription(objname)) + TimeOut)) continue;
if (GetLastTime(ObjectDescription(objname)) > 0)
{
if (StringLen(ObjectDescription(objname)) > 11) objdesc = StringSubstr(ObjectDescription(objname), 0, StringLen(ObjectDescription(objname))-11);
else objdesc = "";
}
else objdesc = ObjectDescription(objname);
//Print(objname," ",ObjectGet(objname, OBJPROP_COLOR),"==",vcolor," ",ObjectGet(objname, OBJPROP_PRICE1));
if (ObjectGet(objname, OBJPROP_COLOR) == HLine_small_BID &&
ObjectGet(objname, OBJPROP_PRICE1) < Bid)
{
Print(TimeOut," \"",Snarl_Title,"\" \"",Symbol()," ",TimeToStr(TimeCurrent())," BID: ",Bid," ASK: ",Ask," Description: ",objdesc,"\"");
snarl(TimeOut+" \""+Snarl_Title+"\" \""+Symbol()+"\n"+TimeToStr(TimeCurrent())+"\nBID: "+Bid+"\nASK: "+Ask+"\nDescription:\n"+objdesc+"\"");
ObjectSetText(objname, objdesc + ";" + TimeCurrent());
continue;
}
if (ObjectGet(objname, OBJPROP_COLOR) == HLine_big_BID &&
ObjectGet(objname, OBJPROP_PRICE1) > Bid)
{
Print(TimeOut," \"",Snarl_Title,"\" \"",Symbol()," ",TimeToStr(TimeCurrent())," BID: ",Bid," ASK: ",Ask," Description: ",objdesc,"\"");
snarl(TimeOut+" \""+Snarl_Title+"\" \""+Symbol()+"\n"+TimeToStr(TimeCurrent())+"\nBID: "+Bid+"\nASK: "+Ask+"\nDescription:\n"+objdesc+"\"");
ObjectSetText(objname, objdesc + ";" + TimeCurrent());
continue;
}
if (ObjectGet(objname, OBJPROP_COLOR) == HLine_small_ASK &&
ObjectGet(objname, OBJPROP_PRICE1) < Ask)
{
Print(TimeOut," \"",Snarl_Title,"\" \"",Symbol()," ",TimeToStr(TimeCurrent())," BID: ",Bid," ASK: ",Ask," Description: ",objdesc,"\"");
snarl(TimeOut+" \""+Snarl_Title+"\" \""+Symbol()+"\n"+TimeToStr(TimeCurrent())+"\nBID: "+Bid+"\nASK: "+Ask+"\nDescription:\n"+objdesc+"\"");
ObjectSetText(objname, objdesc + ";" + TimeCurrent());
continue;
}
if (ObjectGet(objname, OBJPROP_COLOR) == HLine_big_ASK &&
ObjectGet(objname, OBJPROP_PRICE1) > Ask)
{
Print(TimeOut," \"",Snarl_Title,"\" \"",Symbol()," ",TimeToStr(TimeCurrent())," BID: ",Bid," ASK: ",Ask," Description: ",objdesc,"\"");
snarl(TimeOut+" \""+Snarl_Title+"\" \""+Symbol()+"\n"+TimeToStr(TimeCurrent())+"\nBID: "+Bid+"\nASK: "+Ask+"\nDescription:\n"+objdesc+"\"");
ObjectSetText(objname, objdesc + ";" + TimeCurrent());
continue;
}
}
if (ObjectType(objname) == OBJ_VLINE)
{
if (TimeCurrent() < (GetLastTime(ObjectDescription(objname)) + TimeOut)) continue;
if (GetLastTime(ObjectDescription(objname)) > 0)
{
if (StringLen(ObjectDescription(objname)) > 11) objdesc = StringSubstr(ObjectDescription(objname), 0, StringLen(ObjectDescription(objname))-11);
else objdesc = "";
}
else objdesc = ObjectDescription(objname);
//Print(ObjectGet(objname, OBJPROP_COLOR)," == ",VLine,", ",TimeToStr(ObjectGet(objname, OBJPROP_TIME1)));
if (ObjectGet(objname, OBJPROP_COLOR) == VLine &&
ObjectGet(objname, OBJPROP_TIME1) > TimeCurrent()-60 && ObjectGet(objname, OBJPROP_TIME1) < TimeCurrent()+60)
{
Print(TimeOut," \"",Snarl_Title,"\" \"",Symbol()," ",TimeToStr(TimeCurrent())," BID: ",Bid," ASK: ",Ask," Description: ",objdesc,"\"");
snarl(TimeOut+" \""+Snarl_Title+"\" \""+Symbol()+"\n"+TimeToStr(TimeCurrent())+"\nBID: "+Bid+"\nASK: "+Ask+"\nDescription:\n"+objdesc+"\"");
ObjectSetText(objname, objdesc + ";" + TimeCurrent());
continue;
}
if (ObjectGet(objname, OBJPROP_COLOR) == VLine_big &&
ObjectGet(objname, OBJPROP_TIME1) < TimeCurrent())
{
Print(TimeOut," \"",Snarl_Title,"\" \"",Symbol()," ",TimeToStr(TimeCurrent())," BID: ",Bid," ASK: ",Ask," Description: ",objdesc,"\"");
snarl(TimeOut+" \""+Snarl_Title+"\" \""+Symbol()+"\n"+TimeToStr(TimeCurrent())+"\nBID: "+Bid+"\nASK: "+Ask+"\nDescription:\n"+objdesc+"\"");
ObjectSetText(objname, objdesc + ";" + TimeCurrent());
continue;
}
}
}
return(1);
}
void snarl(string str)
{
WinExec(Snarl_CMD + " snShowMessage " + str, 0);
}
int GetLastTime(string str)
{
return( StrToInteger(StringSubstr(str, StringLen(str)-10)) );
}
// the end.
Comments