Page 1 of 1

Strategy and Chart indicator issue

PostPosted: Fri Feb 21, 2014 8:02 am
by MrRiversideDude
Hi,

I have created 2 MAs, 1 EMA and 1 MVA, in a strategy and I signal when price crosses the faster MA. Whenever I check the values of each MA after the crossover, the value given to me by the strategy is different from what I see on the chart. Is there a way to make them exactly the same? I created the chart indicator to match the ones in the strategy.

Code snippets:
MA = core.indicators:create("EMA", Source.close, instance.parameters.Fast);
SLOW = core.indicators:create("MVA", Source.close, instance.parameters.Slow);

MA:update(core.UpdateLast);
SLOW:update(core.UpdateLast);

if MA.DATA[period] > SLOW.DATA[period]
then
Alert("10 MA > 200 MA FAST: ", MA.DATA[period] , period);
Alert("10 MA > 200 MA SLOW: ", SLOW.DATA[period] , period);
end

Thanks in advance.

Re: Strategy and Chart indicator issue

PostPosted: Fri Feb 21, 2014 6:57 pm
by moomoofx
Yeah this one catches me out too sometimes.

Assuming you are using the ExtSubscribe and ExtUpdate functions to access your prices, ExtUpdate only updates when the bar closes.

So let's say Bar 1 closes, and runs ExtUpdate for period 1. You're code will run and go - ooh, a cross! - and then trigger an alert.

However, as far as time is concerned, your alert has happened after the bar closed, so alerts will always be the next bar. If you check the price at the bar you see the alert, it will always be one behind.

The best way to check what the value is at the time of the alert is use the core.host:trace() function and log the values when you are triggering the alert.

Re: Strategy and Chart indicator issue

PostPosted: Sat Feb 22, 2014 3:47 am
by MrRiversideDude
Thank you very much, I'll give it a try.