In previous code I used the time to detect a new bar. This time let's use the bars count to detect a new bar. it's way lighter and faster than using the time method.
int BarsTotal_OnInt; int BarsTotal_OnTick; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { BarsTotal_OnInt = iBars(NULL,PERIOD_CURRENT); // Asign the total bars at initialization return(INIT_SUCCEEDED); } void OnTick() // OnTick Function { BarsTotal_OnTick = iBars(NULL,PERIOD_CURRENT); // Stores the latest amount if(BarsTotal_OnTick > BarsTotal_OnInt) // New bar has arrived { BarsTotal_OnInt = BarsTotal_OnTick; // Updates the history. Alert("New Bar has arrived"); Comment("Bars Count in history -: ", BarsTotal_OnInt, "\n", "Bars Count in Live -: ", BarsTotal_OnTick); // Your Code goes here. -------------------------- // You can update a "flag" / variable to use it on later too. } }
Candle Analysis Report
This script helps traders understand the distribution and range of candles in a specific period, which can be useful for making trading decisions such as determining which historical values to use for Take Profit or Stop Loss.
Counter Attack Candlestick
Counter attack candlestick pattern
Basic GridManager Library
This is a basic library to create and manage grids.
Code blocks for "Counters" like Count "X" time and pass
Here are some examples of codes for set counters based on "Count"