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.

How to show an indicator in the Chart
 Post subject: How to show an indicator in the Chart Post rating: 0   New post Posted: Tue 15 Feb, 2011, 18:23 

User rating: 0
Joined: Tue 15 Feb, 2011, 18:09
Posts: 1
I would like to show an SMA indicator in the chart in JForex.
Could you please provide some sample code?
I could not find any sample in the forum or in the documentation.

I tried the following, but it does not work:

public void onStart(final IContext context) throws JFException {
indicators = context.getIndicators();
final IIndicator indicator = indicators.getIndicator("sma");
final IndicatorInfo indicatorInfo = indicator.getIndicatorInfo();
indicatorInfo.setOverChart(true);
final IIndicators.AppliedPrice medianPrice = IIndicators.AppliedPrice.MEDIAN_PRICE;
chart.addIndicator(indicator, new Object[]{INSTRUMENT, period, OfferSide.BID, medianPrice, 3, 0});
}

I get the following error:
16:31:39 Unexpected optional parameter [com.dukascopy.api.Instrument]=[GBP/JPY] for index [0]

Unfortunately JForex is closed source so I can not have a look at the code to see what the API wants me to do.
The documentation is insufficient at this point.


 
 Post subject: Re: How to show an indicator in the Chart Post rating: 0   New post Posted: Fri 10 Jun, 2011, 09:02 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
In SMA case there is one optional parameter - time period, so you add SMA indicator with optional input parameters in the following way:
int smaPeriod = 30;
chart.addIndicator(indicator, new Object[] { smaPeriod})
In general case you can check optional input parameters of an indicator by doing the following:
print("count: " + indicatorInfo.getNumberOfOptionalInputs());
for (int i = 0; i < indicatorInfo.getNumberOfOptionalInputs(); i++){
   print( i + ": name = '"+ indicator.getOptInputParameterInfo(i).getName()  + "' type = "+ indicator.getOptInputParameterInfo(i).getType());
}


 

Jump to:  

  © 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