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.

JFOREX-3666 change the parameters of the ind from the strategy?
 Post subject: JFOREX-3666 change the parameters of the ind from the strategy? Post rating: 0   Post Posted: Thu 29 Mar, 2012, 09:06 

User rating: 3
Joined: Thu 28 Jul, 2011, 19:40
Posts: 72
Location: PolandPoland
I would like to change the parameters of indicator from strategy, so that the indicator was draw with the specified parameters on the chart.
I wrote the code below and it seems that it should work correctly:

package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.indicators.*;

public class SetOptInputParametersSamlpe implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
   

    @Configurable("Instrument:") public Instrument instrumentThis = Instrument.EURUSD;
    @Configurable(value="Period:") public Period periodThis = Period.TEN_SECS;
   
    int SMAPeriod = 10;
   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
         if(instrument == instrumentThis && period==periodThis){
            SMAPeriod++;
            if(SMAPeriod >300) SMAPeriod=10;
            IChart chart = context.getChart(instrument);
            if (chart != null){
                java.util.List<IIndicator> ind = chart.getIndicators();
                for(IIndicator i : ind){
                    console.getOut().println(i.getIndicatorInfo().getName() );
                    if(i.getIndicatorInfo().getName().equals("SMA")){
                        i.setOptInputParameter(0, SMAPeriod);
                        console.getOut().println("Set SMAPeriod: "+ SMAPeriod);
                    }
                }
            }
        }
    }
}


but I get an indicator error:
Quote:
07:54:42 Error in indicator: java.lang.ArrayIndexOutOfBoundsException: 1 @ com.dukascopy.api.impl.ct.calculate(Unknown Source)

or
Quote:
08:02:39 Error in indicator: calculate() method of indicator [SMA] returned less values than expected. Requested from-to [0]-[29], input array size [30], returned first calculated index [0], number of calculated values [0], lookback [29], lookforward [0], expected number of elements is [1]


Please help...


Attachments:
SetOptInputParametersSamlpe.java [1.86 KiB]
Downloaded 269 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.
 
 Post subject: Re: How to change the parameters of the indicator from the strategy? Post rating: 0   Post Posted: Thu 29 Mar, 2012, 10:31 
User avatar

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


 
 Post subject: Re: How to change the parameters of the indicator from the strategy? Post rating: 0   Post Posted: Thu 29 Mar, 2012, 11:23 

User rating: 3
Joined: Thu 28 Jul, 2011, 19:40
Posts: 72
Location: PolandPoland
Thanks you for this example. But this is adding new indicator to the chart and it work fine.
But I would like only to change optional parameter in existing indicator on the chart.

Of course I can always remove old indicator and add new with different optional parameters, but this is not elegant and numerically expensive (I think).

I understand that method setOptInputParameter working incorrect or why my solution is incorrect?

Best regards


 
 Post subject: Re: JFOREX-3666 change the parameters of the ind from the strategy? Post rating: 0   Post Posted: Fri 30 Mar, 2012, 17:07 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
janjjj wrote:
I understand that method setOptInputParameter working incorrect or why my solution is incorrect?
The method that you use is for indicator calculation on a price array, not for adjusting optional parameters of a plotted indicator.


 

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