Dukascopy
 
 
Wiki JStore Search Login

Remote Server Problem
 Post subject: Remote Server Problem Post rating: 0   New post Posted: Fri 30 Nov, 2012, 15:11 

User rating: 0
Joined: Mon 26 Nov, 2012, 16:32
Posts: 11
Location: JapanJapan
Hello, can you explain me, why i don't have problem to run my testing strategy localy from my PC.
But when i want to test it on Remote Server, just after uploading, the remote server stop my strategy ???

Thank you.


Here's my code:

package jforex.feed.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.feed.*;
import com.dukascopy.api.feed.util.*;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.IEngine.OrderCommand;

/**
* The following strategy demonstrates how one can bind an arbitrary set of indicators
* with corresponding feed descriptors, such that each indicator with its feed descriptor
* can be used both for indicator calculation and indicator plotting on the chart.
*
*/

public class ORDRESEND implements IStrategy {

private IConsole console;
private IIndicators indicators;
private IContext context;
private IEngine engine;
private IHistory history;
private IUserInterface userInterface;




@Configurable("")
public Instrument instrument = Instrument.EURUSD;

public int counter;

@Configurable("Period")
public Period selectedPeriod = Period.FIFTEEN_MINS;

@Configurable("Period")
public Period selectedPeriodh = Period.ONE_HOUR;

@Configurable("Period")
public Period selectedPeriodc = Period.FIVE_MINS;

@Configurable("Period")
public Period selectedPeriodm = Period.ONE_MIN;

@Configurable("SMA filter")
public Filter indicatorFilter = Filter.NO_FILTER;
@Configurable("Amount")
public double amount = 0.1;
@Configurable("Stop loss")
public int stopLossPips = 20;



@Configurable("Take profit")
public int takeProfitPips = 100;




@Configurable("")
public OfferSide side = OfferSide.BID;

public int w=0;

public double ccio;

class IndDataAndFeed{

private IFeedDescriptor feedDescriptor;
private String indicatorName;
private Object[] optionalInputs;
private int outputIndex;
private IIndicator indicator;
private IChart chart;

public IndDataAndFeed(String indicatorName, Object[] optionalInputs, int outputIndex, IFeedDescriptor feedDescriptor) {
this.feedDescriptor = feedDescriptor;
this.indicatorName = indicatorName;
this.optionalInputs = optionalInputs;
this.outputIndex = outputIndex;
}

public void openChartAddIndicator(){
for(IChart openedChart : context.getCharts(feedDescriptor.getInstrument())){
IFeedDescriptor chartFeed = openedChart.getFeedDescriptor();
if(chartFeed.getPeriod() == feedDescriptor.getPeriod() && chartFeed.getOfferSide() == feedDescriptor.getOfferSide()){
chart = openedChart;
}
}
if(chart == null){
chart = context.openChart(feedDescriptor);
}
indicator = indicators.getIndicator(indicatorName);
chart.add(indicator, optionalInputs);
}

public double getCurrentValue() throws JFException{
Object[] outputs = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { side },indicatorName,
new AppliedPrice[] { AppliedPrice.CLOSE }, optionalInputs, 0);
double value = (Double) outputs[outputIndex];
return value;
}

public void removeFromChart(){
if(chart != null && indicator != null){
chart.removeIndicator(indicator);
}
}

@Override
public String toString(){
return String.format("%s %s on %s feed", indicatorName, Arrays.toString(optionalInputs), feedDescriptor.getPeriod());
}

}

