Strategy and Chart indicator issue

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Strategy and Chart indicator issue

Postby MrRiversideDude » Fri Feb 21, 2014 8:02 am

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.
MrRiversideDude
 
Posts: 87
Joined: Fri Feb 21, 2014 7:50 am

Re: Strategy and Chart indicator issue

Postby moomoofx » Fri Feb 21, 2014 6:57 pm

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.
User avatar
moomoofx
FXCodeBase: Confirmed User
 
Posts: 193
Joined: Wed Oct 23, 2013 10:26 pm
Location: Okinawa, Japan. http://moomooforex.com

Re: Strategy and Chart indicator issue

Postby MrRiversideDude » Sat Feb 22, 2014 3:47 am

Thank you very much, I'll give it a try.
MrRiversideDude
 
Posts: 87
Joined: Fri Feb 21, 2014 7:50 am


Return to Discussions

Who is online

Users browsing this forum: No registered users and 2 guests