Hey guys, I'm a newbie here, and please forgive me if I'm asking a silly question. And yes I live in China, I'll try my best to describe my problem in Chinglish.
I tried to set up an indicator like errr...price diversion. My code is like this:
Variables:
double DIFF(0), double DEA(0), double MyMACD(0),MACD_GCross(False),
MACD_DCross(False), int BarsUp(0);
DIFF = XAverage(Close, 12) - XAverage(Close, 26);
DEA = XAverage(DIFF, 9);
MyMACD = 20*(DIFF-DEA); //It was multiplied by 20 for convenience only, actually it should be 2hi
Plot1(DIFF, "DIFF", White);
Plot2(DEA, "DEA", Yellow);
Plot3(MyMACD, !("MyMACD")); //Displayed in histogram
if MyMACD > 0 then
SetPlotColor(3, Red)
else if MyMACD < 0 then
SetPlotColor(3, Cyan);
MACD_GCross = DIFF cross over DEA;
MACD_DCross = DIFF cross under DEA;
BarsUp = MRO(MACD_GCross, 200, 1) + 1; //Calculating the bars since the last time DIFF crossed over DEA, in a 200- bar length
...
So here's the problem. It was verified all OK. But when I add it to my bars chart, the first 200 verticle lines plotted(i.e. MyMACD Variable) was automatically removed from the chart. If I remove the "BarsUp = MRO(MACD_GCross, 200, 1) + 1;" sentence, it was plotted right. Anyone have any idea what's wrong with my code? What should I do if I wanna keep all the lines without removing the MRO function, which I think is a very handy function for newbies like me. I Any help is appreciated.
Thanks for the quick tip, ABCTG. I was googling how to use the Maxbarback and will try to figure it out by myself.
I'd like to bring forward one more question without adding a new thread. On many occasions, when I try to plot some lines for my variables, TS won't allow me to plot from the first bar(i.e. the first in history of a stock). I tried these code:
"Value1=10.01;
Plot1(Value1, "Value1");
And it plotted the value from the SECOND bar, which should be BarNumber 1 I suppose.
I tried "Value 1 = Close;", it also began from the second bar(BarNumber 1). So what's the usual way to reference the REAL first bar, and plot the Values exactly from the beginning?
P.S. Certain functions like MACD also IGNORED the first Bar. The first Bar arguably has no 'previous EMA value', but the code actually presumes the second Bar Price to be the 'previous value' for the third Bar. It used the same method, like many other platforms, except it just IGNORED the first Bar.
I am not sure you can get around this platform behavior. If starting at the very first bar of a session is important you could load one additional session and start your code logic on the first bar of the second session.
Regards,
ABCTG
The following user says Thank You to ABCTG for this post:
Tried to modify the XAverage function. And it works better now. Thought of a way to work around the manner of TS, which means I'll have to write some more code myself. Thanks ABCTG for your help and patience!