private List<IndDataAndFeed> calculatableIndicators = new ArrayList<IndDataAndFeed>(Arrays.asList(new IndDataAndFeed[]{
new IndDataAndFeed("MACD", new Object[] {12,26,9}, 0, new TimePeriodAggregationFeedDescriptor(instrument, Period.FIVE_MINS, side)),
new IndDataAndFeed("RSI", new Object[] {50}, 0, new TimePeriodAggregationFeedDescriptor(instrument, Period.FIVE_MINS, side)),
new IndDataAndFeed("RSI", new Object[] {50}, 0, new TimePeriodAggregationFeedDescriptor(instrument, Period.ONE_HOUR, side)),
new IndDataAndFeed("CCI", new Object[] {14}, 0, new TimePeriodAggregationFeedDescriptor(instrument, Period.FIFTEEN_MINS, side)),
new IndDataAndFeed("CCI", new Object[] {14}, 0, new TimePeriodAggregationFeedDescriptor(instrument, Period.ONE_HOUR, side)),
new IndDataAndFeed("CCI", new Object[] {14}, 0, new TimePeriodAggregationFeedDescriptor(instrument, Period.ONE_MIN, side))
}));


@Override
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();

if(!context.getSubscribedInstruments().contains(instrument)){
context.setSubscribedInstruments(new HashSet<Instrument>(Arrays.asList(new Instrument [] {instrument})), true);
}

this.context = context;
console = context.getConsole();
indicators = context.getIndicators();

for(IndDataAndFeed indDataAndFeed : calculatableIndicators){
indDataAndFeed.openChartAddIndicator();
}
}

@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (instrument != this.instrument) {
return;
}


int i=0;

for (IndDataAndFeed indDataAndFeed : calculatableIndicators) {
double value = indDataAndFeed.getCurrentValue();
// print("%s current value=%.5f", indDataAndFeed, value);

i=i+1;


if(i==6)
{print("%s current value pour le CCI M1=%.5f", indDataAndFeed, value);
ccio = value;}



}

// ORDERS
if (w==0 && ccio>0)
{engine.submitOrder("buyorder", instrument, OrderCommand.BUY, 0.1);
w=300;}



if (w==0 && ccio<0)
{engine.submitOrder("sellorder", instrument, OrderCommand.SELL, 0.1);
w=400;}


// CLOSING
if (w==300 && ccio<0)
{engine.getOrder("buyorder").close();
engine.getOrder("buyorder").waitForUpdate(IOrder.State.CLOSED); //wait till the order is closed};
w=0;
}


if (w==400 && ccio>0)
{engine.getOrder("sellorder").close();
engine.getOrder("sellorder").waitForUpdate(IOrder.State.CLOSED); //wait till the order is closed};
w=0;
}




}

@Override
public void onStop() throws JFException {
for(IndDataAndFeed indDataAndFeed : calculatableIndicators){
indDataAndFeed.removeFromChart();
}
//close all orders
for (IOrder order : engine.getOrders()) {
engine.getOrder(order.getLabel()).close();
}
}

private void print(Object o) {
console.getOut().println(o);
}

private void print(String format, Object... args) {
print(String.format(format, args));
}


private IOrder submitOrder(OrderCommand orderCmd) throws JFException {

return engine.submitOrder(getLabel(instrument), this.instrument, orderCmd, this.amount, 0, 5);
}



protected String getLabel(Instrument instrument) {
String label = instrument.name();
label = label + (counter++);
label = label.toUpperCase();
return label;
}




@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}

@Override
public void onMessage(IMessage message) throws JFException {
}

@Override
public void onAccount(IAccount account) throws JFException {
}



}


Attachments:
ORDRESEND.java [8.62 KiB]
Downloaded 552 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: Remote Server Problem Post rating: 0   New post Posted: Sat 01 Dec, 2012, 06:17 
User avatar

User rating: 3
Joined: Mon 05 Mar, 2012, 11:15
Posts: 24
Location: Indonesia, Jakarta
public void openChartAddIndicator(){
            for(IChart openedChart : context.getCharts(feedDescriptor.getInstrument())){
                IFeedDescriptor chartFeed = openedChart.getFeedDescriptor();
                if(chartFeed.getPeriod() == feedDescriptor.getPeriod() && chartFeed.getOfferSide() == feedDescriptor.getOfferSide()){
                    chart = openedChart;
                }
            }
            if(chart == null){
                chart = context.openChart(feedDescriptor);
            }
            indicator = indicators.getIndicator(indicatorName);
            chart.add(indicator, optionalInputs);
        }


