|
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.
I coudn´t add some many forex symbols into my code |
daykoku
|
Post subject: I coudn´t add some many forex symbols into my code |
Post rating: 1
|
Posted: Tue 18 Sep, 2018, 13:43
|
|
User rating: 2
Joined: Mon 19 Aug, 2013, 11:21 Posts: 2 Location: Spain, Matanza de Acentejo
|
Hi, i have some many problems when i try to add in my strategy EURJPY, GBPJPY, and much more.... tried to deleted historical data in .cache, work the symbols with example strategys, reinstall platform but its impossible, when i add the symbols in historical tester, thats blocked and strategy doesnt work. Just work when run with EURUSD or GBPUSD
Please i need help to solve the issue, thanks.
D
|
|
|
|
|
JP7
|
Post subject: Re: I coudn´t add some many forex symbols into my code |
Post rating: 0
|
Posted: Fri 21 Sep, 2018, 00:50
|
|
User rating: 13
Joined: Mon 27 Jul, 2015, 16:30 Posts: 110 Location: Canada, Mission
|
|
|
|
|
daykoku
|
Post subject: Re: I coudn´t add some many forex symbols into my code |
Post rating: 1
|
Posted: Tue 25 Sep, 2018, 09:35
|
|
User rating: 2
Joined: Mon 19 Aug, 2013, 11:21 Posts: 2 Location: Spain, Matanza de Acentejo
|
Hi JP7, thanks for u reply. This mourning when i try to run your code all the symbols work again in all the strategys. But when I try with 4 instruments in another code where only need 4 instrument it still doesnt work. Anyway in this way I can continue testing . have a nice day! D.
|
|
|
|
|
JP7
|
Post subject: Re: I coudn´t add some many forex symbols into my code |
Post rating: 0
|
Posted: Fri 30 Aug, 2019, 07:19
|
|
User rating: 13
Joined: Mon 27 Jul, 2015, 16:30 Posts: 110 Location: Canada, Mission
|
import com.dukascopy.api.Configurable; import com.dukascopy.api.IAccount; import com.dukascopy.api.IBar; import com.dukascopy.api.IConsole; import com.dukascopy.api.IContext; import com.dukascopy.api.IEngine; import com.dukascopy.api.IEngine.OrderCommand; import com.dukascopy.api.IHistory; import com.dukascopy.api.IMessage; import com.dukascopy.api.IOrder; import com.dukascopy.api.IStrategy; import com.dukascopy.api.ITick; import com.dukascopy.api.Instrument; import com.dukascopy.api.JFException; import com.dukascopy.api.Period;
public class Tobogan_11_Instruments implements IStrategy {
// AUDJPY AUDUSD CADJPY EURGBP EURJPY EURUSD GBPUSD NZDJPY NZDUSD USDCAD USDJPY public int tradesTotalBUY(Instrument XXX) throws JFException { int counter1 = 0; for (IOrder ORD : engine.getOrders(XXX)) { if (ORD.getState() == IOrder.State.FILLED && ORD.isLong()) { counter1++; } } return counter1; }
public int tradesTotalSELL(Instrument XXX) throws JFException { int counter2 = 0; for (IOrder ORD : engine.getOrders(XXX)) { if (ORD.getState() == IOrder.State.FILLED && !ORD.isLong()) { counter2++; } } return counter2; }
private IEngine engine; private IConsole console; private int counter = 0; private IHistory history; private ITick previousTick = null; private String string = ""; public Period selectedPeriod = Period.TEN_MINS;
// AUDJPY AUDUSD CADJPY EURGBP EURJPY EURUSD GBPUSD NZDJPY NZDUSD USDCAD USDJPY public Instrument instrument = Instrument.EURUSD; public Instrument AUDJPY = Instrument.AUDJPY; // 1 public Instrument AUDUSD = Instrument.AUDUSD; // 2 public Instrument CADJPY = Instrument.CADJPY; // 3 public Instrument EURGBP = Instrument.EURGBP; // 4 public Instrument EURJPY = Instrument.EURJPY; // 5 public Instrument EURUSD = Instrument.EURUSD; // 6 public Instrument GBPUSD = Instrument.GBPUSD; // 7 public Instrument NZDJPY = Instrument.NZDJPY; // 8 public Instrument NZDUSD = Instrument.NZDUSD; // 9 public Instrument USDCAD = Instrument.USDCAD; // 10 public Instrument USDJPY = Instrument.USDJPY; // 11
@Configurable("Step pips") public double step = 20;
@Configurable("Slippage") public double slippage = 2;
@Configurable("Amount") public double amount = 0.1;
@Configurable("Stop Loss Pips") public int slPips = 100; @Configurable("Take Profit Pips") public int takeProfitPips = 10;
@Override public void onStart(IContext context) throws JFException { this.console = context.getConsole(); this.engine = context.getEngine(); this.setHistory(context.getHistory());
}
@Override public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (period != this.selectedPeriod || instrument != this.instrument) { return; } }
public void onTick(Instrument instrument, ITick tick) throws JFException { if (instrument != this.instrument) { return; }
if (previousTick == null) { previousTick = tick; return; }
if (tick.getBid() >= previousTick.getBid() + instrument.getPipValue()*(step)) { if (tradesTotalSELL(AUDJPY) == 0) {string = "SELL_"+AUDJPY;submitOrder(OrderCommand.SELL, AUDJPY);} if (tradesTotalSELL(AUDUSD) == 0) {string = "SELL_"+AUDUSD;submitOrder(OrderCommand.SELL, AUDUSD);} if (tradesTotalSELL(CADJPY) == 0) {string = "SELL_"+CADJPY;submitOrder(OrderCommand.SELL, CADJPY);} if (tradesTotalSELL(EURGBP) == 0) {string = "SELL_"+EURGBP;submitOrder(OrderCommand.SELL, EURGBP);} if (tradesTotalSELL(EURJPY) == 0) {string = "SELL_"+EURJPY;submitOrder(OrderCommand.SELL, EURJPY);} if (tradesTotalSELL(EURUSD) == 0) {string = "SELL_"+EURUSD;submitOrder(OrderCommand.SELL, EURUSD);} if (tradesTotalSELL(GBPUSD) == 0) {string = "SELL_"+GBPUSD;submitOrder(OrderCommand.SELL, GBPUSD);} if (tradesTotalSELL(NZDJPY) == 0) {string = "SELL_"+NZDJPY;submitOrder(OrderCommand.SELL, NZDJPY);} if (tradesTotalSELL(NZDUSD) == 0) {string = "SELL_"+NZDUSD;submitOrder(OrderCommand.SELL, NZDUSD);} if (tradesTotalSELL(USDCAD) == 0) {string = "SELL_"+USDCAD;submitOrder(OrderCommand.SELL, USDCAD);} if (tradesTotalSELL(USDJPY) == 0) {string = "SELL_"+USDJPY;submitOrder(OrderCommand.SELL, USDJPY);} previousTick = tick; } else if (tick.getAsk() <= previousTick.getAsk() - instrument.getPipValue()*(step)) {
if (tradesTotalBUY(AUDJPY) == 0) {string = "BUY_"+AUDJPY;submitOrder(OrderCommand.BUY, AUDJPY);} if (tradesTotalBUY(AUDUSD) == 0) {string = "BUY_"+AUDUSD;submitOrder(OrderCommand.BUY, AUDUSD);} if (tradesTotalBUY(CADJPY) == 0) {string = "BUY_"+CADJPY;submitOrder(OrderCommand.BUY, CADJPY);} if (tradesTotalBUY(EURGBP) == 0) {string = "BUY_"+EURGBP;submitOrder(OrderCommand.BUY, EURGBP);} if (tradesTotalBUY(EURJPY) == 0) {string = "BUY_"+EURJPY;submitOrder(OrderCommand.BUY, EURJPY);} if (tradesTotalBUY(EURUSD) == 0) {string = "BUY_"+EURUSD;submitOrder(OrderCommand.BUY, EURUSD);} if (tradesTotalBUY(GBPUSD) == 0) {string = "BUY_"+GBPUSD;submitOrder(OrderCommand.BUY, GBPUSD);} if (tradesTotalBUY(NZDJPY) == 0) {string = "BUY_"+NZDJPY;submitOrder(OrderCommand.BUY, NZDJPY);} if (tradesTotalBUY(NZDUSD) == 0) {string = "BUY_"+NZDUSD;submitOrder(OrderCommand.BUY, NZDUSD);} if (tradesTotalBUY(USDCAD) == 0) {string = "BUY_"+USDCAD;submitOrder(OrderCommand.BUY, USDCAD);} if (tradesTotalBUY(USDJPY) == 0) {string = "BUY_"+USDJPY;submitOrder(OrderCommand.BUY, USDJPY);} previousTick = tick; } }
private String getLabel(Instrument instrument) { String label = instrument.name(); label = label + (counter++); label = label.toUpperCase(); return label; }
public void onMessage(IMessage message) throws JFException { print(message); }
public void onStop() throws JFException { }
private void print(Object o) { console.getOut().println(o); }
public IHistory getHistory() { return history; }
public void setHistory(IHistory history) { this.history = history; }
private IOrder submitOrder(OrderCommand orderCmd, Instrument instrument) throws JFException { double stopLossPrice = 0.0, takeProfitPrice = 0.0; if (orderCmd == OrderCommand.BUY) { if (slPips > 0) { stopLossPrice = history.getLastTick(instrument).getBid() - instrument.getPipValue()*(slPips); } if (takeProfitPips > 0) { takeProfitPrice = history.getLastTick(instrument).getBid() + instrument.getPipValue()*(takeProfitPips); } } else if (orderCmd == OrderCommand.SELL) { if (slPips > 0) { stopLossPrice = history.getLastTick(instrument).getBid() + instrument.getPipValue()*(slPips); } if (takeProfitPips > 0) { takeProfitPrice = history.getLastTick(instrument).getBid() - instrument.getPipValue()*(takeProfitPips); } }
return engine.submitOrder(getLabel(instrument), instrument, orderCmd, amount, 0, slippage, stopLossPrice,takeProfitPrice,0,string); } public void onAccount(IAccount account) throws JFException { } }
Attachments: |
Tobogan_11_Instruments.java [7.65 KiB]
Downloaded 122 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.
|
|
|
|
|
|
|
Pages: [
1
]
|
|
|
|
|