Author: emsjoflo
PIPQInd_v1

This tool is designed to analyze price action and identify potential trend reversals or momentum shifts by tracking specific "stop levels" on a trading chart. Rather than relying on standard moving averages, it focuses on the relationship between current price movement and trailing thresholds.

Core Logic and Mechanism

Dynamic Stop Level Tracking The script constantly calculates a "Stop Level" based on previous price data. It monitors how the market is moving relative to its most recent history. If the price moves in a specific direction, the script adjusts this level (a distance defined by the user in pips) to trail behind the action. This creates a dynamic boundary that helps define the current "floor" or "ceiling" of a price movement.

Trend Identification The logic looks for specific breaches of these trailing levels to determine market sentiment:

  • Buy Opportunities: The tool identifies a potential upward shift when the price closes above the trailing stop level, specifically following a pattern where previous bars were below that level or showed signs of weakness.
  • Sell Opportunities: Conversely, it detects potential downward shifts when the price closes below the trailing stop level after showing signs of strength in previous bars.

Volatility Integration To ensure the signals are reliable and not triggered by minor market "noise," the script incorporates an Average True Range (ATR) calculation. This allows the tool to measure current market volatility and adjust the placement of its visual markers accordingly, ensuring that the suggested "stop" points are mathematically significant relative to how much the market is actually moving at that moment.

Visual Indicators and Alerts The script provides immediate visual feedback on the trading chart:

  • Arrows and Bars: It plots specific arrows and color-coded bars to highlight exactly where a trend change has been detected.
  • Trend Lines: When a significant signal is identified, the tool draws horizontal trend lines on the chart to visually represent the calculated support or resistance levels.
  • Proactive Notifications: One of the key features is its predictive alert system. It calculates how many minutes remain until a candle closes and can send real-time alerts (pop-ups or emails) to notify the user of an impending "Buy" or "Sell" setup before it fully matures.

Summary for the User

In simple terms, this script acts as a high-sensitivity "trend watcher." It tracks where a price movement might "break," calculates the safest distance for a stop based on market volatility, and alerts you when the price behaves in a way that suggests a new trend is starting. It aims to give traders an early heads-up on momentum shifts rather than just reacting to what has already happened.

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
11 Views
0 Downloads
0 Favorites
PIPQInd_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------
//|                                            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