When running on local machine, you have Chart object from jforex, while running on remote server there is no chart object, so context.getCharts(feedDescriptor.getInstrument()) will return null.

Quick n dirty fix
public void openChartAddIndicator(){
       if ( context.getCharts(feedDescriptor.getInstrument()) == null ) return;
       ...


You might also want to move OnTick body to OnBar, for performance.


 
 Post subject: Re: Remote Server Problem Post rating: 0   New post Posted: Wed 05 Dec, 2012, 17:20 

User rating: 0
Joined: Mon 26 Nov, 2012, 16:32
Posts: 11
Location: JapanJapan
Thanks a lot my friend !!!!
It perfectly works !!!!!!


 
 Post subject: Re: Remote Server Problem Post rating: 0   New post Posted: Mon 14 Jan, 2013, 19:33 

User rating: 0
Joined: Mon 14 Jan, 2013, 19:24
Posts: 2
popopo wrote:
public void openChartAddIndicator(){
            for(IChart openedChart : context.getCharts(feedDescriptor.getInstrument())){
                IFeedDescriptor chartFeed = openedChart.getFeedDescriptor();
                if(chartFeed.getPeriod() == feedDescriptor.getPeriod() && chartFeed.getOfferSide() == feedDescriptor.getOfferSide()){
                    chart = openedChart;
                }
            }
            if(chart == null){
                chart = context.openChart(feedDescriptor);
            }
            indicator = indicators.getIndicator(indicatorName);
            chart.add(indicator, optionalInputs);
        }


When running on local machine, you have Chart object from jforex, while running on remote server there is no chart object, so context.getCharts(feedDescriptor.getInstrument()) will return null.

Quick n dirty fix
public void openChartAddIndicator(){
       if ( context.getCharts(feedDescriptor.getInstrument()) == null ) return;
       ...


You might also want to move OnTick body to OnBar, for performance.


---

Hello Guys,

I think I have similar issue, but I cannot find out the source of problem.
Would you be so kind and look into the following codes, that where can be the problem: I cannot run Remote mode. Srtategy is only working on Local run.
ps.: I have requested slot for Remote mode already :)

Thanks in advance.

Code as follow:

import com.dukascopy.api.*;
import java.util.HashSet;
import java.util.Set;
import com.dukascopy.api.drawings.IChartObjectFactory;
import com.dukascopy.api.drawings.IOhlcChartObject;
import com.dukascopy.api.indicators.OutputParameterInfo.DrawingStyle;
import java.awt.Color;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;
import com.dukascopy.api.drawings.IChartDependentChartObject;
import com.dukascopy.api.drawings.ITriangleChartObject;
import com.dukascopy.api.drawings.ITextChartObject;

public class Vterv02 implements IStrategy {

private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
private IBar previousBar;
private IOrder order;
private IChart openedChart;
private IChartObjectFactory factory;
private int signals;
private static final int PREV = 1;
private static final int SECOND_TO_LAST = 0;
private int uniqueOrderCounter = 1;
private SMATrend previousSMADirection = SMATrend.NOT_SET;
private SMATrend currentSMADirection = SMATrend.NOT_SET;
private Map<IOrder, Boolean> createdOrderMap = new HashMap<IOrder, Boolean>();
private int shorLineCounter;
private int textCounterOldSL;
private int textCounterNewSL;

@Configurable(value = "Instrument value")
public Instrument myInstrument = Instrument.EURUSD;
@Configurable(value = "Offer Side value", obligatory = true)
public OfferSide myOfferSide = OfferSide.BID;
@Configurable(value = "Period value")
public Period myPeriod = Period.ONE_HOUR;
@Configurable("SMA time period")
public int smaTimePeriod = 30;
@Configurable("Add OHLC Index to chart")
public boolean addOHLC = true;
@Configurable("Filter")
public Filter filter = Filter.WEEKENDS;
@Configurable("Draw SMA")
public boolean drawSMA = true;
@Configurable("Close chart on onStop")
public boolean closeChart;
@Configurable("Stop loss in pips")
public int stopLossPips = 400;
@Configurable("Take profit in pips")
public int takeProfitPips = 10;
@Configurable("Break event pips")
public double breakEventPips = 10;
@Configurable("Amount")
public double amount = 0.005;

private enum SMATrend {
UP, DOWN, NOT_SET;
}

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();
this.openedChart = context.getChart(myInstrument);
this.factory = openedChart.getChartObjectFactory();

Set<Instrument> instruments = new HashSet<Instrument>();
instruments.add(myInstrument);
context.setSubscribedInstruments(instruments, true);

if (drawSMA) {
if (!addToChart(openedChart)) {
printMeError("Indicators did not get plotted on chart. Check the chart values!");
}}
}

public void onAccount(IAccount account) throws JFException {
}

public void onMessage(IMessage message) throws JFException {
if (message.getOrder() != null) {
printMe("order: " + message.getOrder().getLabel() + " || message content: " + message);
}
}

public void onStop() throws JFException {}

public void onTick(Instrument instrument, ITick tick) throws JFException {
if (instrument != myInstrument) {
return;
}
for (Map.Entry<IOrder, Boolean> entry : createdOrderMap.entrySet()) {
IOrder currentOrder = entry.getKey();
boolean currentValue = entry.getValue();
if (currentValue == false && currentOrder.getProfitLossInPips() >= breakEventPips) {
printMe("Order has profit of " + currentOrder.getProfitLossInPips() + " pips! Moving the stop loss to the open price.");
addBreakToChart(currentOrder, tick, currentOrder.getStopLossPrice(), currentOrder.getOpenPrice());
currentOrder.setStopLossPrice(currentOrder.getOpenPrice());
entry.setValue(true);
}
}
}

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (!instrument.equals(myInstrument) || !period.equals(myPeriod)) {
return;
}

int candlesBefore = 2, candlesAfter = 0;
long completedBarTimeL = myOfferSide == OfferSide.ASK ? askBar.getTime() : bidBar.getTime();
double sma[] = indicators.sma(instrument, period, myOfferSide, IIndicators.AppliedPrice.CLOSE,
smaTimePeriod, Filter.NO_FILTER, candlesBefore, completedBarTimeL, candlesAfter);
printMe(String.format("Bar SMA Values: Second-to-last = %.5f; Last Completed = %.5f", sma[SECOND_TO_LAST], sma[PREV]));

IEngine.OrderCommand myCommand = null;
printMe(String.format("Bar SMA Values: Second-to-last = %.5f; Last Completed = %.5f", sma[SECOND_TO_LAST], sma[PREV]));
if (sma[PREV] > sma[SECOND_TO_LAST]) {
printMe("SMA in up-trend");
myCommand = IEngine.OrderCommand.BUY;
currentSMADirection = SMATrend.UP;
} else if (sma[PREV] < sma[SECOND_TO_LAST]) {
printMe("SMA in down-trend");
myCommand = IEngine.OrderCommand.SELL;
currentSMADirection = SMATrend.DOWN;
} else {
return;
}

double lastTickBid = history.getLastTick(myInstrument).getBid();
double lastTickAsk = history.getLastTick(myInstrument).getAsk();
double stopLossValueForLong = myInstrument.getPipValue() * stopLossPips;
double stopLossValueForShort = myInstrument.getPipValue() * takeProfitPips;
double stopLossPrice = myCommand.isLong() ? (lastTickBid - stopLossValueForLong) : (lastTickAsk + stopLossValueForLong);
double takeProfitPrice = myCommand.isLong() ? (lastTickBid + stopLossValueForShort) : (lastTickAsk - stopLossValueForShort);

if (currentSMADirection != previousSMADirection) {
previousSMADirection = currentSMADirection;
IOrder newOrder = engine.submitOrder("MyStrategyOrder" + uniqueOrderCounter++, instrument, myCommand, 0.005, 0, 1, stopLossPrice, takeProfitPrice);
createdOrderMap.put(newOrder, false);

if(openedChart == null){
return;
}
long time = bidBar.getTime() + myPeriod.getInterval();
double space = myInstrument.getPipValue() * 2;
IChartDependentChartObject signal = myCommand.isLong()
? factory.createSignalUp("signalUpKey" + signals++, time, bidBar.getLow() - space)
: factory.createSignalDown("signalDownKey" + signals++, time, bidBar.getHigh() + space);
signal.setStickToCandleTimeEnabled(false);
signal.setText("MyStrategyOrder" + (uniqueOrderCounter - 1));
openedChart.addToMainChart(signal);
}

}

