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.

Previous High/Low
 Post subject: Previous High/Low Post rating: 0   New post Posted: Thu 05 May, 2011, 15:40 

User rating: 0
Joined: Wed 05 May, 2010, 03:54
Posts: 2
Is there an indicator that will draw an arrow (like the fractal does) when the current candle price breaks the previous candle's high/low?

So if it breaks the previous candle's high, we'd see an up arrow above the current candle, and if it breaks the previous candle's low, we'd see a down arrow below the current candle?

I tried locating/researching this and couldn't find one. Would this be a difficult indicator to build?

Thanks


 
 Post subject: Re: Previous High/Low Post rating: 0   New post Posted: Wed 08 Jun, 2011, 10:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider the following indicator:

package jforex.indicators;

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

public class FractalSimple implements IIndicator{
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;
    private double[][][] inputs = new double[2][][];
    private double[][] outputs = new double[2][];
    //private int barsOnSides = 2;
   
    private IConsole console;

    public void onStart(IIndicatorContext context) {
       
       console = context.getConsole();
       
       
        indicatorInfo = new IndicatorInfo("FRACTAL SIMPLE", "Fractal indicator simple", "Custom Indicators", true, false, false, 1, 0, 2);
        inputParameterInfos = new InputParameterInfo[] {
          new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)
      };
        outputParameterInfos = new OutputParameterInfo[] {
            new OutputParameterInfo("Maximums", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.ARROW_SYMBOL_DOWN),
            new OutputParameterInfo("Minimums", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.ARROW_SYMBOL_UP)
        };
     }
   


    public IndicatorResult calculate(int startIndex, int endIndex) {
       
        //calculating startIndex taking into account lookback value
        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }
        //calculating endIndex taking into account lookforward value
        if (endIndex + getLookforward() >= inputs[0][0].length) {
            endIndex = inputs[0][0].length - 1 - getLookforward();
        }
        if (startIndex > endIndex) {
            return new IndicatorResult(0, 0);
        }

        //inputs[0 = InputParameterInfo.Type.PRICE][0 = open, 1 = close, 2 = high, 3 = low, 4 = volume][0 = previous bar, 1 = current bar]
        //up arrow
        outputs[1][0] = inputs[0][2][1] > inputs[0][2][0] ? inputs[0][2][1] : Double.NaN;
       
        //down arrow
        outputs[0][0] = inputs[0][3][1] < inputs[0][3][0] ? inputs[0][3][1] : Double.NaN;
           
        return new IndicatorResult(startIndex, endIndex - startIndex + 1, endIndex);
    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    public InputParameterInfo getInputParameterInfo(int index) {
        if (index <= inputParameterInfos.length) {
            return inputParameterInfos[index];
        }
        return null;
    }

    //we are only interested in values of the previous bar
    public int getLookback() {
        return 1;
    }

    //we are not interested in any of next bars
    public int getLookforward() {
        return 0;
    }

    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;
    }

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

    public void setOptInputParameter(int index, Object value) {

    }

    public void setOutputParameter(int index, Object array) {
        outputs[index] = (double[]) array;
    }
   
    private void print(Object o){
       this.console.getOut().println(o);
    }

}


 

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