Forex Factory (https://www.forexfactory.com/)
-   Platform Tech (https://www.forexfactory.com/forum/69-platform-tech)
-   -   Java API (https://www.forexfactory.com/thread/205326-java-api)

manohar Nov 6, 2009 12:25pm | Post# 1

Java API
 
package jforex;
import java.util.*;
import com.dukascopy.api.*;
public class Frac_ATR_CCI implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;

static double point=0.0001;
static int digits=6;
public int iBars=100;
public int fractalperiod=10;
public int S2_CCI_Period_m1 = 210;
public int S2_CCI_Period_m5 = 42;
public int S2_CCI_Period_m15 = 14;
static int ATR_Period_m15 = 4;
public int ATR_m15_MaxPoints = 15;
public int MaxDistanceBetweenFractals_m15 = 32;
double[] fractaloutput;
double[] fractal_output;


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();
this.userInterface = context.getUserInterface();
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}

public void onTick(Instrument instrument, ITick tick) throws JFException
{
double close_0=NormalizeDouble(close[0],digits);
double NormalizeDouble(double operand,int digits)
{
try{
if(digits>6) digits=6;
String decimalplaces="###0.";
for(int i=0; i<digits; i++){
decimalplaces += "0";
}
DecimalFormat applydeci = new DecimalFormat(decimalplaces);
Double result = new Double(applydeci.format(operand)).doubleValue();
return(result);
} catch (Exception e) {
return(0.0);
}
}
close[0]=tick.getBid();
if(close_0>GetLastFractalUp(1,Period.ONE_HOUR)||close_0<GetLastFractalDown(1,Period.ONE_HOUR))
return(0);

if(MathRound(indicators.atr(NULL,Period.FIFTEEN_MINS,OfferSide.BID,ATR_Period_m15,0)/point)>=ATR_m15_MaxPoints)
return(0);

double fractal_upper_m15=GetLastFractalUp(1,Period.FIFTEEN_MINS);
double fractal_lower_m15=GetLastFractalDown(1,Period.FIFTEEN_MINS);
fractaloutput= indicators.fractal(instrument,Period.FIFTEEN_MINS,OfferSide.BID,fractalperiod,0);
print(" "+ fractaloutput.length + " " + fractaloutput[0]+ " " + fractaloutput[1]);
fractal_output= indicators.fractal(instrument,Period.FIFTEEN_MINS,OfferSide.BID,fractalperiod,0);
print(" "+fractal_output.length + " " + fractal_output[0]+ " " + fractal_output[1]);
int dist_fractals_m15=MathRound((fractal_upper_m15 - fractal_lower_m15)/point);
double middle_price_fractals_m15=(fractal_upper_m15 + fractal_lower_m15)/2;
if (dist_fractals_m15 >=(MaxDistanceBetweenFractals_m15))
return;
double cci_m15_0=indicators.cci(instrument,Period.FIFTEEN_MINS,OfferSide.BID,S2_CCI_PERIOD_m15,0);
double cci_m5_0=indicators.cci(instrument,Period.FIVE_MINS,OfferSide.BID,S2_CCI_PERIOD_m5,0);
double cci_m1_0=indicators.cci(instrument,Period.ONE_MIN,OfferSide.BID,S2_CCI_PERIOD_m1,0);
print(" "+cci_m15_0+" "+cci_m55_0 + " "+cci_m1_0);
}
double GetLastFractalDown(int shift,Period timePeriod)
{
for(int i=shift;i<=iBars;i++)
{
fractaloutput = indicators.fractal(Instrument.EURUSD,Period.FIFTEEN_MINS,OfferSide.BID,fractalperiod,i);
if(fractaloutput!=0)
return(0);
}
}
double GetLastFractalUp(int shift,Period timePeriod)
{
for(int i=shift;i<=iBars;i++)
{
fractal_output = indicators.fractal(Instrument.EURUSD,Period.FIFTEEN_MINS,OfferSide.BID,fractalperiod,i);
if(fractal_output!=0)
return(0);
}
}
}

I am a beginner in this coding. I need to display the fractaloutput as well as the length/size. But i am facing these errors i.e
*) Incompatible operand types double[] and int
if(fractal_output!=0)
*) Incompatible operand types double[] and int
if(fractaloutput!=0)
*) Syntax error on token ")", ; expected
double NormalizeDouble(double operand,int digits)
*) Syntax error on token ",", ; expected
double NormalizeDouble(double operand,int digits)
*) Syntax error on token "(", ; expected
double NormalizeDouble(double operand,int digits)

realdrago Feb 7, 2011 6:35am | Post# 2

Here is a little tip :
use software like ECLIPSE or NetBeans for code writing or editing.
They are free and will save a LOT of time and effort


© Forex Factory