private void printMe(Object toPrint) {
console.getOut().println(toPrint);
}


private void printMeError(Object o) {
console.getErr().println(o);
}

private boolean addToChart(IChart chart) {
if (!checkChart(chart)) {
return false;
}

chart.addIndicator(indicators.getIndicator("SMA"), new Object[]{smaTimePeriod},
new Color[]{Color.BLUE}, new DrawingStyle[]{DrawingStyle.LINE}, new int[]{3});

if (addOHLC) {
IOhlcChartObject ohlc = null;
for (IChartObject obj : chart.getAll()) {
if (obj instanceof IOhlcChartObject) {
ohlc = (IOhlcChartObject) obj;
}
}
if (ohlc == null) {
ohlc = chart.getChartObjectFactory().createOhlcInformer();
ohlc.setPreferredSize(new Dimension(100, 200));
chart.addToMainChart(ohlc);
}
ohlc.setShowIndicatorInfo(true);
}
return true;
}

private void addBreakToChart(IOrder changedOrder, ITick tick, double oldSL, double newSL) throws JFException {
}

private boolean checkChart(IChart chart) {
if (chart == null) {
printMeError("chart for " + myInstrument + " not opened!");
return false;
}
if (chart.getSelectedOfferSide() != this.myOfferSide) {
printMeError("chart offer side is not " + this.myOfferSide);
return false;
}
if (chart.getSelectedPeriod() != this.myPeriod) {
printMeError("chart period is not " + this.myPeriod);
return false;
}
if (chart.getFilter() != this.filter) {
printMeError("chart filter is not " + this.filter);
return false;
}
return true;
}


}


 
 Post subject: Re: Remote Server Problem Post rating: 0   New post Posted: Thu 17 Jan, 2013, 08:32 
