DinapoliTargetsAlerts_Log

Download script
Author: mishanya
DinapoliTargetsAlerts_Log

This script is designed as a visual analysis tool for traders who use price action patterns to determine where the market might move next. Its primary purpose is to identify specific structural "swings" in price history and automatically project potential profit targets and risk levels directly onto your trading chart.

How the Logic Works

1. Structural Analysis (Swing Detection) The tool begins by scanning historical price data to identify significant peaks and valleys (highs and lows). Rather than looking at every tiny price flicker, it uses a specific "Length" parameter to ensure it only captures meaningful market turns. It tracks these movements to build a map of the most recent major price structures.

2. Identifying Key Reference Points Once the script identifies these significant turns, it isolates three critical points in the current price sequence:

  • Point A: The previous major structural high or low.
  • Point B: The immediate preceding structural point.
  • Point C: The most recent structural point (the current active move).

By identifying these three points, the script can calculate the "distance" and "direction" of the current market momentum.

3. Automated Projections (Target & Risk Lines) Based on the distance between Point A, B, and C, the script automatically calculates several horizontal lines on your chart:

  • Risk Management (Start & Stop): It determines a suggested "Start" entry area and a "Stop" loss level based on the current price trend. These are displayed as dotted lines to help you visualize where the trade might become invalid.
  • Profit Targets: The script uses mathematical ratios (specifically Fibonacci-style multipliers like 0.618, 1.618, etc.) to project five different target zones:
    • Target 1, 2, and 3: Standard price objectives based on the current move's expansion.
    • Fantasy & Crazy Dream: Extended, "moonshot" targets for cases where the market is in a very strong, over-extended trend.

4. Real-Time Alerts Beyond just drawing lines, the script actively monitors the live price (the "Bid"). If the current market price touches any of your calculated targets—whether it be Target 1 or the "Crazy Dream" level—the tool will trigger a pop-up alert on your screen and log the event in your terminal history.

Summary for the User

Essentially, this script does the heavy lifting of "measuring" the chart for you. Instead of you having to manually calculate where a trend might end based on previous highs and lows, the tool identifies the structure automatically and draws a roadmap of potential exit points and risk levels, alerting you the moment the price hits those marks.

Price Data Components
Series array that contains open time of each bar
Miscellaneous
It issuies visual alerts to the screen
14 Views
0 Downloads
0 Favorites
DinapoliTargetsAlerts_Log
//+------------------------------------------------------------------+
//|                                              DinapoliTargets.mq4 |
//|                                            mishanya_fx@yahoo.com |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mishanya"
#property link      "mishanya_fx@yahoo.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---- input parameters
extern int       barn=300;
extern int       Length=6;
//---- buffers
double ExtMapBuffer1[];
//double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexEmptyValue(0,0.0);
  //SetIndexDrawBegin(0, barn);
   //SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,ExtMapBuffer1);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

   ObjectDelete("Start line");
   ObjectDelete("Stop line");
   ObjectDelete("Target1 line");
   ObjectDelete("Target2 line");
   ObjectDelete("Target3 line");
   ObjectDelete("Fantasy line");
   ObjectDelete("CrazyDream line");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int shift,Swing,Swing_n,uzl,i,zu,zd,mv;
   double PointA,PointB,PointC,Target1,Target2,Target3,Fantasy,CrazyDream,Start,Stop;
   double LL,HH,BH,BL,NH,NL; 
   double Uzel[10000][3]; 
   string text;
// loop from first bar to current bar (with shift=0) 
      Swing_n=0;Swing=0;uzl=0; 
      BH =High[barn];BL=Low[barn];zu=barn;zd=barn; 

for (shift=barn;shift>=0;shift--) { 
      LL=10000000;HH=-100000000; 
   for (i=shift+Length;i>=shift+1;i--) { 
         if (Low[i]< LL) {LL=Low[i];} 
         if (High[i]>HH) {HH=High[i];} 
   } 


   if (Low[shift]<LL && High[shift]>HH){ 
      Swing=2; 
      if (Swing_n==1) {zu=shift+1;} 
      if (Swing_n==-1) {zd=shift+1;} 
   } else { 
      if (Low[shift]<LL) {Swing=-1;} 
      if (High[shift]>HH) {Swing=1;} 
   } 

   if (Swing!=Swing_n && Swing_n!=0) { 
   if (Swing==2) {
      Swing=-Swing_n;BH = High[shift];BL = Low[shift]; 
   } 
      uzl=uzl+1; 
   if (Swing==1) {
      Uzel[uzl][1]=zd;
      Uzel[uzl][2]=BL;
   } 
   if (Swing==-1) {
      Uzel[uzl][1]=zu;
      Uzel[uzl][2]=BH; 
   } 
      BH = High[shift];
      BL = Low[shift]; 
   } 

   if (Swing==1) { 
      if (High[shift]>=BH) {BH=High[shift];zu=shift;}} 
      if (Swing==-1) {
          if (Low[shift]<=BL) {BL=Low[shift]; zd=shift;}} 
      Swing_n=Swing; 
   } 
   for (i=1;i<=uzl;i++) { 
      //text=DoubleToStr(Uzel[i][1],0);
      //text=;
         mv=StrToInteger(DoubleToStr(Uzel[i][1],0));
      //ExtMapBuffer1[mv]=Uzel[i][2];
   } 

