PIPQInd_SLTSm
Download scriptThis script is a technical analysis tool designed to help traders identify potential trend reversals and price action shifts by monitoring specific "breakout" levels. It works by tracking the relationship between current market prices and a dynamically calculated threshold, providing visual cues on the chart and optional notifications for traders.
Core Logic and Functionality
1. Dynamic Level Tracking The tool continuously monitors the closing prices of candles to determine a specific price level (referred to as a "Stop Level"). This level isn't static; it adjusts based on price movement:
- If the price moves significantly in one direction, the tool recalculates the threshold to reflect that new momentum.
- It uses a user-defined "Pip" setting to determine how much distance to maintain between the current price and this calculated level.
2. Trend Detection and Signal Generation The script looks for specific "rejection" or "breakout" patterns where the price crosses over these dynamic levels.
- Buy Opportunities: When the price moves above the threshold after showing signs of a pullback, the script identifies a potential upward move. It then calculates a visual support line based on recent market volatility (using the Average True Range) to help define a potential entry point.
- Sell Opportunities: Conversely, when the price drops below the threshold after a peak, the script identifies a potential downward move and calculates a visual resistance line.
3. Visual Indicators To make this data easy to read on a live chart, the script provides several visual elements:
- Arrows: Specific arrows appear on the chart to mark where the logic has identified a potential Buy or Sell setup.
- Color Bars: The tool uses colored bars (Blue and Red) to highlight high and low price points during these signal phases.
- Trend Lines: When a signal is triggered, the script draws short horizontal trend lines on the chart to visually represent the "Stop" or "Target" zones based on current volatility.
4. Automated Alerts For traders who cannot watch the screen constantly, the script includes an alert system. It can be configured to:
- Pop-up Alerts: Trigger a sound/visual notification on the trading platform when a setup is detected.
- Email Notifications: Send an automated email with a detailed summary, including the current price, the symbol being traded, and a countdown of how many minutes remain before the current candle closes.
- Smart Timing: The script includes logic to prevent "spamming" by ensuring alerts are only sent at specific intervals or when there is sufficient time left in the current candle to act on the information.
Summary for the User
In simple terms, this tool acts as a "scout." It watches how the price interacts with recent highs and lows, calculates a dynamic boundary based on your preferred settings, and alerts you whenever the price breaks through that boundary in a way that suggests a new trend is starting.
//+------------------------------------------------------------------+
//| |
//| PIPQind.mq4 |
//| |
//+------------------------------------------------------------------+
#property copyright "emsjoflo"
#property link "automaticforec.invisionzone.com"
//----
#property indicator_chart_window
#include <stdlib.mqh>
#property indicator_buffers 5
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 DodgerBlue
#property indicator_color4 Tomato
#property indicator_color5 MediumPurple
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2
#property indicator_style5 2
//----
extern double nPips=65;
extern bool SendAlert=false ;
extern bool SendEmail=false;
extern int AlertMinutesB4Close =5;
extern int AlertEveryNMinutes =10;
extern double ATRmultiplier= 0.45; //
//----
double stop,atr,atrstop;
double UpArrow[];
double DownArrow[];
double BlueBar[],RedBar[];
double TrStopDots[];
datetime alertsent;
string MinutesB4BarCloses;
int shift=0,i=0;
double cnt=0;
double TrStopLevel=0;
double PREV=0;
//void SetLoopCount(int loops)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 233);
SetIndexBuffer(0, UpArrow);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 234);
SetIndexBuffer(1, DownArrow);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,BlueBar);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3,RedBar);
SetIndexStyle(4, DRAW_LINE);
SetIndexBuffer(4,TrStopDots);
alertsent=CurTime();
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
//----
for(int shift=Bars-2;shift>=0 ;shift--)
{
if (ObjectFind(TimeToStr(Time[shift]))>-1) ObjectDelete(TimeToStr(Time[shift]));
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//----
limit=Bars-counted_bars-1;
// loop from first bar to current bar (with shift=0)
for(shift=limit;shift>=0 ;shift--)
{
if((Close[shift]==PREV))
{
TrStopLevel=PREV;
}
else
{
if((Close[shift+1])<=PREV && (Close[shift]<PREV) )
{
TrStopLevel=MathMin(PREV,Close[shift]+nPips*Point);
}
else
{
if(((Close[shift+1])>=PREV) && (Close[shift]>PREV))
{
TrStopLevel=MathMax(PREV,Close[shift]-nPips*Point);
}
else
{
if((Close[shift]>PREV))
{
TrStopLevel=Close[shift]-nPips*Point;
}
else TrStopLevel=Close[shift]+nPips*Point;
}
}
}
//Comment("TRStop = "+TrStopLevel);
TrStopDots[shift]=TrStopLevel;
if (UpArrow[shift]!=0 && UpArrow[shift]!=TrStopDots[shift]) UpArrow[shift]=0.0;
if (DownArrow[shift]!=TrStopDots[shift]) DownArrow[shift]=0.0;
if(Close[shift] > TrStopLevel && (Close[shift+1]<PREV || (Close[shift+1]<=TrStopDots[shift+1] && Close[shift+2]<TrStopDots[shift+2])) && PREV !=0)
{
atr=iATR(NULL,0,14,shift);
stop=Low[Lowest(NULL,0,MODE_LOW,3,shift)];
atrstop =NormalizeDouble(TrStopLevel-atr*ATRmultiplier,MarketInfo(Symbol(),MODE_DIGITS));
if (atrstop > stop) stop=atrstop;
if (ObjectFind(TimeToStr(Time[shift]))>-1) ObjectDelete(TimeToStr(Time[shift]));
ObjectCreate(TimeToStr(Time[shift]),OBJ_TREND,0,Time[shift+2],stop,Time[shift],stop);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_RAY,0);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_COLOR,SlateBlue);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_WIDTH,2);
// Comment(stop);
if ((Bid > TrStopDots[0]) && (Close[1]<=TrStopDots[1]) && ((CurTime()-Time[0])>=(Time[0]-Time[1]-AlertMinutesB4Close*60)) && (CurTime()-alertsent> AlertEveryNMinutes*60))
{
MinutesB4BarCloses=TimeToStr((Time[0]-Time[1])-(CurTime()-Time[0]),TIME_MINUTES);
// if(SendAlert) Alert("Look for Buying opportunity soon");
if (SendAlert) Alert("PIPQind: Buy setup on "+Symbol()+" M"+Period()+" Pr:"+Close[0]+"");
if (SendEmail) SendMail("Possible Buy setup on "+Symbol(),"PIPQind anticpates a Buy signal on "+Symbol()+" in "+MinutesB4BarCloses+" minutes"+" at "+TimeToStr(CurTime())+" Bid: "+Bid+" Ask: "+Ask+" Close[0]:"+Close[0]+"Close[1]: "+Close[1]+" TrStopDots[1]: "+TrStopDots[1]+" PREV: "+PREV+" TrStopLevel: "+TrStopLevel+" TrStopDots[0]: "+TrStopDots[0]);
alertsent=CurTime();
}
RedBar[shift]=Low[shift];
BlueBar[shift]=High[shift];
UpArrow[shift]=TrStopLevel;
}
if(Close[shift] < TrStopLevel && (Close[shift+1]>PREV || (Close[shift+1]>=TrStopDots[shift+1] && Close[shift+2]>=TrStopDots[shift+2])) && PREV !=0)
{
atr=iATR(NULL,0,14,shift);
stop=High[Highest(NULL,0,MODE_HIGH,3,shift)];
atrstop=NormalizeDouble(TrStopLevel+atr*ATRmultiplier,MarketInfo(Symbol(),MODE_DIGITS));
if (atrstop < stop) stop =atrstop;
if (ObjectFind(TimeToStr(Time[shift]))>-1) ObjectDelete(TimeToStr(Time[shift]));
ObjectCreate(TimeToStr(Time[shift]),OBJ_TREND,0,Time[shift+2],stop,Time[shift],stop);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_RAY,0);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_COLOR,Orchid);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_WIDTH,2);
Comment (stop);
if((Ask < TrStopDots[0]) && (Close[1]>=TrStopDots[1]) && ((CurTime()-Time[0])>=(Time[0]-Time[1]-AlertMinutesB4Close*60)) && (CurTime()-alertsent> AlertEveryNMinutes*60))
{
MinutesB4BarCloses=TimeToStr((Time[0]-Time[1])-(CurTime()-Time[0]),TIME_MINUTES);
// if (SendAlert)Alert("Look for Selling opportunity soon");
if (SendAlert) Alert("PIPQind: Sell setup on "+Symbol()+" M "+Period()+" Pr:"+Close[0]+"");
if (SendEmail) SendMail("Possible Sell setup on "+Symbol(),"PIPQind anticipates a sell signal on "+Symbol()+" in "+MinutesB4BarCloses+" minutes "+" at " +TimeToStr(CurTime())+" Bid: "+Bid+" Ask: "+Ask+" Close[0]:"+Close[0]+"Close[1]: "+Close[1]+" TrStopDots[1]: "+TrStopDots[1]+" PREV: "+PREV+" TrStopLevel: "+TrStopLevel+" TrStopDots[0]: "+TrStopDots[0]);
alertsent=CurTime();
}
BlueBar[shift]=Low[shift];
RedBar[shift]=High[shift];
DownArrow[shift]=TrStopLevel;
}
PREV=TrStopLevel;
}
//for (i=0;i>5;i++)
// {
i=1;
if (UpArrow[i]>0 && UpArrow[i]<TrStopDots[i]) UpArrow[i]=0.0;
if (DownArrow[i]>TrStopDots[i]) DownArrow[i]=0.0;
//}
return(0);
}
//+------------------------------------------------------------------+
Comments