Author: Denis Orlov

This script is designed as a specialized technical indicator for the MetaTrader 4 platform. It monitors price movements in real-time to calculate and visualize the "net momentum" or the difference between upward and downward price pressure during a single trading candle (bar).

Core Logic and Functionality

1. Real-Time Price Tracking The script continuously tracks the price changes from one tick to the next. It compares the current price against the previous price to determine if the market is moving up or down. It accumulates these movements into two separate categories:

  • Upward Momentum: A running total of all positive price increases.
  • Downward Momentum: A running total of all negative price decreases.

2. Net Difference Calculation Instead of just looking at the final price of a candle, this logic calculates the "net difference" between the total upward movement and the total downward movement. By subtracting the accumulated downward movement from the upward movement, it provides a clearer picture of the true strength of the market's direction, filtering out minor oscillations.

3. Visual Feedback & Dynamic Labeling The indicator provides immediate visual feedback on the trading chart:

  • Dynamic Labels: It displays numerical values representing the current net difference and the maximum difference achieved during the current candle.
  • Color Coding: The labels change color (Green for bullish/positive bias, Red for bearish/negative bias) to help traders quickly identify market sentiment at a glance.

4. Milestone Detection & Alerts The script includes a monitoring system for significant price movements:

  • Maximum Difference Tracking: It keeps track of the highest net difference reached during the current candle.
  • Threshold Alerts: You can set a specific "Difference Line" (a numerical threshold). If the net difference between upward and downward movement reaches this target, the script will:
    • Trigger an audible alert notification.
    • Draw a vertical line on the chart to mark the exact moment the milestone was hit.
    • Label that specific point with the value of the difference.

5. Automated Reset Logic The script is designed to be "self-cleaning." Every time a new candle forms on the chart, it automatically resets all previous calculations (sums, maximums, and price references). This ensures that the data shown is always relevant to the current active candle, preventing old data from polluting the current analysis.

Summary for the User

Essentially, this tool helps you see "how hard" the market is pushing in one direction versus the other within a single bar. It filters out noise and highlights significant surges of momentum, alerting you whenever the price moves with enough concentrated strength to hit your predefined target.

Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
Tick_v1
//+------------------------------------------------------------------+
//|                                                       Tick.mq4 |
//|                                                      Denis Orlov |
//|                                    http://denis-or-love.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Denis Orlov"
#property link      "http://denis-or-love.narod.ru"

//#include <Trend.mqh>

#property indicator_separate_window

double Line1[],Line2[],Line3[],Line4[],Line5[];
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
//#property indicator_color4 Green
//#property indicator_color5 Red

double oldPrice;
double UpSumm, DnSumm, MaxDiff;
datetime per;

extern int Diff_Line=6;
extern bool Diff_Alert=True;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    IndicatorShortName("Volume");
      int Win=WindowFind("Volume");
   DrawLabels("Diff", 1, 30, 10, "...", Blue, Win, 12);
   DrawLabels("MaxDiff", 1, 30, 30, "...", Blue, Win, 14);
   //ObjectSet("MaxDiff", OBJPROP_FONTSIZE, 14); 
   ObjectSetText("MaxDiff","...",14,"Arial",Blue);
   
