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.

Which OptInputDescription for OptInputParInfo.Type.CURRENCY?
 Post subject: Which OptInputDescription for OptInputParInfo.Type.CURRENCY? Post rating: 0   New post Posted: Fri 12 Mar, 2010, 15:14 

User rating: -
Hi, I want to use OptInputParInfo.Type.CURRENCY in my custom indicator. But I can't compile it because I don't know which OptInputDescription has to be assigned. There are only these description types
DoubleListDescription, DoubleRangeDescription, IntegerListDescription, IntegerRangeDescription

so which of them shall I use to solve my problem?

thanks


 
 Post subject: Re: Which OptInputDescription for OptInputParInfo.Type.CURRENCY? Post rating: 0   New post Posted: Tue 06 Apr, 2010, 14:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
to pass currency as optional parameter don't use OptInputParInfo.Type.CURRENCY.
Bellow is sample with modified "ENTROPY" indicator, which demonstrates how to pass an enum to the indicator.
Please consider this sample:
    
            .    .    .
public void onStart(IIndicatorContext context) {
        indicatorInfo = new IndicatorInfo("ENTROPY", "Calculates entropy number", "My indicators",
                false, false, false, 1, 2, 1);
        inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Input data", InputParameterInfo.Type.DOUBLE)};
       
        int[] vals = new int[Currency.values().length];
        String[] valNames = new String[Currency.values().length];
        int i = 0;

        //prepare arrays to define currency's list
        for (Currency cur : Currency.values()){
           vals[i] = cur.ordinal();
           valNames[i] = cur.name();
           i++;
        }
       
        optInputParameterInfos = new OptInputParameterInfo[]
                     {new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(2, 2, 100, 1)),
                      //use OptInputParameterInfo type OTHER
                      new OptInputParameterInfo("Currency", OptInputParameterInfo.Type.OTHER, new IntegerListDescription(1,  vals, valNames))
                     };
        outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("out", OutputParameterInfo.Type.DOUBLE,
                OutputParameterInfo.DrawingStyle.LINE)};
    }
            .    .    .
    public void setOptInputParameter(int index, Object value) {
       if (index == 1){
          for (Currency cur : Currency.values()){
             if(cur.ordinal() == (Integer)value)
                                //verify that an indicator have correct value
                System.out.println(" cur: "+cur.name());                
          }
                    
       }
        timePeriod = (Integer) value;
       
    }

And here is, how you can call it from strategy
context.getIndicators().calculateIndicator(instrument,                         
                period,
                new OfferSide[] {OfferSide.BID},
                "ENTROPY",
                new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
                new Object[]{1, Currency.USD.ordinal()},               
                 1);

If you still have question, please do not hesitate to ask.


Attachments:
Entropy.java [4.45 KiB]
Downloaded 552 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

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