Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

difference in SMA implementation
 Post subject: difference in SMA implementation Post rating: 0   Post Posted: Mon 10 Dec, 2012, 10:26 

User rating: 0
Joined: Mon 10 Dec, 2012, 10:12
Posts: 1
Location: GermanyGermany
Hello,
I am new here and maybe my questions is stupid but I have not founded the answer and would like to ask community.
I am trying to use SMA and would like to get predictable result.
The values of the SMA in code are different from the visual graph. Maybe I use SMA in code not right. Please help me with it. I would like to get the same result from code and from visual graph. Also I tryed to implement it by myself.

public Instrument instrument = Instrument.EURUSD;
public Period selectedPeriod = Period.FOUR_HOURS;
//....
//-------- 1 use standart implementation
IBar prevBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, 1);
double sma = indicators.sma(instrument, selectedPeriod, OfferSide.BID, AppliedPrice.CLOSE, 15, indicatorFilter, 1,  prevBar.getTime(), 0)[1];
//....
//-------- 2 use own implementation
Double smaOpen = 0.0;
Double smaClose = 0.0;
for(int i = 1; i <= 15; i++ ){
  IBar bar = history.getBar(instrument, selectedPeriod, OfferSide.BID, i);
  smaOpen += bar.getOpen();
  smaClose += bar.getClose();
}
smaOpen = smaOpen / 15;
smaClose = smaClose / 15;
console.getOut().println("SMA = " + smaClose);

Could me explain where is my error? Thank you in advance


 
 Post subject: Re: difference in SMA implementation Post rating: 1   Post Posted: Mon 10 Dec, 2012, 10:30 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#Indicator_usage_checklist


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com