Play videoPlease edit your post.
For large amounts of code, attach it.
int init(){ limit=Bars; } int start(){ int counted_bars=IndicatorCounted(); for(shift=limit; shift>=0; shift--) ...
Why are you calling IndicatorCounted() when you're not using the value? Why are you reprocessing all bars (up to the original bar count?) Do it right.int start(){ int counted_bars=IndicatorCounted(); // if(counted_bars < LOOKBACK) counted_bars = LOOKBACK; // SMA(x) has look back of x for(shift=Bars - 1 - counted_bars; shift>=0; shift--) ... // Bars is not constant.
ObjectCreate(VertUp,OBJ_VLINE,Window,shift,shift);
RTFM. what is the fourth argument to ObjectCreate and what are you passing?- What are Function return values ? How do I use them ? - MQL4 forum
//+------------------------------------------------------------------+ //| 000shift.mq4 | //| Copyright 2013, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int shift; int limit; extern int Window; extern color ColourUp=Blue,ColourDown=Orange; extern int ScaleVertLineUp=5,ScaleVertLineDown=5; extern int InputOBJPROP_STYLE=0; extern string VertLineUp = "VertLineUp"; extern string VertLineDown = "VertLineDown"; int init() { limit=Bars; return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ //-------------- int start(){ int counted_bars=IndicatorCounted(); // if(counted_bars < LOOKBACK) counted_bars = LOOKBACK; // SMA(x) has look back of x for(shift=Bars - 1 - counted_bars; shift>=0; shift--) { double BarMarker = Time[shift]; string VertUp = VertLineUp + BarMarker; string VertDown = VertLineDown + BarMarker; ObjectCreate(VertUp,OBJ_VLINE,Window,shift,shift);ObjectSet(VertUp,OBJPROP_COLOR,ColourUp); ObjectSet(VertUp,OBJPROP_STYLE,0); } //---- return(0); } //+------------------------------------------------------------------+
Play videoPlease edit your post.
For large amounts of code, attach it.
-
Why are you calling IndicatorCounted() when you're not using the value? Why are you reprocessing all bars (up to the original bar count?) Do it right.
- RTFM. what is the fourth argument to ObjectCreate and what are you passing?
- What are Function return values ? How do I use them ? - MQL4 forum
Thanks a lot WH!
I integrated some of your programming lines.
But the thing I'm looking for, is a simple (initial) procedure, how to simply place a vertical Line (object) on every bar which is displayed. (later I'll use certain conditions where a vertical line should appear, so this is just a preparation)
the objects (vertical lines, I'm getting are numerous, but they seem to be all located on 1970/01/01 (probably the first available date in MT4), so my mistake may be that the positioning of the vertical lines by using the "shift" parameter in "createobject" is wrong? .. or should I use some kinda Time[shift] parameter there?
btw, I solved one part of the issue
for example a line like : ObjectCreate("line",OBJ_VLINE,0,Time[0],0) puts a vertical line at the last bar correctly
but in the context below only 1 vertical line at the last bar appears (which is at shift+1 btw), so the other vertical lines from "Bars" down to/until "shift>=0"
are not there? how to solve this? At the present time, forex is closed,so MT is not receiving any ticks, but I think that "for" condition below should be executed anyway?!
{
double BarMarker = Time[shift+1];
string VertUp = VertLineUp + BarMarker;
string VertDown = VertLineDown + BarMarker;
ObjectCreate(VertUp,OBJ_VLINE,Window,Time[shift+1],0);ObjectSet(VertUp,OBJPROP_COLOR,ColourUp);
ObjectSet(VertUp,OBJPROP_STYLE,0);
} // unfortunately creates only 1 line at the last bar
btw, I solved one part of the issue
for example a line like : ObjectCreate("line",OBJ_VLINE,0,Time[0],0) puts a vertical line at the last bar correctly
but in the context below only 1 vertical line at the last bar appears (which is at shift+1 btw), so the other vertical lines from "Bars" down to/until "shift>=0"
are not there? how to solve this? At the present time, forex is closed,so MT is not receiving any ticks, but I think that "for" condition below should be executed anyway?!
<CODE REMOVED>
You were already asked politely . . .
Please edit your post . . . please use the SRC button to post code: How to use the SRC button.
for(shift=Bars; shift>=0; shift--) { double BarMarker = Time[shift+1]; string VertUp = VertLineUp + BarMarker; string VertDown = VertLineDown + BarMarker; ObjectCreate(VertUp,OBJ_VLINE,Window,Time[shift+1],0);ObjectSet(VertUp,OBJPROP_COLOR,ColourUp); ObjectSet(VertUp,OBJPROP_STYLE,0); }
btw, I solved one part of the issue
for example a line like : ObjectCreate("line",OBJ_VLINE,0,Time[0],0) puts a vertical line at the last bar correctly
but in the code inserted only 1 vertical line at the last bar appears (which is at shift+1 btw), so the other vertical lines from "Bars" down to/until "shift>=0"
are not there? how to solve this? At the present time, forex is closed,so MT is not receiving any ticks, but I think that "for" condition below should be executed anyway?!btw, I solved one part of the issue
for example a line like : ObjectCreate("line",OBJ_VLINE,0,Time[0],0) puts a vertical line at the last bar correctly
but in the code inserted only 1 vertical line at the last bar appears (which is at shift+1 btw), so the other vertical lines from "Bars" down to/until "shift>=0"
are not there? how to solve this? At the present time, forex is closed,so MT is not receiving any ticks, but I think that "for" condition below should be executed anyway?!btw, I solved one part of the issue
for example a line like : ObjectCreate("line",OBJ_VLINE,0,Time[0],0) puts a vertical line at the last bar correctly
but in the code inserted only 1 vertical line at the last bar appears (which is at shift+1 btw), so the other vertical lines from "Bars" down to/until "shift>=0"
are not there? how to solve this? At the present time, forex is closed,so MT is not receiving any ticks, but I think that "for" condition below should be executed anyway?!
- 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,
I'm experimenting with a short code, just to learn how to place objects at different bars in a chart.
I just wanted to place a vertical line at each bar in the chart (later I'm gonna add conditions for where a vertical line should appear)
Now, when I place this "indicator" on a chart, it apparently creates many (not visible) objects with individual names (if you use the show/list objects function),
but they are all placed like on the 1970/01/01 so that there are no vertical lines from the first to the last bar in the chart as intended.
If anyone has an idea how to correct the progr. mistake, I'd be very thankful in advance.
So my (for the experts surely very simple) code is:
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int shift;
int limit;
extern int Window;
extern color ColourUp=Blue,ColourDown=Orange;
extern int ScaleVertLineUp=5,ScaleVertLineDown=5;
extern int InputOBJPROP_STYLE=0;
extern string VertLineUp = "VertLineUp";
extern string VertLineDown = "VertLineDown";
int init()
{ limit=Bars;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
for(shift=limit; shift>=0; shift--)
{
double BarMarker = Time[shift];
string VertUp = VertLineUp + BarMarker;
string VertDown = VertLineDown + BarMarker;
ObjectCreate(VertUp,OBJ_VLINE,Window,shift,shift);ObjectSet(VertUp,OBJPROP_COLOR,ColourUp);
// ObjectSet(VertUp,OBJPROP_STYLE,0}; this line is skipped because a compiling error message
}
//----
return(0);
}
//+------------------------------------------------------------------+