time to next bar

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
time to next bar

This tool is designed to analyze market trends and provide real-time visual feedback regarding price momentum and timing on your trading chart. It works by scanning historical price data to identify specific shifts in momentum, specifically focusing on whether the market is transitioning from a downward trend to an upward one (or vice versa).

How the Logic Works

1. Momentum Tracking The script utilizes a technical indicator known as the MACD (Moving Average Convergence Divergence) to monitor the "speed" and "direction" of price movements. It looks specifically at three consecutive points in time to detect "crosses"—moments where the momentum shifts from negative to positive or vice versa.

2. Identifying Key Price Points When the script detects these momentum shifts, it captures specific high and low price points:

  • Upward Potential: If the momentum moves from a negative state to a positive state, the script identifies the highest price reached during that transition.
  • Downward Potential: If the momentum moves from a positive state to a negative state, the script identifies the lowest price reached during that transition.

3. Trend Confirmation To ensure that the signals are meaningful, the tool applies an additional layer of verification using Exponential Moving Averages (EMA). It compares two different averages: a fast-moving one and a slow-moving one.

  • It checks if the fast average is significantly above the slow average (indicating strength) or significantly below it (indicating weakness).

4. Real-Time Countdown A unique feature of this script is its live reporting system. While it processes these technical calculations, it simultaneously monitors the current time on your chart. It calculates exactly how much time remains until the start of the next candle (bar), displaying a countdown in minutes and seconds directly on your screen.

Summary for the User

Essentially, this script acts as a dual-purpose monitor. It filters through market history to identify significant turning points where momentum changes direction, while providing you with a live "clock" so you can stay perfectly synced with the timing of new price candles.

Price Data Components
Series array that contains open time of each bar
Indicators Used
MACD HistogramMoving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
time to next bar
//+------------------------------------------------------------------+
//|                                           |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DeepSkyBlue
//---- input parameters
extern int       numBars=630;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexArrow(0,160);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexArrow(1,160);   
   SetIndexEmptyValue(1,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   
   int shift=0;
	double MACD=0, MACD1=0, MACD2=0 ,pvu=0 ,pvd=0;
//---- TODO: add your code here
   for (shift=numBars-Period()-1;shift>=1;shift--)
   {
   //********** Coding Gue mulai di sini nih 
   MACD=iMACD(NULL,0,5,13,9,PRICE_CLOSE,MODE_MAIN,shift);
   MACD1=iMACD(NULL,0,5,13,9,PRICE_CLOSE,MODE_MAIN,shift+1);
   MACD2=iMACD(NULL,0,5,13,9,PRICE_CLOSE,MODE_MAIN,shift+2);
   
   double seco= (Time[4]-Time[5])-MathMod(CurTime(),Time[4]-Time[5]);
   double minu=seco/60;
   seco=(minu-MathFloor(minu))*60;
   minu=MathFloor(minu);
   
   if (MACD2<0 && MACD1>=0) 
      {
      pvu=High[shift+1];
      }
   if (MACD2>0 && MACD1<=0) 
      {
      pvd=Low[shift+1];
      }

   if (iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,shift+1)>=iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,shift+1)+(1*Point))
      {
   //   ExtMapBuffer1[shift]=pvu;
      Comment("Time for next bar: ",	minu," min ",seco," sec");
      }
   if (iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,shift+1)<=iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,shift+1)-(1*Point)) 
      {
   //	ExtMapBuffer2[shift]=pvd;
   	Comment("Time for next bar: ",	minu," min ",seco," sec");
   	}

   }
//----

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

Comments