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.

CHANNEL_UP and DOWN indicators
 Post subject: CHANNEL_UP and DOWN indicators Post rating: 0   New post Posted: Thu 28 Oct, 2010, 15:27 

User rating: 0
Joined: Mon 25 Oct, 2010, 21:53
Posts: 3
Hello,

is it possible to access the indicators CHANNEL_UP and CHANNEL_DOWN programmatically from a strategy using indicators.calculateIndicator(), and if yes, what are the output types and their definition?

Thank you.


 
 Post subject: Re: CHANNEL_UP and DOWN indicators Post rating: 0   New post Posted: Wed 03 Nov, 2010, 14:23 

User rating: 0
Joined: Mon 25 Oct, 2010, 21:53
Posts: 3
OK I guess no reply means it's not possible yet.

Thanks


 
 Post subject: Re: CHANNEL_UP and DOWN indicators Post rating: 0   New post Posted: Wed 03 Nov, 2010, 23:21 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
If you mean Price Action Channel indicator
here is source code of my custom:

/**
 * Copyright 2010 LorencSoftware. All rights reserved.
 * LORENCSOFTWARE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package jforex;

import com.dukascopy.api.IBar;
import com.dukascopy.api.indicators.*;
import java.awt.Color;


public class LS_I_PAC implements IIndicator {

    public static final int FALSE = 0;
    public static final int TRUE = 1;

    public static final String name = "LS_I_PAC";
    public static final String group = "LorencSoftware.indicators";

   
   
    private int period;
    private boolean includeCurrentBar;

    private double[][] outputs = new double[2][];
    private IBar[] inputs = null;

    private IndicatorInfo indicatorInfo;
    private InputParameterInfo inputParameterInfo;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;




    public void onStart(IIndicatorContext context) {
        indicatorInfo = new IndicatorInfo(name, name, group, true, false, false, 1, 2, 2);

        inputParameterInfo = new InputParameterInfo("Price chart", InputParameterInfo.Type.BAR);
           
           
        OptInputParameterInfo opt_period = new OptInputParameterInfo("Period",
                OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(5, 1, 100, 1));

        int[] opt_includeCurrentBar_intArray = new int[]{FALSE, TRUE};
        String[] opt_includeCurrentBar_stringArray = new String[]{"false", "true"};
        IntegerListDescription opt_includeCurrentBar_intListDesc =
                new IntegerListDescription(0, opt_includeCurrentBar_intArray, opt_includeCurrentBar_stringArray);
        OptInputParameterInfo opt_includeCurrentBar =
                new OptInputParameterInfo("Include current bar", OptInputParameterInfo.Type.OTHER, opt_includeCurrentBar_intListDesc);

        optInputParameterInfos = new OptInputParameterInfo[2];
        optInputParameterInfos[0] = opt_period;
        optInputParameterInfos[1] = opt_includeCurrentBar;
           
           
        OutputParameterInfo out_highestHigh = new OutputParameterInfo("Highest high",
                OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE);
        out_highestHigh.setColor(Color.GREEN);
        OutputParameterInfo out_lowestLow = new OutputParameterInfo("Lowest low",
                OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE);
        out_lowestLow.setColor(Color.RED);

        outputParameterInfos = new OutputParameterInfo[2];
        outputParameterInfos[0] = out_highestHigh;
        outputParameterInfos[1] = out_lowestLow;
    }








    public IndicatorResult calculate(int startIndex, int endIndex) {
        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }
        int i, j;
        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
            IBar[] data;
            if (includeCurrentBar) {
                data = subArrayOfLastValues(inputs, i, period);
            } else {
                data = subArray(inputs, i-period, (i-1));
            }
            double highestHigh = Double.MIN_VALUE;
            double lowestLow = Double.MAX_VALUE;
            for (int ii = 0; ii<data.length; ii++) {
                IBar bar = data[ii];
                if (bar.getHigh()>highestHigh) { highestHigh = bar.getHigh(); }
                if (bar.getLow()<lowestLow) { lowestLow = bar.getLow(); }
            }
            outputs[0][j] = highestHigh;
            outputs[1][j] = lowestLow;
        }
        return new IndicatorResult(startIndex, j);
    }









    //SET PARAMETERS
    public void setOptInputParameter(int index, Object value) {
        Integer i_value = (Integer) value;
        if (index == 0) {
            period = i_value;
        }
        if (index == 1) {
            if (i_value == FALSE) {
                includeCurrentBar = false;
            }
            if (i_value == TRUE) {
                includeCurrentBar = true;
            }
        }
    }

    public void setOutputParameter(int index, Object array) {
        if (index < outputs.length) {
            outputs[index] = (double[])array;
        }
    }

    public void setInputParameter(int index, Object array) {
        inputs = (IBar[]) array;
    }


   






    //GET PARAMETERS
    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    public InputParameterInfo getInputParameterInfo(int index) {
        return inputParameterInfo;
    }

    public OptInputParameterInfo getOptInputParameterInfo(int index) {
        if (index < optInputParameterInfos.length) {
            return optInputParameterInfos[index];
        }
        return null;
    }

    public OutputParameterInfo getOutputParameterInfo(int index) {
        if (index < outputParameterInfos.length) {
            return outputParameterInfos[index];
        }
        return null;
    }










    //LOOKBACK & LOOKFORWARD
    public int getLookback() {
        if (includeCurrentBar) {
            return period-1;
        } else {
            return period;
        }
    }

    public int getLookforward() {
        return 0;
    }


   





    //CUSTOM METHODS
    private IBar[] subArray(IBar[] sourceArray, int startingIndex, int endingIndex) {
        IBar[] result = null;
        result = new IBar[(endingIndex-startingIndex)+1];
        int j = result.length-1;
        for (int i = startingIndex; i<=endingIndex; i++) {
            result[j] = sourceArray[i];
            j--;
        }
        return result;
    }

    private IBar[] subArrayOfLastValues(IBar[] sourceArray, int lastSourceArrayPosition, int countOfLastValues) {
        IBar[] result = null;
        result = new IBar[countOfLastValues];
        for (int i = 0; i<countOfLastValues; i++) {
            result[i] = sourceArray[lastSourceArrayPosition-i];
        }
        return result;
    }

}




and here is example how to get the indicator values inside of strategy for example:
private double PAC_high(Instrument instrument, Period period, OfferSide offerSide, int lookBack, boolean includeLastBar, long time) Exception {
        int includeLastBar_int = 0;
        if (includeLastBar) { includeLastBar_int=1; }

        double[] values = (double[]) indicators.calculateIndicator(
                instrument,
                period,
                new OfferSide[] {offerSide},
                "LS_I_PAC",
                new AppliedPrice[] {AppliedPrice.CLOSE},
                new Object[] {lookBack, includeLastBar_int},
                Filter.WEEKENDS,
                1,
                time,
                0)[0];
        Double value = values[0];
        return value;
    }
   
    private double PAC_low(Instrument instrument, Period period, OfferSide offerSide, int lookBack, boolean includeLastBar, long time) Exception {
        int includeLastBar_int = 0;
        if (includeLastBar) { includeLastBar_int=1; }

        double[] values = (double[]) indicators.calculateIndicator(
                instrument,
                period,
                new OfferSide[] {offerSide},
                "LS_I_PAC",
                new AppliedPrice[] {AppliedPrice.CLOSE},
                new Object[] {lookBack, includeLastBar_int},
                Filter.WEEKENDS,
                1,
                time,
                0)[1];
        Double value = values[0];
        return value;
    }


 
 Post subject: Re: CHANNEL_UP and DOWN indicators Post rating: 0   New post Posted: Wed 10 Nov, 2010, 10:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Please take a look at the following JForex Wiki page: https://www.dukascopy.com/wiki/index.php ... CHANNEL_UP


 

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