User avatar

User rating: 3
Joined: Mon 05 Mar, 2012, 11:15
Posts: 24
Location: Indonesia, Jakarta
try this

from function body onStart()
this.openedChart = context.getChart(myInstrument);
this.factory = openedChart.getChartObjectFactory();

change to
this.openedChart = context.getChart(myInstrument);
if ( this.openedChart != null )
{
     this.factory = openedChart.getChartObjectFactory();
}


 
 Post subject: Re: Remote Server Problem Post rating: 0   New post Posted: Fri 01 Feb, 2013, 11:19 
User avatar

User rating: 0
Joined: Wed 20 Jul, 2011, 05:45
Posts: 20
Location: BulgariaBulgaria
Can somebody help me to fix my strategy from local to remote server please? It didn't working...




package jforex;
import java.util.*;
import com.dukascopy.api.*;
public class test33 implements IStrategy {
private IContext context = null;
private IEngine engine = null;
private IChart chart = null;
private IHistory history = null;
private IIndicators indicators = null;
private IConsole console = null;
private double volume = 0.02;
private int profitLimit;
private int lossLimit;
private double bidPrice;
private double askPrice;


public void onStart(IContext context) throws JFException {
this.context = context;
engine = context.getEngine();
indicators = context.getIndicators();
history = context.getHistory();
console = context.getConsole();
Set subscribedInstruments = new HashSet();
subscribedInstruments.add(Instrument.EURJPY);
context.setSubscribedInstruments(subscribedInstruments);
}


public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}

