Would you please help me to write a code that makes the first candle visible in a chart (switch to first candle when chart is launched)
Hi everyone,
I need an urgent help with writing a few lines of code that makes the first candle visible in a chart, in other words, when the chart is opened, it automatically scrolls the chart to the first candle available in that chart.
I would appreciate your kind help in advance
Hi everyone,
I need an urgent help with writing a few lines of code that makes the first candle visible in a chart, in other words, when the chart is opened, it automatically scrolls the chart to the first candle available in that chart.
I would appreciate your kind help in advance
No need for code.
- Disable AutoScroll. (this can be saved in the Default template).
- Press 'Home' key.
No need for code.
- Disable AutoScroll. (this can be saved in the Default template).
- Press 'Home' key.
Thanks for your help, I am a beginner so, sorry for stupid questions.
I tried
But it did not work, I placed it in "int OnInit()", should I place it somewhere else in the indicator? Please help me. I appreciate your kind guidance.
Thanks for your help, I am a beginner so, sorry for stupid questions.
I tried
But it did not work, I placed it in "int OnInit()", should I place it somewhere else in the indicator? Please help me. I appreciate your kind guidance.
- indicator
- script
- Advisor?
- indicator
- script
- Advisor?
Sorry that I did not explain more,
Actually, it is an indicator. I want to make first candle visible (to load all the history for that symbol before the indicator starts its calculations). I want it to happen automatically every time the indicator starts and it is enough to happen once before all other calculations start, so it does not need to be in a loop.
Thank you
Sorry that I did not explain more,
Actually, it is an indicator. I want to make first candle visible (to load all the history for that symbol before the indicator starts its calculations). I want it to happen automatically every time the indicator starts and it is enough to happen once before all other calculations start, so it does not need to be in a loop.
Thank you
What is "the first candle"? Picture, please.
This indicator scrolls graph:
//+------------------------------------------------------------------+ //| CHART_BEGIN.mq5 | //| Copyright © 2015, Vladimir Karputov | //| http://wmua.ru/slesar/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2015, Vladimir Karputov" #property link "http://wmua.ru/slesar/" #property version "1.00" #property indicator_chart_window #property indicator_plots 0 bool start=false; //--- input parameters input int begin_bar=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- if(!start) first_bar(); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool first_bar(void) { //--- get handle of the current chart long handle=ChartID(); if(handle>0) // if successful, additionally set up the chart { //--- disable auto scroll ChartSetInteger(handle,CHART_AUTOSCROLL,false); //--- set a shift from the right chart border ChartSetInteger(handle,CHART_SHIFT,true); //--- draw candlesticks ChartSetInteger(handle,CHART_MODE,CHART_CANDLES); //--- set the display mode for tick volumes ChartSetInteger(handle,CHART_SHOW_VOLUMES,CHART_VOLUME_TICK); //--- scroll 0 bars to the right of the history start ChartNavigate(handle,CHART_BEGIN,begin_bar); } return(true); } //+------------------------------------------------------------------+
This indicator scrolls graph:
Thank you so much for your help, it worked.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
I need an urgent help with writing a few lines of code that makes the first candle visible in a chart, in other words, when the chart is opened, it automatically scrolls the chart to the first candle available in that chart.
I would appreciate your kind help in advance