Normally, I have no issues with Cross function. However, this code snippet is producing a result where my shapes (arrows) seem to be offset and late 1 bar. Shifting plotshape offset by -1 makes things worse. Am I doing something wrong? (Arrows should appear at crossover points).
Here is the code:
//Vortex Indicator Positive (VortexUp) and Negative (VortexDn) omputations.
VMP = Sum( abs( H - Ref( L, -1 ) ), 14 );
VMM = Sum( abs( L - Ref( H, -1 ) ), 14 );
STR = Sum( ATR( 1 ), 14 );
VortexUp = VMP / STR;
VortexDown = VMM / STR;
Plot(VortexUp, "+VI Vortex Up",colorGreen, styleline);
Plot(VortexDown, "-VI Vortex Dn", colorRed, styleline);
UpSignalVTI = Cross(VortexUp, VortexDown);
DownSignalVTI = Cross(VortexDown, VortexUp);
Shape = (UpSignalVTI * shapeUpArrow) + (DownSignalVTI * shapeDownArrow);
PlotShapes(shape,IIf(UpSignalVTI,colorGreen, colorRed), 0, IIf(UpSignalVTI,UpSignalVTI,DownSignalVTI), -25, 0);
@SwingTradeMonkey if you Plot the values of the indicator you will see the arrows are properly placed (at least on my charts) . It is on the Close of the bar that the indicator is calculated and that is when the Cross has occurred.
If you go back one bar, the cross has not yet taken place as you can see by the values.
And the slight change I made to your code (as it was coded by Tomasz http://www.amibroker.com/members/traders/01-2010.html),
Plot( VortexUp, "VI"+period+"+", colorBlue, styleThick);
Plot( VortexDown, "VI"+period+"-", colorRed, styleThick );
@portfoliobuilder So it would appear that the arrows are correctly positioned, however the line drawings are not. Am I correct?
@SwingTradeMonkey I think the lines just appear to "jump" because you are drawing a continuous line between two data points that are not connected by any other data points.
Are you kidding?
I mean if you have two lines moving different ways and one moves up and one moves down then surprise surprise… they will cross at certain coordinates. And if there is no bar index there then what is supposed to be wrong about that fact that there is no bar index there at lines cross? Do you want to invent new bar indexes just so that you have an extra funky monkey bar index at cross of lines? Think man, think what cross means!
Sometimes Internet is really “funny”.
@portfoliobuilder is 100% correct. Under a maximum magnification, I can see the crossover does occur between bars. So the arrows are positioned on the next available bar where an action (e.g. buy) can take place.
The Thinkorswim platform plots this indicators arrows in the same manor, showing some crossovers happening between days. I wonder if there is anything we can or, for that matter, should do to the formula to synchronize the crossovers to plot so they show “on the bars” rather than between bars!
Thanks to this forum, I am learning something new every day!
I also feel good about building this forum for future visitors. Thanks Again!
--> You are going for a record. Currently only Tomasz is better than you in creating new threads ...
A new thread, in most cases, means new issues to be solved or help to be provided by other members. I would say those who offer their time and knowledge for free and help others, might have slightly more input into building the forum than those who ask
Without Good Questions, there would not be any Good Answers!!! And I am certainly getting many good answers!
I hope that many others, in the near future will gain valuable insight from the answers we provide on this platform.
While I do review and try to provide answers to other’s questions where possible, I hope that one day I will be answering far more questions than I am asking!
Again, thanks EVERYONE for the valuable input. The time everyone puts into this forum is very much appreciated and, in my case, is being put to use in real time!
THANK YOU… THANK YOU… THANK YOU!!!
I wonder if there is anything we can or, for that matter, should do to the formula to synchronize the crossovers to plot so they show “on the bars” rather than between bars!
I meant to post this on my last post a few hours ago. If it helps you with the concept you can plot your indicators as discrete data points with no lines. Most people I think prefer looking at lines for many indicators but you just need to remember that the lines are "imaginary" between data points. The lines are really just "connecting the dots".