protected int positionsTotal(Instrument instrument) throws JFException {
int counter = 0;
for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() == IOrder.State.FILLED) {
counter++;
}
}
return counter;
}
protected String getLabel(Instrument instrument) {
String label = instrument.name();
long time = new java.util.Date().getTime();
label = label.substring(0, 2) + label.substring(3, 5);
label = label + time;
label = label.toLowerCase();
return label;
}
public void onBar(Instrument instrument, Period period, IBar askbar, IBar bidbar) throws JFException {
if (instrument != Instrument.EURJPY|| period != Period.THIRTY_MINS) return;
{

profitLimit = 10;
lossLimit = 128;

if (askbar.getVolume() == 0) return;
double openPrice = bidbar.getOpen();
askPrice = askbar.getClose();
bidPrice = bidbar.getClose();


double sma1 = this.indicators.sma(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 55, 0);
double [] bands = this.indicators.bbands(instrument,
period,
OfferSide.BID,
IIndicators.AppliedPrice.CLOSE,
30,
0.8,
0.8,
IIndicators.MaType.DEMA,
0);


if (positionsTotal(instrument) == 0) {
//openPrice < bands[0] && bidPrice > bands[0] && // openPrice > bands[2] && bidPrice < bands[2] &&
if ( openPrice < bands[0] && bidPrice > bands[0] && bidPrice > sma1 ) {
buy(instrument, engine, profitLimit, lossLimit, volume);
}

else if (openPrice > bands[2] && bidPrice < bands[2] && bidPrice < sma1 ) {
sell(instrument, engine, profitLimit, lossLimit, volume);
}

}
}
}
public void onMessage(IMessage message) throws JFException {
if (message != null && message.getType() == IMessage.Type.ORDER_CLOSE_OK) {
IOrder lastOne = message.getOrder();
double profitsLoss = lastOne.getProfitLossInPips() ;
console.getOut().println("Order : "+lastOne.getLabel()+ " "+ lastOne.getOrderCommand()+ " Pips: "+profitsLoss);
}
}
@Override
public void onAccount(IAccount account) throws JFException {
}
public void sell(Instrument instrument, IEngine engine, int takeProfitPipLevel, int endLossPipLevel, double volumeParam) throws JFException {
engine.submitOrder(getLabel(instrument), instrument, IEngine.OrderCommand.SELL, volumeParam, 0, 10, bidPrice
+ instrument.getPipValue() *endLossPipLevel, bidPrice - instrument.getPipValue() * takeProfitPipLevel);
}
public void buy(Instrument instrument, IEngine engine, int takeProfitPipLevel, int endLossPipLevel, double volumeParam) throws JFException {
engine.submitOrder(getLabel(instrument), instrument, IEngine.OrderCommand.BUY, volumeParam, 0, 10, askPrice
- instrument.getPipValue() * endLossPipLevel, askPrice + instrument.getPipValue() * takeProfitPipLevel);
}
}


 
 Post subject: Re: Remote Server Problem Post rating: 0   New post Posted: Fri 01 Feb, 2013, 19:42 

User rating: 0
Joined: Mon 14 Jan, 2013, 19:24
Posts: 2
Hi,

Thanks for the tip, it is running now.

The only problem that it writes: 18:33:22 Strategy "Vterv03" is started at 2013-02-01 18:34:14.441 GMT on the remote server with no parameters.

Any idea how can it be pre set upped?
Thanks again and have a nice weekend.
A.


 

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