//---- indicators
   SetIndexBuffer(0,Line1);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);//DRAW_LINE
   SetIndexShift(0,2);
   
   SetIndexBuffer(1,Line2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexShift(1,2);
   
   SetIndexBuffer(2,Line3);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexShift(2,2);
   
     /* SetIndexBuffer(4,Line4);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,2);//
   SetIndexBuffer(5,Line5);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,2);*/
   
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
      int    i, Counted_bars=IndicatorCounted();
      
      
      
     i=Bars-Counted_bars-1;           // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîãî  
     //if (History>0 && i>History-1)                 // Åñëè ìíîãî áàðîâ òî ..      
      // i=History-1; 
     /* while(i>=2)                      // Öèêë ïî íåïîñ÷èòàííûì áàðàì     
      { 
        if(Bull_Bear(i)>0) {Line1[i+1]=Volume[i]; Line2[i+1]=Volume[i]-Volume[i]/24;}
        if(Bull_Bear(i)<0) {Line2[i+1]=Volume[i]; Line3[i+1]=Volume[i]-Volume[i]/24;}
      i--;
      }*/
      
      if (per == Time[0])//òîò æå áàð
      {
         double Razn=(Close[0]-oldPrice)/Point;
         //Alert("Bid="+Bid+";oldPrice="+oldPrice+";Razn="+Razn);
         if(Razn>0)
            {
               UpSumm=UpSumm+Razn;
            }
         if(Razn<0)
            {
                DnSumm=DnSumm+Razn;
            } 
         oldPrice=Close[0]; 
 
       Line1[1]=UpSumm; 
       Line2[0]=-DnSumm; 
       //if(Line1[0]<Line2[0])Line3[0]=UpSumm; else Line3[0]=0;
       
       int Win=WindowFind("Volume");
       double Diff=Line1[1]-Line2[0];
       string DiffS=DoubleToStr(Diff, 1);
       
        if(Line1[1]>Line2[0])
         {color clr=Green; DrawLabels("Diff", 1, 30, 10, DiffS ,clr , Win, 12); 
          }//Line4[0]=Diff*2;
         else
       if(Line1[1]<Line2[0])
         {clr=Red; DrawLabels("Diff", 1, 30, 10, DiffS, clr, Win, 12); 
         }//Line5[0]=-Diff*2;
        // else
       //if(Line1[1]==Line2[0])
         //{clr=Blue; DrawLabels("Diff", 1, 30, 10, "..." ,clr , Win, 12); 
        //}// Line5[0]=0; Line4[0]=0;
        
        if(MathAbs(Diff)>=MathAbs(MaxDiff))
         {
          MaxDiff=Diff;
          DrawLabels("MaxDiff", 1, 30, 30, DiffS ,clr , Win, 14); 
          
          if(Diff_Line!=0 && MathAbs(MaxDiff)>=Diff_Line)
            {
            string name="Diff "+TimeToStr(Time[0],TIME_MINUTES);
            
            if(Diff_Alert && ObjectFind(name)==-1)
               Alert(Symbol()+" : Ðàçíèöà ìåæäó òèêàìè äîñòèãëà "+DiffS);
               
            if(ObjectFind(name)==-1)
               ObjectCreate(name, OBJ_VLINE,Win, Time[0], 0);
         ObjectSet(name, OBJPROP_COLOR, clr ) ;
         ObjectSetText( name, DiffS); 
            }
         }
         
         
         
      }
      else// íîâûé áàð
      {
       per = Time[0];

       Line1[3]=UpSumm; 
       Line2[3]=-DnSumm;
       if(Line1[3]<Line2[3])Line3[3]=UpSumm; else Line3[3]=0;
       
       Line1[2]=0; 
       Line2[2]=0;
        Line1[1]=0; 
         Line2[1]=0;
       
       UpSumm=0; DnSumm=0; MaxDiff=0;
      // Line5[0]=Line5[1]; Line4[0]=Line4[1];
       oldPrice=Open[0];

      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
int DrawLabels(string name, int corn, int X, int Y, string Text, color Clr=Green, int W=0, int FSize=10)
   {
     int Error=ObjectFind(name);// Çàïðîñ 
   if (Error!=W)// Åñëè îáúåêòà â óê. îêíå íåò :(
    {  
      ObjectCreate(name,OBJ_LABEL,W, 0,0); // Ñîçäàíèå îáúåêòà
    }
     
     ObjectSet(name, OBJPROP_CORNER, corn);     // Ïðèâÿçêà ê óãëó   
     ObjectSet(name, OBJPROP_XDISTANCE, X);  // Êîîðäèíàòà Õ   
     ObjectSet(name,OBJPROP_YDISTANCE,Y);// Êîîðäèíàòà Y   
     ObjectSetText(name,Text,FSize,"Arial",Clr);
   }

Comments