#SpudFibo alert v3
Download scriptThis script is designed as a specialized technical analysis tool for the MetaTrader 4 platform. It combines automated Fibonacci retracement mapping with a price-crossing alert system to help traders identify potential entry points based on historical volatility and specific price levels.
Core Functional Logic
1. Dynamic Fibonacci Mapping The script automatically identifies significant price extremes (the Highs and Lows) from a specific timeframe, such as the weekly chart. Based on these extremes, it calculates a "Range" and projects three distinct sets of Fibonacci levels onto your chart:
- Upper Levels: Projects expansion zones above the current high.
- Lower Levels: Projects expansion zones below the current low.
- Inner Levels (Optional): Focuses on the internal price action within the established range, highlighting the mid-point and the high/low boundaries.
The script is designed to be visually organized, using different colors for these levels so that users can easily distinguish between primary market structure and secondary expansion zones.
2. Automated Price Crossing Detection The core "intelligence" of the script lies in its ability to monitor how the current price interacts with these calculated Fibonacci lines. It performs a continuous check to see if the price has moved from one side of a key level to the other.
- It calculates a running average of the price range over the last 10 bars to determine the "volatility" or "spread" of the current movement.
- When the market price crosses one of the significant Fibonacci levels, the script identifies this as a potential shift in momentum.
3. Real-Time Signaling and Alerts To ensure traders don't have to watch the charts constantly, the script provides several methods for notification when a crossover occurs:
- Visual Cues: It can automatically place "Arrows" on the chart (pointing up or down) at the exact moment a price level is breached.
- Audible & Visual Alerts: It can trigger a sound alert or a pop-up window on your trading terminal.
- Remote Notifications: If configured, it can send an automated email to your designated address when a signal is detected.
Summary of User Experience
For the end-user, this tool transforms raw price data into a structured map of "zones." Instead of manually drawing Fibonacci lines every time the market moves, the script handles the geometry automatically. It then acts as a sentry, watching those lines and notifying you only when the price interacts with them in a way that suggests a trend change or a significant breakout.
//+------------------------------------------------------------------+
//| #SpudFibo.mq4 - downloaded from ultimaforex.com
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
extern string Ind="---------------- Indicator Settings";
extern int SF_Period=PERIOD_W1;
extern string note1 = "Fibonacci colors";
extern color UpperFiboColor = Navy;
extern color MainFiboColor = RoyalBlue;
extern color LowerFiboColor = DodgerBlue;
extern string note2 = "Draw main Fibonacci lines?";
extern bool InnerFibs = true;
extern string Ale="---------------- Alert Settings";
extern bool SoundAlert = true;
extern bool PopUpAlert = false;
extern bool EmailAlert = false;
extern bool ArrowsSignal = true;
double alertBar;
int limit=1;int counter;
double CrossUp[];
double CrossDown[];
double prevtime;
double Crange, AvgRange;
double HiPrice, LoPrice, Range;
datetime StartTime;
double fib500,fib000,fib1000,fibm1500,fibm2000,fibm2500,fibm3000,fibm3500,fibm4000,fibm4500,fibm5000,fibm5500,fibm6000,fibp1500,fibp2000,fibp2500,fibp3000,fibp3500,fibp4000,fibp4500,fibp5000;
int init()
{
SetIndexStyle(0, DRAW_ARROW, EMPTY, 2);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY, 2);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
return(0);
}
int deinit()
{
ObjectDelete("FiboUp");
ObjectDelete("FiboDn");
ObjectDelete("FiboIn");
return(0);
}
//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+
int DrawFibo1()
{
if(ObjectFind("FiboUp") == -1)
ObjectCreate("FiboUp",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
else
{
ObjectSet("FiboUp",OBJPROP_TIME2, StartTime);
ObjectSet("FiboUp",OBJPROP_TIME1, StartTime);
ObjectSet("FiboUp",OBJPROP_PRICE1,HiPrice+Range);
ObjectSet("FiboUp",OBJPROP_PRICE2,HiPrice);
}
ObjectSet("FiboUp",OBJPROP_LEVELCOLOR,UpperFiboColor);
ObjectSet("FiboUp",OBJPROP_FIBOLEVELS,13);
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("FiboUp",0,"(100.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+3,0.500); ObjectSetFiboDescription("FiboUp",3,"(150.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+6,1.000); ObjectSetFiboDescription("FiboUp",6,"(200.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+8,1.500); ObjectSetFiboDescription("FiboUp",8,"(250.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+10,2.000); ObjectSetFiboDescription("FiboUp",10,"(300.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+11,2.500); ObjectSetFiboDescription("FiboUp",11,"(350.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+12,3.000); ObjectSetFiboDescription("FiboUp",12,"(400.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+13,3.500); ObjectSetFiboDescription("FiboUp",13,"(450.0%) - %$");
ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+14,4.000); ObjectSetFiboDescription("FiboUp",14,"(500.0%) - %$");
ObjectSet("FiboUp",OBJPROP_RAY,true);
ObjectSet("FiboUp",OBJPROP_BACK,true);
if(ObjectFind("FiboDn") == -1)
ObjectCreate("FiboDn",OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
else
{
ObjectSet("FiboDn",OBJPROP_TIME2, StartTime);
ObjectSet("FiboDn",OBJPROP_TIME1, StartTime);
ObjectSet("FiboDn",OBJPROP_PRICE1,LoPrice-Range);
ObjectSet("FiboDn",OBJPROP_PRICE2,LoPrice);
}
ObjectSet("FiboDn",OBJPROP_LEVELCOLOR,LowerFiboColor);
ObjectSet("FiboDn",OBJPROP_FIBOLEVELS,19);
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("FiboDn",0,"(0.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+3,0.500); ObjectSetFiboDescription("FiboDn",3,"(-50.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+6,1.000); ObjectSetFiboDescription("FiboDn",6,"(-100.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+9,1.500); ObjectSetFiboDescription("FiboDn",9,"(-150.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+12,2.000); ObjectSetFiboDescription("FiboDn",12,"(-200.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+13,2.500); ObjectSetFiboDescription("FiboDn",13,"(-250.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+14,3.000); ObjectSetFiboDescription("FiboDn",14,"(-300.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+15,3.500); ObjectSetFiboDescription("FiboDn",15,"(-350.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+16,4.000); ObjectSetFiboDescription("FiboDn",16,"(-400.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+17,4.500); ObjectSetFiboDescription("FiboDn",17,"(-450.0%) - %$");
ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+18,5.000); ObjectSetFiboDescription("FiboDn",18,"(-500.0%) - %$");
ObjectSet("FiboDn",OBJPROP_RAY,true);
ObjectSet("FiboDn",OBJPROP_BACK,true);
if(InnerFibs)
{
if(ObjectFind("FiboIn") == -1)
ObjectCreate("FiboIn",OBJ_FIBO,0,StartTime,HiPrice,StartTime+SF_Period*60,LoPrice);
else
{
ObjectSet("FiboIn",OBJPROP_TIME2, StartTime);
ObjectSet("FiboIn",OBJPROP_TIME1, StartTime+SF_Period*60);
ObjectSet("FiboIn",OBJPROP_PRICE1,HiPrice);
ObjectSet("FiboIn",OBJPROP_PRICE2,LoPrice);
}
ObjectSet("FiboIn",OBJPROP_LEVELCOLOR,MainFiboColor);
ObjectSet("FiboIn",OBJPROP_FIBOLEVELS,7);
ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("FiboIn",0,"Period LOW (0.0) - %$");
ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+3,0.500); ObjectSetFiboDescription("FiboIn",3,"(50.0) - %$");
ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+6,1.000); ObjectSetFiboDescription("FiboIn",6,"Period HIGH (100.0) - %$");
ObjectSet("FiboIn",OBJPROP_RAY,true);
ObjectSet("FiboIn",OBJPROP_BACK,true);
}
else
ObjectDelete("FiboIn");
}
//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+
int start()
{
int shift = iBarShift(NULL,SF_Period,Time[0]) + 1; // yesterday
HiPrice = iHigh(NULL,SF_Period,shift);
LoPrice = iLow (NULL,SF_Period,shift);
StartTime = iTime(NULL,SF_Period,shift);
if(TimeDayOfWeek(StartTime)==0/*Sunday*/)
{//Add fridays high and low
HiPrice = MathMax(HiPrice,iHigh(NULL,SF_Period,shift+1));
LoPrice = MathMin(LoPrice,iLow(NULL,SF_Period,shift+1));
}
Range = HiPrice-LoPrice;
fibp1500=HiPrice+(Range*0.5);
fibp2000=HiPrice+(Range*1);
fibp2500=HiPrice+(Range*1.5);
fibp3000=HiPrice+(Range*2);
fibp4000=HiPrice+(Range*3);
fibp4500=HiPrice+(Range*3.5);
fibp5000=HiPrice+(Range*4);
fibm1500=HiPrice-(Range*1.5);
fibm2000=HiPrice-(Range*2);
fibm2500=HiPrice-(Range*2.5);
fibm3000=HiPrice-(Range*3);
fibm3500=HiPrice-(Range*3.5);
fibm4000=HiPrice-(Range*4);
fibm4500=HiPrice-(Range*4.5);
fibm5000=HiPrice-(Range*5);
fibm5500=HiPrice-(Range*5.5);
fibm6000=HiPrice-(Range*6);
fib000=HiPrice-(Range*1);
fib500=HiPrice-(Range*0.5);
fib1000=HiPrice;
for(int i=1;i<=limit;i++){
counter=i;
Crange=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Crange=AvgRange/10;
if((Open[i+1]<fibp1500&&Open[i]>fibp1500)||(Open[i+1]<fibp2000&&Open[i]>fibp2000)||(Open[i+1]<fibp2500&&Open[i]>fibp2500)||(Open[i+1]<fibp3000&&Open[i]>fibp3000)||
(Open[i+1]<fibp4000&&Open[i]>fibp4000)||(Open[i+1]<fibp4500&&Open[i]>fibp4500)||(Open[i+1]<fibp5000&&Open[i]>fibp5000)||(Open[i+1]<fibm1500&&Open[i]>fibm1500)||
(Open[i+1]<fibm2000&&Open[i]>fibm2000)||(Open[i+1]<fibm2500&&Open[i]>fibm2500)||(Open[i+1]<fibm3000&&Open[i]>fibm3000)||(Open[i+1]<fibm3500&&Open[i]>fibm3500)||
(Open[i+1]<fibm4000&&Open[i]>fibm4000)||(Open[i+1]<fibm4500&&Open[i]>fibm4500)||(Open[i+1]<fibm5000&&Open[i]>fibm5000)||(Open[i+1]<fibm5500&&Open[i]>fibm5500)||
(Open[i+1]<fibm6000&&Open[i]>fibm6000)||(Open[i+1]<fib000&&Open[i]>fib000)||(Open[i+1]<fib500&&Open[i]>fib500)||(Open[i+1]<fib1000&&Open[i]>fib1000)){
if(PopUpAlert == true && Bars>alertBar) {Alert ("SpudFibo: ",Symbol()+" "+Period()+": Buy Alert @ "+DoubleToStr(Bid,Digits));alertBar = Bars;}
if(EmailAlert == true)SendMail ("SpudFibo: ",Symbol()+" "+Period()+": Buy Alert @ "+DoubleToStr(Bid,Digits));
if(ArrowsSignal == true)CrossUp[i] = Low[i] - Crange*0.5;}
if((Open[i+1]>fibp1500&&Open[i]<fibp1500)||(Open[i+1]>fibp1500&&Open[i]<fibp1500)||(Open[i+1]>fibp1500&&Open[i]<fibp1500)||(Open[i+1]>fibp3000&&Open[i]<fibp3000)||
(Open[i+1]>fibp4000&&Open[i]<fibp4000)||(Open[i+1]>fibp4500&&Open[i]<fibp4500)||(Open[i+1]>fibp5000&&Open[i]<fibp5000)||(Open[i+1]>fibm1500&&Open[i]<fibm1500)||
(Open[i+1]>fibm2000&&Open[i]<fibm2000)||(Open[i+1]>fibm2500&&Open[i]<fibm2500)||(Open[i+1]>fibm3000&&Open[i]<fibm3000)||(Open[i+1]>fibm3500&&Open[i]<fibm3500)||
(Open[i+1]>fibm4000&&Open[i]<fibm4000)||(Open[i+1]>fibm4500&&Open[i]<fibm4500)||(Open[i+1]>fibm5000&&Open[i]<fibm5000)||(Open[i+1]>fibm5500&&Open[i]<fibm5500)||
(Open[i+1]>fibm6000&&Open[i]<fibm6000)||(Open[i+1]>fib000&&Open[i]<fib000)||(Open[i+1]>fib500&&Open[i]<fib500)||(Open[i+1]>fib1000&&Open[i]<fib1000)){
if(PopUpAlert == true && Bars>alertBar) {Alert ("SpudFibo: ",Symbol()+" "+Period()+": Sell Alert @ "+DoubleToStr(Bid,Digits));alertBar = Bars;}
if(EmailAlert == true)SendMail ("SpudFibo: ",Symbol()+" "+Period()+": Sell Alert @ "+DoubleToStr(Bid,Digits));
if(ArrowsSignal == true)CrossDown[i] = High[i] + Crange*0.5;}
if ((CrossUp[0] > 2000) && (CrossDown[0] > 2000)) { prevtime = 0; }
if ((CrossUp[0] == Low[0] - Range*0.5) && (prevtime != Time[0]))
{
prevtime = Time[0];
}
if ((CrossDown[0] == High[0] + Range*0.5) && (prevtime != Time[0]))
{
prevtime = Time[0];
}}
DrawFibo1();
return(0);
}
//+------------------------------------------------------------------+
Comments