for (int i=0; i<=Limit; i++) DaveCloseTime=(iTime(Symbol(),PERIOD_D1,i)+DaveCloseHour*60*60+DaveCloseMin*60); {What is the difference between the above code and below?
DaveCloseTime=(iTime(Symbol(),PERIOD_D1,Limit)+DaveCloseHour*60*60+DaveCloseMin*60); {
You are creating the line and then moving it to 50 days ago.
What is the difference between the above code and below?
To be honest I am not certain. I thought by using "i" I would get DaveCloseTime calculated for every value of i between 0 and Limit. By inserting "Limit" as you have in that 2nd line, I think that would just calculate a single value.
Looking at both, I am thinking that I should be putting the calculated DaveCloseTime[i] values in a buffer
But then how I would then plot on the chart itself, vertical lines at each of these values is the question, I assume a histogram would have to be of fixed height, and if I persist with ObjectCreate approach, I am not sure I will get multiple vertical lines plotted..???
Hello Forum
I have tried to make an indicator which simply puts a vertical line on my chart at the same time every day
I have got the indicator to draw a line at the right time, but the line is not repeating or visible on different time frames, and is only drawn once, not each day as I desired.
I assume the error is in my ObjectSet, but not really sure
Would someone mind helping me fix this error
Why are you drawing the line or moving the line for each tick ? is it meant to move each tick ? perhaps your CPU is a bit cold ? why not just do it once every hour ?
You only want one line ? and it's called DaveCloseLine. If you want a line for each day what are they all called ? they can't all be called DaveCloseLine can they ?
Why are you drawing the line or moving the line for each tick ? is it meant to move each tick ? perhaps your CPU is a bit cold ? why not just do it once every hour ?
Thanks Raptor, I was having a vague moment when I started this indicator.
Think my knowledge is ok to chip away at getting the multi line side of things right ...eventually :-)
But your comment about drawing the line every tick, is something that has caused me problems in the past
I would like to read up and learn more about this.
Is there a section of the documentation or an article, you could point me to, that explains a bit more, maybe even has examples of constructing indicators to only update at specified intervals
Is this the same as stopping an indicator from repainting?
Thanks!!!!
Thanks Raptor, I was having a vague moment when I started this indicator.
Think my knowledge is ok to chip away at getting the multi line side of things right ...eventually :-)
But your comment about drawing the line every tick, is something that has caused me problems in the past
I would like to read up and learn more about this.
Is there a section of the documentation or an article, you could point me to, that explains a bit more, maybe even has examples of constructing indicators to only update at specified intervals
Is this the same as stopping an indicator from repainting?
Here's your loop with a few changes, but you still have to address whether you want it calculating every tick or just every bar/hour.
Also you may want to add some code in deinit to delete the objects
int start() // { for (int i=0; i<=Limit; i++) { DaveCloseTime=(iTime(Symbol(),PERIOD_D1,i)+DaveCloseHour*60*60+DaveCloseMin*60); //-----Draw DaveCloseLine"); //-- if (DaveCloseLine) // draw if true { string objectname = "DaveCloseLine"+i; if (ObjectFind (objectname) == -1) ObjectCreate (objectname, OBJ_VLINE, 0, DaveCloseTime, 0); ObjectSet (objectname, OBJPROP_COLOR, Blue); ObjectSet (objectname, OBJPROP_WIDTH, 3); } //-- Draw Box Label ----------------------------------------- if (DaveCloseLine_label) // draw if true { objectname = "DaveCloseLine_label"+i; if (ObjectFind (objectname) == -1) ObjectCreate (objectname, OBJ_TEXT, 0, 0, 0); ObjectSet (objectname, OBJPROP_TIME1,DaveCloseTime ); ObjectSet (objectname, OBJPROP_PRICE1, (Ask+2*Point) ); ObjectSet (objectname, OBJPROP_COLOR, Black); ObjectSetText(objectname, "10:30AM:", font_size, "Arial", Black); } } //---- return(0); } //+------------------------------------------------------------------+
It's different from repainting . . . you can move the lines every tick it's just that there is no need, you have an x hour offset from midnight so there is nothing to be gained from creating/moving the lines more frequently than once per hour. So all you need to do is determine when a new H1 bar has started and then draw/move your lines. Use iTime(NULL, PERIOD_H1, 1) and when this value changes you have a new H1 bar . . . while it is the same simply return(0) from start()
Thanks Raptor and GumRai.
Am almost there with this, the indicator now works as I need, or as I want it to appear on the chart.
But as I try to incorporate your suggestion Raptor ( lines 58,59 and 60 of code marked below is my attempt), I lose all but the 1st object line.
I can't seen to get the loop right (the position of lines 58-60 such that the specified number of lines draw, before the updating code stops it from redrawing.
Perhaps I have misinterpreted this....
Would you mind pointing out the error.
GumRai's suggestion helped me with the object names etc, many thanks!!
//+------------------------------------------------------------------+ //| | //| Copyright © 1999-2008, MetaQuotes Software Corp. | //| http://www.metaquotes.ru | //+------------------------------------------------------------------+ //---- indicator settings #property indicator_chart_window #property indicator_buffers 0 //---- //---- indicator parameters extern int DaveCloseHour = 5; extern int DaveCloseMin = 30; extern int Limit = 50; extern int font_size = 8; // sets font size extern string help1 = "set to true to show vertical line"; extern bool DaveCloseLine = true; // set true to display vertical lines extern string help2 = "set to true to show vertical line time"; extern bool DaveCloseLine_label = true; // set true to display label, time of vertical line double DaveCloseTime; datetime Bar1Time; // used to check if the curen tick is for a new bar //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorShortName("DaveCloseLine"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { for (int i=0; i<=Limit; i++) { ObjectDelete("DaveCloseLine"+i); ObjectDelete("DaveCloseLine_label"+i); } return(0); } //+------------------------------------------------------------------+ //| Other timeframe line levels | //+------------------------------------------------------------------+ int start() // { for (int i=0; i<=Limit; i++) { //-58- Comment("") Only update the objects if they need updating //-59- if( iTime(NULL, PERIOD_H1, 1) == Bar1Time) return(0); //-60- Bar1Time = iTime(NULL,PERIOD_H1,1); DaveCloseTime=(iTime(Symbol(),PERIOD_D1,i)+DaveCloseHour*60*60+DaveCloseMin*60); //-----Draw DaveCloseLine"); //-- if (DaveCloseLine) // draw if true { string objectname = "DaveCloseLine"+i; if (ObjectFind (objectname) == -1) ObjectCreate (objectname, OBJ_VLINE, 0, DaveCloseTime, 0); ObjectSet (objectname, OBJPROP_COLOR, Blue); ObjectSet (objectname, OBJPROP_WIDTH, 3); } //-- Draw Box Label ----------------------------------------- if (DaveCloseLine_label) // draw if true { objectname = "DaveCloseLine_label"+i; if (ObjectFind (objectname) == -1) ObjectCreate (objectname, OBJ_TEXT, 0, 0, 0); ObjectSet (objectname, OBJPROP_TIME1,DaveCloseTime ); ObjectSet (objectname, OBJPROP_PRICE1, (Ask+2*Point) ); ObjectSet (objectname, OBJPROP_COLOR, Black); ObjectSetText(objectname, "10:30AM:", font_size, "Arial", Black); } } //---- return(0); } //+------------------------------------------------------------------+
Thanks Raptor and GumRai.
Am almost there with this, the indicator now works as I need, or as I want it to appear on the chart.
But as I try to incorporate your suggestion Raptor ( lines 58,59 and 60 of code marked below is my attempt), I lose all but the 1st object line.
I can't seen to get the loop right (the position of lines 58-60 such that the specified number of lines draw, before the updating code stops it from redrawing.
Why do you have those lines within the loop ? answer that and you will know what to do . . .
thanks so obvious when you take a step back, Thanks !!!!!!!!!!!!!!!!!!!
It now works
//+------------------------------------------------------------------+ //| | //| Copyright © 1999-2008, MetaQuotes Software Corp. | //| http://www.metaquotes.ru | //+------------------------------------------------------------------+ //---- indicator settings #property indicator_chart_window #property indicator_buffers 0 //---- //---- indicator parameters extern int DaveCloseHour = 5; extern int DaveCloseMin = 30; extern int Limit = 50; extern int font_size = 8; // sets font size extern string help1 = "set to true to show vertical line"; extern bool DaveCloseLine = true; // set true to display vertical lines extern string help2 = "set to true to show vertical line time"; extern bool DaveCloseLine_label = true; // set true to display label, time of vertical line double DaveCloseTime; datetime Bar1Time; // used to check if the curen tick is for a new bar //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorShortName("DaveCloseLine"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { for (int i=0; i<=Limit; i++) { ObjectDelete("DaveCloseLine"+i); ObjectDelete("DaveCloseLine_label"+i); } return(0); } //+------------------------------------------------------------------+ //| Other timeframe line levels | //+------------------------------------------------------------------+ int start() // { //-- Comment("") Only update the objects if they need updating if( iTime(NULL, PERIOD_H1, 1) == Bar1Time) return(0); Bar1Time = iTime(NULL,PERIOD_H1,1); { for (int i=0; i<=Limit; i++) { DaveCloseTime=(iTime(Symbol(),PERIOD_D1,i)+DaveCloseHour*60*60+DaveCloseMin*60); //-----Draw DaveCloseLine"); //-- if (DaveCloseLine) // draw if true { string objectname = "DaveCloseLine"+i; if (ObjectFind (objectname) == -1) ObjectCreate (objectname, OBJ_VLINE, 0, DaveCloseTime, 0); ObjectSet (objectname, OBJPROP_COLOR, Blue); ObjectSet (objectname, OBJPROP_WIDTH, 3); } //-- Draw Box Label ----------------------------------------- if (DaveCloseLine_label) // draw if true { objectname = "DaveCloseLine_label"+i; if (ObjectFind (objectname) == -1) ObjectCreate (objectname, OBJ_TEXT, 0, 0, 0); ObjectSet (objectname, OBJPROP_TIME1,DaveCloseTime ); ObjectSet (objectname, OBJPROP_PRICE1, (Ask+2*Point) ); ObjectSet (objectname, OBJPROP_COLOR, Black); ObjectSetText(objectname, "10:30AM:", font_size, "Arial", Black); } } } //---- return(0); } //+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello Forum
I have tried to make an indicator which simply puts a vertical line on my chart at the same time every day
I have got the indicator to draw a line at the right time, but the line is not repeating or visible on different time frames, and is only drawn once, not each day as I desired.
I assume the error is in my ObjectSet, but not really sure
Would someone mind helping me fix this error
Thanks Always!