PDA

View Full Version : General Question about CrossAbove


moflaherty
08-22-2007, 02:13 PM
Hi!

I am new to this and I am trying to understand how the indicators work in code.

If I have a chart open, with an EMA (Close, 13) and an SMA(Close 20), I am trying to programatically determine with they cross with my own indicator (so I have a total of three indicators on the chart.) This is the code I wrote in my custom indicator which does not seem to work:

if (CrossAbove(EMA(Close, 13), SMA(Close, 20), 1))
{
DrawArrowUp("UpArrow", 0, High[0] + TickSize, Color.LimeGreen);
}

So when your indicators cross, my code does not seem to place the arrow anywhere close to where your indicators show the crossover. Which of these arguments do I have wrong and do not understand?

Thanks so much!
Michael

NinjaTrader_Ray
08-22-2007, 02:22 PM
Hi Michael,

Your code will only ever plot 1 arrow and move the arrow on each new occurence of a cross. If you want individual arrows for each cross, change your tag to "UpArrow" + CurrentBar.ToString().

Please try this change and see if it makes a difference.

moflaherty
08-22-2007, 02:32 PM
Hi! Thanks for writing back.

I understand the need for a unique tag; that was not my problem. (I was actually appending a serialized date time to each tag which is obviously overkill compared to your superior example - ha!)

Anyway, this is the new code:

if (CrossAbove(EMA(Close, 13), SMA(Close, 20), 1))
{
DrawArrowUp("UpArrow" + CurrentBar.ToString(), 0, High[0] + TickSize, Color.LimeGreen);
}

I have attached a screenshot of what I am trying to do. I want to catch these crossovers [note: I have not yet written the CrossBelow code; I am trying to get it to work in the one direction.)

Thanks again!

NinjaTrader_Ray
08-22-2007, 02:42 PM
The SMA on the chart has 10 period. Your code has 20 period. That is the source of the discrepancy.

moflaherty
08-22-2007, 02:54 PM
So the problem was between the keyboard and the chair.

Thanks! This drove me nuts.

:p