PDA

View Full Version : Unexpected results from script


suedeuno
02-16-2009, 05:50 PM
I set up a DrawPoint when CrossAbove(macd.Diff, 0, 20) is true.
I'm getting plots where the Diff isn't above 0.

I have set up : MACD macd = MACD(Close, 6, 12, 9);

I added the standard MACD 6,12,9 indicator to check results

Newshues
02-16-2009, 07:05 PM
CrossAbove(IDataSeries series1, double value, int lookBackPeriod)

CrossAbove(macd.Diff, 0, 20) is true

Did you intend for the statement to evaluate to true if the macd.diff was above 0 at any time in the last 20 bars?

If you're looking for a marker on the bar that it crosses 0 on then you want the look back period to 1 I believe, possibly 0, I'd have to check.

suedeuno
02-16-2009, 08:38 PM
I intended to check for a cross of the diff over 0 over the past 20 bars, and if so draw a dot.

NinjaTrader_Bertrand
02-17-2009, 04:38 AM
if (CrossAbove(MACD(12,26,9).Diff, 0, 20))
DrawDot("myDot" + CurrentBar, false, 0, Low[0] - 1 * TickSize, Color.Blue);


Then this code is correct, but you have to consider it will then of course also draw a dot if the current diff is < 0 because the diff 15 bars back might still be > 0.

For a dot on a cross of the 0 try this -


if (CrossAbove(MACD(12,26,9).Diff, 0, 1))
DrawDot("myDot" + CurrentBar, false, 0, Low[0] - 1 * TickSize, Color.Blue);