Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Code Snippet : Time Left Info Near to the Candle/Bars

1 min read

Here is a small time left code snippet that displays the seconds left for the bar to close near to the current running candle. If you are more focused on trading at a lower timeframe then this feature makes more sense as a lower timeframe trader. And the code is compatible with Amibroker 5.71 and onwards. It may not work with lower Amibroker versions.

time left code snippet near the running candle

 
Time left AFL code near to Current Running Candle


_SECTION_BEGIN("Time Left");

sound = ParamList("Sound Alert", "ON|OFF",0);

function GetSecondNum()

{

Time = Now( 4 );

Seconds = int( Time % 100 );

Minutes = int( Time / 100 % 100 );

Hours = int( Time / 10000 % 100 );

SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );

return SecondNum;

}

RequestTimedRefresh( 1 );

TimeFrame = Interval();

SecNumber = GetSecondNum();

Newperiod = SecNumber % TimeFrame == 0;

SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;

SecsToGo = TimeFrame - SecsLeft;


if ( NewPeriod )

{

GfxSelectSolidBrush( colorYellow );

GfxSelectPen( colorYellow, 2 );

if(sound=="ON")
{
_TRACE("New Period Alert");
Say( "New period" );
}
}


PlotTextSetFont(NumToStr(SecsToGo,1,False)+ " Sec Left", "Arial", 10, BarCount-1, Close[BarCount-1], colorred, colorDefault, -30 ); 


_SECTION_END(); 

Timeleft Parameter Settings

Masterclass on AmiBroker AFL coding

AMIBROKER

Masterclass on AmiBroker AFL coding

Write trading systems, explorations and backtests in AFL, and use ChatGPT to code faster.

  • AFL from basics to trading systems
  • Backtesting and optimisation done right
  • 7 courses in one masterclass
Learn AFL coding →by Marketcalls

Sound Alert is Control added to the External Parameters section and now one can toggle between Sound Off/On from the external dashboard as shown below. Right click over the charts and goto parameters to access the External Parameter Settings where you can control the sound settings. Sound Alert uses Text to speech based Amibroker Alerts

Timeleft Properties

How to Setup the AFL in Amibroker

1)Download Timeleft (Amibroker AFL Code).
2)Unzip Timeleft afl to local folder
3)Copy Timeleft.afl file to \\program files\\amibroker\\formula\\basic folder\\
5)Open Amibroker
6)Goto Charts->Basic Charts and apply/drag-and-drop the Timeleft code over any of your stratgies containing candle/bars over any timeframe.
7)Bingo you are done. Now you will be able to see the timeleft indicatons with sound alerts enabled by default.

Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

4 Replies to “Code Snippet : Time Left Info Near to the…”

  1. Sir, below line shows error 32.

    PlotTextSetFont(NumToStr(SecsToGo,1,False)+ ” Sec Left”, “Arial”, 10, BarCount-1, Close[BarCount-1], colorRed, colorDefault, -30 );

    Please check it.

      1. yes Sir, my version is Amibroker 5.60
        for this version what is the solution?

  2. sir, i am using 10 minute candle. for example if market open 9:15, the next candle would be 9:25. however, time left code showing 600 seconds. but instead of alerting 9:25, it will alert on 9:20. could you please let us know how to adjust. it.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More