View Full Version : Print Triangle at MA Crossover
cutter
09-14-2007, 04:48 AM
Hi.
I've set up two moving averages of pivot points at 3 bars and 5 bars. When they crossover, I'd like to print a triangle (red for when the shorter ma crosses below the longer ma, green for when the shorter crosses above the longer).
I haven't seen anything on this in the Ninjascript tutorials and haven't yet found anything similar in the forum, but still looking ....
If anyone can help, it would be much appreciated.
Thanks !
NinjaTrader_Josh
09-14-2007, 10:10 AM
Hi cutter,
Drawing triangles can be done with either the DrawTriangleUp() (http://www.ninjatrader-support.com/HelpGuideV6/DrawTriangleUp.html) or DrawTriangleDown() (http://www.ninjatrader-support.com/HelpGuideV6/DrawTriangleDown.html) method.
if (CrossAbove(SMA(5), SMA(20), 1))
{
DrawTriangleUp("Fast-x-Slow", 0, Low[0] - 2 * TickSize, Color.Green);
}
There will be some reference samples up for draw methods up shortly. In the meantime you can view the help file for more draw methods you can use. Go to the index and look into the D section.
cutter
09-14-2007, 03:12 PM
Josh, thank you much !
cutter
09-17-2007, 09:10 AM
Hi. I have this working, thank you !
Right now, it only prints a triangle on the most recent crossover. Once a new crossover occurs, the previous crossover marker drops off.
I would like to have the crossover markers be persistent, meaning to display anywhere in chart history where there is a crossover, not just the most recent one. Can you offer any guidance for this?
Thanks much !
NinjaTrader_Ray
09-17-2007, 09:13 AM
Make the tag name unique.
For example:
DrawTriangleUp("Fast-x-Slow" + CurrentBar, 0, Low[0] - 2 * TickSize, Color.Green);
cutter
09-17-2007, 11:11 AM
Ray, this worked for me, thanks !
cutter
09-17-2007, 11:47 AM
ok, a minor glitch ....
if the ma's cross while a bar is in the middle of printing, the crossover marker appears (which is good) .... but while still mid-bar, if the ma's move back apart, the crossover marker remains, even if the bars closes without an ma crossover.
how can I make the crossover marker go away if the crossover does not hold?
(if i remove and then reapply the indicator, the spurious markers do not come back)
thanks !
NinjaTrader_Ray
09-17-2007, 11:55 AM
Run your indicator with CalculateOnBarClose set to true or if you want it to update tick by tick, you wil need to add some code to remove the draw object.
http://www.ninjatrader-support.com/HelpGuideV6/RemoveDrawObject.html
cutter
09-17-2007, 02:14 PM
Thank you Ray, will give it a shot and post results.
benitecs
05-30-2009, 03:45 AM
Hi.
I've set up two moving averages of pivot points at 3 bars and 5 bars.
Hello!
Could You kindly explain how to set up moving averages of pivot points at 3 bars and 5 bars ? (or could You share Your indicator code)
Kindly regards.