I am able to compile this strategy but when I try to run it I get the error
File is not implementing IStrategy interface.
Any help is appreciated
package jforex;
import com.dukascopy.api.indicators.*;
import com.dukascopy.api.*;
import java.awt.*;
import java.util.*;
import com.dukascopy.api.indicators.*;
import com.dukascopy.api.feed.*;
import com.dukascopy.api.JFException;
import java.text.DecimalFormat;
/**********************************
* Created by: Aristidi Y.
* Date: June 15, 2012
* TODO: Allow to the user to choose between applied price (Close, open, high, low, HL/2, HLC/3, HLCC/4)
* TODO: Show the lines as moving averages
* TODO: Show the highest and lowest value by increase their line width
*********************************/
public class CurrencyStrength implements IIndicator {
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OptInputParameterInfo[] optInputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private IBar[][] inputs = new IBar[21][]; //21 major instruments
private int timePeriod = 1;
private int period=0; //Default :ONE_HOUR
private int[] periodValues= new int[5];
private String[] periodNames=new String[5];
private Period myPeriod=Period.ONE_HOUR;
private double[][] outputs = new double[7][]; //7 currencies USD-EUR-JPY-GBP-CHF-AUD-CAD
private IHistory history;
private IConsole console;
private IIndicatorContext context;
private IBar[] myBar = new IBar[21]; //Contains the IBar for each instruments
private double[] prices = new double[21]; //Contain the value HLC of each instruments
private double[] currencyPrice= new double[7]; //Contain the price sum for each currency
public void onStart(IIndicatorContext context) {
console=context.getConsole();
this.context=context;
this.history=context.getHistory();
indicatorInfo = new IndicatorInfo("CurrenciesStrenght", "Show the Currency strenght for majors ", "My indicators",
false, false, false, 21, 2, 7);
//Definition of the inputs (eg each instruments)
//EURUSD
InputParameterInfo eurUsdInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
eurUsdInput.setInstrument(Instrument.EURUSD);
//GBPUSD
InputParameterInfo gbpUsdInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
gbpUsdInput.setInstrument(Instrument.GBPUSD);
//USDCHF
InputParameterInfo usdChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
usdChfInput.setInstrument(Instrument.USDCHF);
//AUDUSD
InputParameterInfo audUsdInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
audUsdInput.setInstrument(Instrument.AUDUSD);
//USDCAD
InputParameterInfo usdCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
usdCadInput.setInstrument(Instrument.USDCAD);
//USDJPY
InputParameterInfo usdJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
usdJpyInput.setInstrument(Instrument.USDJPY);
//EURGBP
InputParameterInfo eurGbpInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
eurGbpInput.setInstrument(Instrument.EURGBP);
//EURCHF
InputParameterInfo eurChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
eurChfInput.setInstrument(Instrument.EURCHF);
//EURAUD
InputParameterInfo eurAudInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
eurAudInput.setInstrument(Instrument.EURAUD);
//EURCAD
InputParameterInfo eurCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
eurCadInput.setInstrument(Instrument.EURCAD);
//EURJPY
InputParameterInfo eurJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
eurJpyInput.setInstrument(Instrument.EURJPY);
//GBPCHF
InputParameterInfo gbpChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
gbpChfInput.setInstrument(Instrument.GBPCHF);
//GBPAUD
InputParameterInfo gbpAudInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
gbpAudInput.setInstrument(Instrument.GBPAUD);
//GBPCAD
InputParameterInfo gbpCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
gbpCadInput.setInstrument(Instrument.GBPCAD);
//GBPJPY
InputParameterInfo gbpJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
gbpJpyInput.setInstrument(Instrument.GBPJPY);
//AUDCHF
InputParameterInfo audChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
audChfInput.setInstrument(Instrument.AUDCHF);
//CADCHF
InputParameterInfo cadChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
cadChfInput.setInstrument(Instrument.CADCHF);
//CHFJPY
InputParameterInfo chfJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
chfJpyInput.setInstrument(Instrument.CHFJPY);
//AUDCAD
InputParameterInfo audCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
audCadInput.setInstrument(Instrument.AUDCAD);
//AUDJPY
InputParameterInfo audJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
audJpyInput.setInstrument(Instrument.AUDJPY);
//CADJPY
InputParameterInfo cadJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.BAR);
cadJpyInput.setInstrument(Instrument.CADJPY);
//fill the array
inputParameterInfos = new InputParameterInfo[] {eurUsdInput, gbpUsdInput,usdChfInput, audUsdInput, usdCadInput, usdJpyInput,eurGbpInput, eurChfInput, eurAudInput, eurCadInput, eurJpyInput,
gbpChfInput, gbpAudInput, gbpCadInput, gbpJpyInput, audChfInput, cadChfInput, chfJpyInput, audCadInput, audJpyInput, cadJpyInput };
optInputParameterInfos = new OptInputParameterInfo[] {
new OptInputParameterInfo("Number of bar in past for reference", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(1, 1, 200, 1)),
new OptInputParameterInfo("Period", OptInputParameterInfo.Type.OTHER, new IntegerListDescription(period, periodValues, periodNames))
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("USD", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("EUR", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("GBP", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("JPY", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("AUD", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("CAD", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("CHF", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
};
outputParameterInfos[0].setColor(Color.green); //Color USD
outputParameterInfos[1].setColor(Color.blue); //Color EUR
outputParameterInfos[2].setColor(Color.pink); //Color GBP
outputParameterInfos[3].setColor(Color.yellow); //Color JPY
outputParameterInfos[4].setColor(Color.orange); //Color AUD
outputParameterInfos[5].setColor(Color.darkGray); //Color CAD
outputParameterInfos[6].setColor(Color.red); //Color CHF
for (int w=0;w<outputParameterInfos.length;w++)
{
outputParameterInfos[w].setLineWidth(2);
}
setPeriods();
SumOfAllPrices();
}
public IndicatorResult calculate(int startIndex, int endIndex) {
int boucledMax=0;
int boucledMin=0;
if (startIndex>endIndex)
{
return new IndicatorResult(0,0);
}
int i,j=0;
if (startIndex - getLookback() < 0 ) {
startIndex -= startIndex - getLookback();
}
for (i=startIndex, j=0; i<=endIndex;i++,j++)
{
if (i<inputs[0].length && i<inputs[1].length && i<inputs[2].length && i<inputs[3].length && i<inputs[4].length && i<inputs[5].length && i<inputs[6].length && i<inputs[7].length
&& i<inputs[8].length && i<inputs[9].length && i<inputs[10].length && i<inputs[11].length && i<inputs[12].length && i<inputs[13].length && i<inputs[14].length &&
i<inputs[15].length && i<inputs[16].length && i<inputs[17].length && i<inputs[18].length && i<inputs[19].length && i<inputs[20].length)
{
/* ******** ****The outputs are defined like this ******************
* 0 - USD
* 1 - EUR
* 2 - GBP
* 3 - JPY
* 4 - AUD
* 5 - CAD
* 6 - CHF
*
*************** The inputs are defined like this *******************
* 0 - EURUSD
* 1 - GBPUSD
* 2 - USDCHF
* 3 - AUDUSD
* 4 - USDCAD
* 5 - USDJPY
* 6 - EURGBP
* 7 - EURCHF
* 8 - EURAUD
* 9 - EURCAD
* 10 -EURJPY
* 11 - GBPCHF
* 12 - GBPAUD
* 13 - GBPCAD
* 14 - GBPJPY
* 15 - AUDCHF
* 16 - CADCHF
* 17 - CHFJPY
* 18 - AUDCAD
* 19 - AUDJPY
* 20 - CADJPY
*********************************************************************/
outputs[0][j]=(((1/(inputs[0][i].getClose()))+(1/(inputs[1][i].getClose()))+(inputs[2][i].getClose())+(1/(inputs[3][i].getClose()))+(inputs[4][i].getClose())+((inputs[5][i].getClose())))/currencyPrice[0])*100; //USD
outputs[1][j]=((inputs[0][i].getClose()+inputs[6][i].getClose()+inputs[7][i].getClose()+inputs[8][i].getClose()+inputs[9][i].getClose()+((inputs[10][i].getClose())))/currencyPrice[1])*100; //EUR
outputs[2][j]=((inputs[1][i].getClose()+(1/(inputs[6][i].getClose())+inputs[11][i].getClose()+inputs[12][i].getClose()+inputs[13][i].getClose()+(inputs[14][i].getClose())))/currencyPrice[2])*100; //GBP
outputs[3][j]=((((1/inputs[5][i].getClose()))+(1/inputs[10][i].getClose())+(1/inputs[14][i].getClose())+(1/inputs[17][i].getClose())+(1/inputs[19][i].getClose())+(1/inputs[20][i].getClose()))/currencyPrice[3])*100; //JPY
outputs[4][j]=((inputs[3][i].getClose()+(1/(inputs[8][i].getClose()))+(1/(inputs[12][i].getClose()))+inputs[15][i].getClose()+inputs[18][i].getClose()+(inputs[19][i].getClose()))/currencyPrice[4])*100; //AUD
outputs[5][j]=((((1/inputs[4][i].getClose())+(1/(inputs[9][i].getClose()))+(1/inputs[13][i].getClose())+inputs[16][i].getClose()+(1/inputs[18][i].getClose())+(inputs[20][i].getClose())))/currencyPrice[5])*100; //CAD
outputs[6][j]=(((1/inputs[2][i].getClose())+(1/inputs[7][i].getClose())+(1/inputs[11][i].getClose())+(1/inputs[15][i].getClose())+(1/inputs[16][i].getClose())+(inputs[17][i].getClose()))/currencyPrice[6])*100; //CHF
}
}
return new IndicatorResult (startIndex,j);
}
private void showMaxMinCurency(int myMax, int myMin)
{
String maxStr="";
String minStr="";
switch (myMax) {
case 0:
maxStr="USD";
break;
case 1:
maxStr="EUR";
break;
case 2:
maxStr="GBP";
break;
case 3:
maxStr="JPY";
break;
case 4:
maxStr="AUD";
break;
case 5:
maxStr="CAD";
break;
case 6:
maxStr="CHF";
break;
}
switch (myMin) {
case 0:
minStr="USD";
break;
case 1:
minStr="EUR";
break;
case 2:
minStr="GBP";
break;
case 3:
minStr="JPY";
break;
case 4:
minStr="AUD";
break;
case 5:
minStr="CAD";
break;
case 6:
minStr="CHF";
break;
}
console.getOut().println("Highest: "+maxStr+" Lowest: "+minStr);
}
private void setPeriods()
{
for (int i = 0; i < periodValues.length; i++) { periodValues[i] = i; }
periodNames[0]= "One Hour";
periodNames[1]= "Four Hours";
periodNames[2] = "Daily";
periodNames[3] = "Weekly";
periodNames[4] = "Monthly";
}
private void SumOfAllPrices()
{
// This method calculate the values of the currency at the time whe choosen
try {
myBar[0]=history.getBar(Instrument.EURUSD, myPeriod,OfferSide.BID, timePeriod);
myBar[1]=history.getBar(Instrument.GBPUSD, myPeriod,OfferSide.BID, timePeriod);
myBar[2]=history.getBar(Instrument.USDCHF, myPeriod,OfferSide.BID, timePeriod);
myBar[3]=history.getBar(Instrument.AUDUSD, myPeriod,OfferSide.BID, timePeriod);
myBar[4]=history.getBar(Instrument.USDCAD, myPeriod,OfferSide.BID, timePeriod);
myBar[5]=history.getBar(Instrument.USDJPY, myPeriod,OfferSide.BID, timePeriod);
myBar[6]=history.getBar(Instrument.EURGBP, myPeriod,OfferSide.BID, timePeriod);
myBar[7]=history.getBar(Instrument.EURCHF, myPeriod,OfferSide.BID, timePeriod);
myBar[8]=history.getBar(Instrument.EURAUD, myPeriod,OfferSide.BID, timePeriod);
myBar[9]=history.getBar(Instrument.EURCAD, myPeriod,OfferSide.BID, timePeriod);
myBar[10]=history.getBar(Instrument.EURJPY,myPeriod,OfferSide.BID, timePeriod);
myBar[11]=history.getBar(Instrument.GBPCHF,myPeriod,OfferSide.BID, timePeriod);
myBar[12]=history.getBar(Instrument.GBPAUD,myPeriod,OfferSide.BID, timePeriod);
myBar[13]=history.getBar(Instrument.GBPCAD, myPeriod,OfferSide.BID, timePeriod);
myBar[14]=history.getBar(Instrument.GBPJPY, myPeriod,OfferSide.BID, timePeriod);
myBar[15]=history.getBar(Instrument.AUDCHF, myPeriod,OfferSide.BID, timePeriod);
myBar[16]=history.getBar(Instrument.CADCHF, myPeriod,OfferSide.BID, timePeriod);
myBar[17]=history.getBar(Instrument.CHFJPY, myPeriod,OfferSide.BID, timePeriod);
myBar[18]=history.getBar(Instrument.AUDCAD,myPeriod,OfferSide.BID, timePeriod);
myBar[19]=history.getBar(Instrument.AUDJPY,myPeriod,OfferSide.BID, timePeriod);
myBar[20]=history.getBar(Instrument.CADJPY, myPeriod,OfferSide.BID, timePeriod);
for (int p=0;p<myBar.length;p++) {
prices[p] = myBar[p].getClose();
}
currencyPrice[0]=1/prices[0]+1/prices[1]+prices[2]+1/prices[3]+prices[4]+(prices[5]); //USD
currencyPrice[1]=prices[0]+prices[6]+prices[7]+prices[8]+prices[9]+(prices[10]); //EUR
currencyPrice[2]=prices[1]+1/prices[6]+prices[11]+prices[12]+prices[13]+(prices[14]); //GBP
currencyPrice[3]=(((1/prices[5])+(1/prices[10])+(1/prices[14])+(1/prices[17])+(1/prices[19])+(1/prices[20]))); //JPY
currencyPrice[4]=prices[3]+1/prices[8]+1/prices[12]+prices[15]+prices[18]+(prices[19]); //AUD
currencyPrice[5]=1/prices[4]+1/prices[9]+1/prices[13]+prices[16]+1/prices[18]+(prices[20]); //CAD
currencyPrice[6]=1/prices[2]+1/prices[7]+1/prices[11]+1/prices[15]+1/prices[16]+(prices[17]); //CHF
}
catch (JFException e)
{
console.getErr().println(e);
}
}
public IndicatorInfo getIndicatorInfo() {
return indicatorInfo;
}
public InputParameterInfo getInputParameterInfo(int index) {
if (index <= inputParameterInfos.length) {
return inputParameterInfos[index];
}
return null;
}
public int getLookback() {
return timePeriod;
}
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] = (IBar[]) array;
}
public void setOptInputParameter(int index, Object value) {
switch (index)
{
case 0:
timePeriod = (Integer) value;
SumOfAllPrices();
break;
case 1: period=((Integer)value).intValue();
switch (period) {
case 0:
this.myPeriod= Period.ONE_HOUR;
break;
case 1:
this.myPeriod= Period.FOUR_HOURS;
break;
case 2:
this.myPeriod=Period.DAILY;
break;
case 3:
this.myPeriod=Period.WEEKLY;
break;
case 4:
this.myPeriod=Period.MONTHLY;
break;
}
break;
}
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
private void printDouble (double d, String s) {
console.getOut().println(s+(new DecimalFormat("#.#####")).format(d));
}
private void printDouble (double d) {
console.getOut().println((new DecimalFormat("#.#####")).format(d));
}
}