PointA = Uzel[uzl-2][2];
PointB = Uzel[uzl-1][2];
PointC = Uzel[uzl][2];

Comment(PointA," ",PointB," ",PointC);

Target1=NormalizeDouble((PointB-PointA)*0.618+PointC,4);
Target2=PointB-PointA+PointC;
Target3=NormalizeDouble((PointB-PointA)*1.618+PointC,4);
Fantasy=NormalizeDouble((PointB-PointA)*2.618+PointC,4);
CrazyDream=NormalizeDouble((PointB-PointA)*4.618+PointC,4);
if (PointB<PointC)
{
Start= NormalizeDouble((PointB-PointA)*0.318+PointC,4)-(Ask-Bid);
Stop=PointC+2*(Ask-Bid);
}
if (PointB>PointC)
{
Start= NormalizeDouble((PointB-PointA)*0.318+PointC,4)+(Ask-Bid);
Stop=PointC-2*(Ask-Bid);
}


   if (ObjectFind("Start Line") != 0) 
     {
      ObjectCreate("Start line",OBJ_HLINE,0,Time[0],Start);
      ObjectSet("Start line",OBJPROP_COLOR,Honeydew);
      ObjectSet("Start line",OBJPROP_WIDTH,1);
      ObjectSet("Start line",OBJPROP_STYLE,STYLE_DOT);
     }
     else
     {
     ObjectMove("Start line", 0,Time[0],Start);
     }

   if (ObjectFind("Stop Line") != 0) 
     {
      ObjectCreate("Stop line",OBJ_HLINE,0,Time[0],Stop);
      ObjectSet("Stop line",OBJPROP_COLOR,Red);
      ObjectSet("Stop line",OBJPROP_WIDTH,1);
      ObjectSet("Stop line",OBJPROP_STYLE,STYLE_DOT);
     }
     else
     {
     ObjectMove("Stop line", 0,Time[0],Stop);
     }
    
    if (ObjectFind("Target1 Line") != 0) 
     {
      ObjectCreate("Target1 line",OBJ_HLINE,0,Time[0],Target1);
      ObjectSet("Target1 line",OBJPROP_COLOR,Green);
      ObjectSet("Target1 line",OBJPROP_WIDTH,1);
      ObjectSet("Target1 line",OBJPROP_STYLE,STYLE_DOT);
      
     }
     else
     {
     ObjectMove("Target1 line", 0,Time[0],Target1);
     }

    if (ObjectFind("Target2 Line") != 0) 
     {
      ObjectCreate("Target2 line",OBJ_HLINE,0,Time[0],Target2);
      ObjectSet("Target2 line",OBJPROP_COLOR,Yellow);
      ObjectSet("Target2 line",OBJPROP_WIDTH,1);
      ObjectSet("Target2 line",OBJPROP_STYLE,STYLE_DOT);
     
     }
     else
     {
     ObjectMove("Target2 line", 0,Time[0],Target2);
     }
    
    if (ObjectFind("Target3 Line") != 0) 
     {
      ObjectCreate("Target3 line",OBJ_HLINE,0,Time[0],Target3);
      ObjectSet("Target3 line",OBJPROP_COLOR,DarkOrchid);
      ObjectSet("Target3 line",OBJPROP_WIDTH,1);
      ObjectSet("Target3 line",OBJPROP_STYLE,STYLE_DOT);
      
     }
     else
     {
     ObjectMove("Target3 line", 0,Time[0],Target3);
     }
     
     if (ObjectFind("Fantasy Line") != 0) 
     {
      ObjectCreate("Fantasy line",OBJ_HLINE,0,Time[0],Fantasy);
      ObjectSet("Fantasy line",OBJPROP_COLOR,Lime);
      ObjectSet("Fantasy line",OBJPROP_WIDTH,1);
      ObjectSet("Fantasy line",OBJPROP_STYLE,STYLE_DOT);
      
     }
     else
     {
     ObjectMove("Fantasy line", 0,Time[0],Fantasy);
     }
     
  
     if (ObjectFind("CrazyDream Line") != 0) 
     {
      ObjectCreate("CrazyDream line",OBJ_HLINE,0,Time[0],CrazyDream);
      ObjectSet("CrazyDream line",OBJPROP_COLOR,DarkTurquoise);
      ObjectSet("CrazyDream line",OBJPROP_WIDTH,1);
      ObjectSet("CrazyDream line",OBJPROP_STYLE,STYLE_DOT);
      
     }
     else
     {
     ObjectMove("CrazyDream line", 0,Time[0],CrazyDream);     
     }
     
     
     if (Bid==Target1)
     {Alert("Target 1 Reached ", Symbol(),"!!!");
     Print("Target1=",Target1, TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS));

     }
     
     if (Bid==Target2)
     { Alert("Target 2 Reached ", Symbol(),"!!!");
     Print("Target2=",Target2, TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS));

     }
     if (Bid==Target3)
     { Alert("Target3 Reached ", Symbol(),"!!!");
     Print("Target3=",Target3, TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS));

     }
     
      
     if (Bid==Fantasy)
     { Alert("Fantasy Reached ", Symbol(),"!!!");
     Print("Fantasy=",Target3, TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS));

     }
     
      
     if (Bid==CrazyDream)
     { Alert("CrazyDream Reached ", Symbol(),"!!!");
     Print("CrazyDream=",Target3, TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS));

     }
     
     
   return(0);
  }
//+------------------------------------------------------------------+

Comments