Author: emsjoflo
PIPQInd

This indicator is designed to help traders identify potential momentum shifts and entry opportunities by tracking a dynamic "Trailing Stop" level. It analyzes price action to determine where a trend might be losing steam or where a reversal might occur, providing visual cues and notifications for the user.

Core Logic and Mechanics

Dynamic Stop Level Tracking The primary engine of this script is its ability to calculate a floating reference point (a "Stop Level"). Rather than being a fixed price, this level moves in relation to the current market price. It adjusts based on the direction of the price movement:

  • If the price moves significantly in one direction, the stop level follows it at a specific distance (defined by a user-set pip value).
  • The script constantly compares the current closing price against the previous period's results to decide whether to tighten or loosen this reference point.

Trend Recognition and Signal Generation The indicator looks for specific "breakout" behaviors to signal potential trades:

  • Buy Signals: If the market price moves above a previously established stop level—specifically after showing signs of a reversal or recovery from a lower point—the script identifies a bullish opportunity. It then marks this on the chart with an upward-pointing arrow.
  • Sell Signals: Conversely, if the price drops below a stop level following a move from a higher point, it identifies a bearish opportunity and marks it with a downward-pointing arrow.

Visual Support Tools To assist the user in interpreting the data, the script generates several visual elements on the chart:

  • Trend Lines: When a significant signal is detected, the indicator draws a horizontal trend line (colored DodgerBlue) to represent a potential support or resistance zone based on market volatility (using the ATR calculation).
  • Histogram Bars: The script uses different colored bars (Red and Blue) to highlight specific price boundaries during these signaled moments.
  • Stop Dots: A dotted line is plotted to visualize the current "Trailing Stop" level, allowing traders to see how the script's logic is currently tracking the market.

Smart Alert System The script includes an automated notification system that can be customized by the user. It doesn't just alert on every minor movement; it follows specific rules:

  • Timing: It calculates how many minutes remain before a candle closes to ensure the user isn't alerted prematurely.
  • Frequency: To prevent "alert fatigue," it includes a cooldown timer so that notifications are not sent too frequently.
  • Communication: Depending on the user’s settings, the script can trigger an on-screen alert or send an email containing specific market data (current price, previous levels, and time remaining) to notify the trader of a potential "Buy" or "Sell" setup.

Summary for the User

Essentially, this tool acts as an automated "trend follower." It constantly draws a safety line behind the current price; when the price "breaks out" from that line with enough momentum, it paints an arrow on your chart and sends you a notification, suggesting that a new trade opportunity may be forming.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1It sends emails
18 Views
0 Downloads
0 Favorites
PIPQInd
//+------------------------------------------------------------------+
//|                                                                  |
//|                 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_width1 2
#property indicator_color2 Red
#property indicator_width2 2
#property indicator_color3 DodgerBlue
#property indicator_color4 Tomato
#property indicator_color5 Black
//----
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, STYLE_SOLID);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, UpArrow);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, DownArrow);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2);
   SetIndexBuffer(2,BlueBar);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,2);
   SetIndexBuffer(3,RedBar);
   SetIndexStyle(4, DRAW_LINE, STYLE_DOT,1,Black);
   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,DodgerBlue);
         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(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,DodgerBlue);
         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 (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