LineFractals_Alert_v1
Download scriptThis script is designed to work on the MetaTrader 4 platform to help traders identify key price levels and receive automatic notifications when those levels are breached. By automating the identification of "Support" (price floors) and "Resistance" (price ceilings), it simplifies the process of spotting potential trend reversals or continuations.
Core Logic and Functionality
1. Dynamic Level Identification The script automatically scans the market history to find specific price points known as "Fractals." These are peaks and troughs in the price movement. Instead of just identifying a single point, the logic searches backward through recent candles to find the two most significant historical coordinates for both support and resistance.
2. Visual Chart Mapping Once these coordinates are identified, the script draws four distinct trendlines on your chart:
- Primary Support & Resistance: Two main lines representing the most significant historical boundaries found by the algorithm.
- Secondary (Lower) Support & Resistance: Two additional lines that capture secondary market structures.
These lines are drawn as "rays," meaning they extend forward into the future, allowing you to see where the price is heading relative to these established boundaries.
3. Automated Breakout Monitoring The script constantly monitors the closing price of each new candle. It specifically looks for a "breakout"—a situation where the market moves from one side of a line to the other. To prevent false signals, it checks two conditions simultaneously:
- The current price must have closed past the line.
- The previous price must have been on the opposite side of that same line.
4. Real-Time Alerts When a breakout is confirmed, the script triggers a pop-up alert on your screen. These alerts are categorized by direction to help with quick decision-making:
- Short Opportunities: If the price drops below a Support level, the alert notifies you that the support has broken and suggests looking for a "Short" (selling) position.
- Long Opportunities: If the price climbs above a Resistance level, the alert notifies you that the resistance has broken and suggests looking for a "Long" (buying) position.
By combining visual markers with instant notifications, this tool helps traders stay updated on market structural shifts without having to manually watch every price tick.
//+------------------------------------------------------------------+
//| LineFractals_Alert.mq4
//originalcode from Yuriy Tokman
//mod by Pussy Galore
//mod by Darkkiller
//+------------------------------------------------------------------+
#property indicator_chart_window
extern color SupLineColor = Magenta;
extern int SupLnWidth = 2;
extern color ResLineColor = Aqua;
extern int ResLnWidth = 2;
extern bool UseAlert = true;
double Support,Resistance,LastClose;
double PriorSupport,PriorResistance,PriorLastClose;
double Support1,Resistance1,LastClose1;
double PriorSupport1,PriorResistance1,PriorLastClose1;
bool NewBar()
{
static datetime lastbar = 0;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else
{
return (false);
}
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
ObjectCreate("Support", OBJ_TREND, 0,0,0,0,0);
ObjectCreate("Resistance", OBJ_TREND, 0,0,0,0,0);
ObjectCreate("Support1", OBJ_TREND, 0,0,0,0,0);
ObjectCreate("Resistance1", OBJ_TREND, 0,0,0,0,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("Support");
ObjectDelete("Resistance");
ObjectDelete("Support1");
ObjectDelete("Resistance1");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
double F1=0, F3=0, F13;
int B1, B3, SR=2;
while(F3==0)
{
F13=iFractals(NULL,0,MODE_LOWER,SR);
if (F13!=0)
{
if (F1==0){B1=SR; F1=F13;}
else if (F3==0){B3=SR; F3=F13;}
}
SR++;
}
ObjectSet("Support", OBJPROP_TIME1 ,iTime(NULL,0,B3));
ObjectSet("Support", OBJPROP_TIME2 ,iTime(NULL,0,B1));
ObjectSet("Support", OBJPROP_PRICE1,iLow(NULL,0,B3));
ObjectSet("Support", OBJPROP_PRICE2,iLow(NULL,0,B1));
ObjectSet("Support", OBJPROP_RAY , True);
ObjectSet("Support", OBJPROP_COLOR, SupLineColor);
ObjectSet("Support", OBJPROP_WIDTH, SupLnWidth);
ObjectSet("Resistance1", OBJPROP_TIME1 ,iTime(NULL,0,B3));
ObjectSet("Resistance1", OBJPROP_TIME2 ,iTime(NULL,0,B1));
ObjectSet("Resistance1", OBJPROP_PRICE1,iHigh(NULL,0,B3));
ObjectSet("Resistance1", OBJPROP_PRICE2,iHigh(NULL,0,B1));
ObjectSet("Resistance1", OBJPROP_RAY , True);
ObjectSet("Resistance1", OBJPROP_COLOR, ResLineColor);
ObjectSet("Resistance1", OBJPROP_STYLE, 2);
//----
double G1=0, G3=0, G13;
int C1, C3, RR=2;
while(G3==0)
{
G13=iFractals(NULL,0,MODE_UPPER,RR);
if (G13!=0)
{
if (G1==0){C1=RR; G1=G13;}
else if (G3==0){C3=RR; G3=G13;}
}
RR++;
}
ObjectSet("Resistance", OBJPROP_TIME1 ,iTime(NULL,0,C3));
ObjectSet("Resistance", OBJPROP_TIME2 ,iTime(NULL,0,C1));
ObjectSet("Resistance", OBJPROP_PRICE1,iHigh(NULL,0,C3));
ObjectSet("Resistance", OBJPROP_PRICE2,iHigh(NULL,0,C1));
ObjectSet("Resistance", OBJPROP_RAY , True);
ObjectSet("Resistance", OBJPROP_COLOR, ResLineColor);
ObjectSet("Resistance", OBJPROP_WIDTH, ResLnWidth);
ObjectSet("Support1", OBJPROP_TIME1 ,iTime(NULL,0,C3));
ObjectSet("Support1", OBJPROP_TIME2 ,iTime(NULL,0,C1));
ObjectSet("Support1", OBJPROP_PRICE1,iLow(NULL,0,C3));
ObjectSet("Support1", OBJPROP_PRICE2,iLow(NULL,0,C1));
ObjectSet("Support1", OBJPROP_RAY ,True);
ObjectSet("Support1", OBJPROP_COLOR, SupLineColor);
ObjectSet("Support1", OBJPROP_STYLE, 2);
//====================================================================
// Alert if last bar closes outside of trendlines
//====================================================================
Support=ObjectGetValueByShift("Support",1);
Resistance=ObjectGetValueByShift("Resistance",1);
LastClose=iClose(NULL,0,1);
PriorSupport=ObjectGetValueByShift("Support",2);
PriorResistance=ObjectGetValueByShift("Resistance",2);
PriorLastClose=iClose(NULL,0,2);
Support1=ObjectGetValueByShift("Support1",1);
Resistance1=ObjectGetValueByShift("Resistance1",1);
LastClose1=iClose(NULL,0,1);
PriorSupport1=ObjectGetValueByShift("Support1",2);
PriorResistance1=ObjectGetValueByShift("Resistance1",2);
PriorLastClose1=iClose(NULL,0,2);
if (NewBar()==true && (UseAlert) && LastClose<Support && PriorLastClose>=PriorSupport) Alert(Symbol()+" "+Period()+": Support broken @ "+DoubleToStr(Support,Digits)+" - Look to go SHORT");
if (NewBar()==true && (UseAlert) && LastClose>Resistance && PriorLastClose<=PriorSupport) Alert(Symbol()+" "+Period()+": Resistance broken @ "+DoubleToStr(Resistance,Digits)+" - Look to go LONG");
if (NewBar()==true && (UseAlert) && LastClose1<Support1 && PriorLastClose1>=PriorSupport1) Alert(Symbol()+" "+Period()+": Lower Support broken @ "+DoubleToStr(Support1,Digits)+" - Look to go SHORT");
if (NewBar()==true && (UseAlert) && LastClose1>Resistance1 && PriorLastClose1<=PriorSupport1) Alert(Symbol()+" "+Period()+": Lower Resistance broken @ "+DoubleToStr(Resistance1,Digits)+" - Look to go LONG");
//----
return(0);
}
//+------------------------------------------------------------------+
Comments