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.

Using Alligator indicator with back tests
 Post subject: Using Alligator indicator with back tests Post rating: 0   New post Posted: Mon 29 Apr, 2019, 14:28 

User rating: 0
Joined: Mon 18 Mar, 2019, 15:06
Posts: 4
Location: AustraliaAustralia
I am running a back test that is showing an hourly AUD/USD chart. I have added an alligator indicator to this chart using the following code:

    @Override
    public void onStart(IContext context) throws JFException
    {
        super.onStart(context);
        ...
        IChart chart = context.getChart(instrument);
        chart.add(context.getIndicators().getIndicator("ALLIGATOR"),
                       new Object[] { 13, 8, 5 },
                       new Color[] { Color.blue, Color.red, Color.green },
                       new DrawingStyle[] {DrawingStyle.LINE, DrawingStyle.LINE, DrawingStyle.LINE },
                       new int[] { 1, 1, 1} );
        ...


This works fine except that the price property for the indicator is set to Median Price (HL/2). First question, how do I set it to Close? I have manually changed it for this example.

Now to the main problem. When I process a new bar, I use the following code to retrieve the indicator values:

        double[][] alligatorValues = indicators.alligator(feed, AppliedPrice.CLOSE, OfferSide.BID, 13, 8, 5).calculate(2, time, 0);


where time is the bid bar time value. In the calculate call I have used 2 for the bars before parameter because the value 1 doesn't give me the data I need. However, 2 doesn't help me either. This is what the last few bars on the chart look like:

Image

Here is the data from the calculate indicator call:

Image

Notice that the second values in each of the array items of the alligatorValues results are displayed on the right of the chart where the indicator has extended the line to, but when I hover over the line above the bar, it is a different value. The value above the bar is what I need to use, but I can't seem to get this using the calculate call. Could you please help me get the correct values, thanks.


 
 Post subject: Re: Using Alligator indicator with back tests Post rating: 0   New post Posted: Wed 08 May, 2019, 13:34 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The balance lines are designated as the jaw, the teeth, and the lips of the alligator and are as follows:

Alligator's jaw — this is the slowest moving average of the three, and is marked blue. It is a 13-period moving average, shifted forward by 8 bars
Alligator's teeth — red, this is the intermediate moving average of the three, smoothed over 8 periods, and shifted 5 bars forward
Alligator's lips — shown as a green line and calculated as a 5-period moving average that is then shifted 3 bars forward


So, in your example alligator values on selected bar belong not to the current bar, but for old bars shifted to the left(8 bars left for jaws, 5 bars for teeth and 3 bars for lips).
At the same time calculate() method returns actual indicator data shifted to the right.
If you want to synchronize values on chart with calculate() output - need set 0 shift in indicator settings.

Image


Attachments:
alligator_indicator.JPG [39.43 KiB]
Downloaded 204 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: Using Alligator indicator with back tests Post rating: 0   New post Posted: Thu 16 May, 2019, 13:19 

User rating: 0
Joined: Mon 18 Mar, 2019, 15:06
Posts: 4
Location: AustraliaAustralia
Thanks for that. It works. However, this means I manually have to edit the indicator on the chart when I run the back test. How can I set additional parameters via the previous code, i.e. the Price parameter to Close (it defaults to Median price (HL/2)), and the output shift values to 0 (defaults are 8, 5 and 3).


 
The Best Answer  Post subject: Re: Using Alligator indicator with back tests Post rating: 0   New post Posted: Thu 16 May, 2019, 14:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Option 1(from strategy):
        IChart chart = context.getChart(instrument);
        IIndicator alligator = indicators.getIndicator("ALLIGATOR");
       
        InputParameterInfo inputParameterInfo = alligator.getInputParameterInfo(0);
        inputParameterInfo.setAppliedPrice(IIndicators.AppliedPrice.CLOSE);

        OutputParameterInfo jawOutputParameterInfo = alligator.getOutputParameterInfo(0);
        jawOutputParameterInfo.setShift(0);

        OutputParameterInfo teethOutputParameterInfo = alligator.getOutputParameterInfo(1);
        teethOutputParameterInfo.setShift(0);

        OutputParameterInfo lipsOutputParameterInfo = alligator.getOutputParameterInfo(2);
        lipsOutputParameterInfo.setShift(0);

        chart.add(alligator,
                new Object[] { 13, 8, 5 },
                new Color[] { Color.blue, Color.red, Color.green },
                new DrawingStyle[] {DrawingStyle.LINE, DrawingStyle.LINE, DrawingStyle.LINE },
                new int[] { 1, 1, 1}
                );


Option 2(via chart template feature):

1)Save chart with all indicator settings by right click on it in Navigator - Save Template
2)Then in Historical Tester : Custom Settings - Chart Template - Open Template


 

Jump to:  

  © 1998-2024 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