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.

Multiple Periods in Indicator do not work
 Post subject: Multiple Periods in Indicator do not work Post rating: 0   New post Posted: Tue 02 Aug, 2011, 09:43 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
We are having problems to get an indicator working that is loading 4 IBar input parameters using 2 periods.

Here is what we do:

    public void onStart(IIndicatorContext _context) {
        context = _context;
        console = _context.getConsole();

        InputParameterInfo inputASK = new InputParameterInfo("PriceASK", InputParameterInfo.Type.BAR);
        inputASK.setOfferSide(OfferSide.ASK);

        InputParameterInfo inputBID = new InputParameterInfo("PriceBID", InputParameterInfo.Type.BAR);
        inputBID.setOfferSide(OfferSide.BID);
       
        InputParameterInfo inputASKHelper = new InputParameterInfo("PriceASKHelper", InputParameterInfo.Type.BAR);
        inputASKHelper.setOfferSide(OfferSide.ASK);
        inputASKHelper.setPeriod(Period.ONE_MIN);

        InputParameterInfo inputBIDHelper = new InputParameterInfo("PriceBIDHelper", InputParameterInfo.Type.BAR);
        inputBIDHelper.setOfferSide(OfferSide.BID);
        inputBIDHelper.setPeriod(Period.ONE_MIN);
             
        indicatorInfo = new IndicatorInfo("MultiPeriodsTest", "MultiPeriodsTest", "TEST", false, false, true, 4, 0, 3);
        inputParameterInfos = new InputParameterInfo[] {
                inputASK, inputBID, inputASKHelper, inputBIDHelper
        };
       
        outputParameterInfos = new OutputParameterInfo[] {
            new OutputParameterInfo("Out1", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
                {{
                     setColor(Color.GREEN);
                     //setColor2(Color.DARKGREEN);
                }},
            new OutputParameterInfo("Out2", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
                {{
                     setColor(Color.RED);
                     //setColor2(Color.DARKRED);
                }},
            new OutputParameterInfo("Out3", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
                {{
                     setColor(Color.BLUE);
                     //setColor2(Color.DARKBLUE);
                }}
        };
    }
.....
    public IndicatorResult calculate(int startIndex, int endIndex) {
           console.getOut().println("calculate called!");

           //... calculate logic follows here...
    }
.....


In the above example, as you can see, we load the ASK and BID bars of the currently selected timeframe and in addition the ASK and BID bars of a preset HELPER-timeframe (here ONE_MIN).

With this setup we experience the following indicator behaviour:
A) When the current timeframe in the chart is set to the HELPER-timeframe, calculate(int startIndex, int endIndex) is called and the code is executed as intended and the log-message "calculate called!" triggered at the start of the method is written to the output. (in this example when selected timeframe on chart is ONE_MIN)

B) When the current timeframe in the chart is set to something other than the HELPER-timeframe (example: FIVE_MINS), the calculate-code is not called anymore.

Best,
RR.


 
 Post subject: Re: Multiple Periods in Indicator do not work Post rating: 0   New post Posted: Wed 03 Aug, 2011, 08:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
RoadRunner wrote:
B) When the current timeframe in the chart is set to something other than the HELPER-timeframe (example: FIVE_MINS), the calculate-code is not called anymore.
This is a constraint set during indicator validation. See the first paragraph in https://www.dukascopy.com/wiki/index.php ... nt_periods. If you need to work with smaller period bars than the ones on the chart, you can consider retrieving bars from history context.getHistory(), although in this way you can not retrieve the bar that is currently being formed.


 
 Post subject: Re: Multiple Periods in Indicator do not work Post rating: 0   New post Posted: Wed 03 Aug, 2011, 09:15 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
You've made my day! ;) :)

I somehow didn't perceive IHistory can get accessed from within the indicator...
That's making things a lot easier.

Thanks & best, RR.


 

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