Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

I can't create new strategy
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=21&t=53694
Page 1 of 1

Author:  Peggy37 [ Mon 22 Feb, 2016, 17:12 ]
Post subject:  I can't create new strategy

Hi

Why i can't create a new strategy ?
I want to write a code to it and it runs only in view mode.

Please help !

Author:  Peggy37 [ Sun 28 Feb, 2016, 21:34 ]
Post subject:  Re: I can't create new strategy

Al dcdemo helped, thanks Al dcdemo.

Author:  al_dcdemo [ Tue 01 Mar, 2016, 10:22 ]
Post subject:  Re: I can't create new strategy

This was answered in Q&A, pasting it here just for convenience.

al_dcdemo wrote:
Strategy Contest platform is designed specifically for monitoring strategies during the contest in "View Mode".

Please use regular, non-contest JForex platform to develop and backtest your strategies.

Author:  vadim_berezhnoj [ Tue 30 Aug, 2016, 14:46 ]
Post subject:  Re: I can't create new strategy

Hello.

Please specify the error message when you can not upload the strategy.

Author:  Peggy37 [ Fri 02 Sep, 2016, 22:02 ]
Post subject:  Re: I can't create new strategy

it does not provide error messages.

only selling works, when comes on buying it stops.

Please help.

Author:  vadim_berezhnoj [ Wed 07 Sep, 2016, 17:00 ]
Post subject:  Re: I can't create new strategy

Hello.

To see the error log open Strategy Logs.
Open your contest account in JForex platform -> Profile -> Strategy Log.

Author:  Peggy37 [ Sun 11 Sep, 2016, 20:12 ]
Post subject:  Re: I can't create new strategy

Sorry I can't upload files.

I found, that buying does not work.

Last Update : 11.09.2016 18:52:02
Level Date Message
ERROR
09.09.2016 15:15:57 at java.lang.Thread.run(Thread.java:745)
ERROR
09.09.2016 15:15:57 at com.dukascopy.api.impl.execution.ScienceThreadPoolExecutor$Worker.runTask(ScienceThreadPoolExecutor.java:904)
ERROR
09.09.2016 15:15:57 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
ERROR
09.09.2016 15:15:57 at com.dukascopy.api.impl.execution.TaskCustom.call(TaskCustom.java:34)
ERROR
09.09.2016 15:15:57 at com.dukascopy.api.impl.connect.JForexTaskManager$StopCallable.call(JForexTaskManager.java:1249)
ERROR
09.09.2016 15:15:57 at com.dukascopy.api.impl.connect.JFRunnableProcessor.onStop(JFRunnableProcessor.java:149)
ERROR
09.09.2016 15:15:57 at com.dukascopy.api.impl.execution.TaskStop.call(TaskStop.java:29)
ERROR
09.09.2016 15:15:57 at jforex.Lenka_v_0.onStop(Lenka_v_0.java:69)
ERROR
09.09.2016 15:15:57 java.lang.NullPointerException @ jforex.Lenka_v_0.onStop(Lenka_v_0.java:69)

Author:  vadim_berezhnoj [ Wed 14 Sep, 2016, 11:13 ]
Post subject:  Re: I can't create new strategy

Please test your strategies on demo real time run, before starting it on Contest.

Your strategy is locking in the dead-cycle after order sended and keeps spamming message: Order closed either from outside the strategy. Stopping the strategy.

public void onMessage(IMessage message) throws JFException {

if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_TP)) {
engine.submitOrder("order", Instrument.USDCAD, order.getOrderCommand(), 13);
} else if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_SL)) {

engine.submitOrder("order2",Instrument.USDCAD, order.isLong() ? OrderCommand.SELL : OrderCommand.BUY, 7);
} else {
console.getOut().println("Order closed either from outside the strategy. Stopping the strategy.");

}
}

Author:  Peggy37 [ Mon 19 Sep, 2016, 18:41 ]
Post subject:  Re: I can't create new strategy

Tested on demo and works GOOD !!

I don't know why my strategy does not know buying.


package jforex;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IOrder.State;
import com.dukascopy.api.IMessage.Type;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IMessage;
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;
import com.dukascopy.api.OfferSide;

import java.util.Set;
import java.util.HashSet;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.*;
import java.text.*;
import java.util.*;


/*
 * Simple bar scalping strategy. Pair: USD/CAD, take profit:12, stop loss 7, amount 1 mio, If green bar, buys, if red bar, sells. Period: one hour.
 * v_06 test
 */
public class Lenka_v_0 implements IStrategy {

    private IAccount account;
    private IEngine engine;
    private IHistory history;
    private IConsole console;
    private IContext context;
    private IOrder order;
  //  private IBar previosBar;
 
  @Override 
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.history = context.getHistory();
        this.console = context.getConsole();
        this.context = context;
           
         //subscribe an instrument:
        Set instruments = new HashSet();
        instruments.add(Instrument.USDCAD);                     
        context.setSubscribedInstruments(instruments, true);
       
        // init. order = buy.
        IBar initBar = history.getBar(Instrument.USDCAD, Period.ONE_HOUR, OfferSide.ASK, 1);
        OrderCommand makeOrder = initBar.getClose()>initBar.getOpen() ? OrderCommand.BUY  : OrderCommand.SELL;
        engine.submitOrder("initorder", Instrument.USDCAD, OrderCommand.BUY, 1,0,1, history.getLastTick(Instrument.USDCAD).getBid() - 13 * Instrument.USDCAD.getPipValue(),   
                      history.getLastTick(Instrument.USDCAD).getBid() + 7 * Instrument.USDCAD.getPipValue());
        order.waitForUpdate(3000, IOrder.State.FILLED);
       
    }
   
    public void onAccount(IAccount account) throws JFException {
  //     this.account = account;       

    }

    public void onMessage(IMessage message) throws JFException {
        if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_TP)) {
            // on close by TP we keep the order direction
           engine.submitOrder("initorder", Instrument.USDCAD, OrderCommand.BUY, 1,0,1, history.getLastTick(Instrument.USDCAD).getBid() - 13 * Instrument.USDCAD.getPipValue(),   
                      history.getLastTick(Instrument.USDCAD).getBid() + 7 * Instrument.USDCAD.getPipValue());
           order.waitForUpdate(3000, IOrder.State.FILLED);

           
        } else  {
            //  "Order closed by SL". --> SELL.
            OrderCommand orderCmd = order.isLong() ? OrderCommand.SELL : OrderCommand.BUY;   
             engine.submitOrder("redbar", Instrument.USDCAD, OrderCommand.SELL, 1, 0, 1, history.getLastTick(Instrument.USDCAD).getAsk() + 7 * Instrument.USDCAD.getPipValue(),
                  history.getLastTick(Instrument.USDCAD).getAsk() - 13 * Instrument.USDCAD.getPipValue());
                  order.waitForUpdate(3000, IOrder.State.FILLED);
       
        }
    }
   
    public void onStop() throws JFException {
 //     if(order.getState() == IOrder.State.FILLED || order.getState() == IOrder.State.OPENED){
     
//           order.close();
 //          context.stop();
 //     }
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
 
               
   }
 @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if(engine.getOrders().size()==0 && instrument.equals("USDCAD") && period.equals("ONE_HOUR"))
        {
            if(((history.getBar(Instrument.USDCAD, Period.ONE_HOUR, OfferSide.BID, 1).getClose()))>history.getBar(Instrument.USDCAD, Period.ONE_HOUR, OfferSide.BID, 1).getOpen())
            {   
                  engine.submitOrder("greenbar", Instrument.USDCAD, OrderCommand.BUY, 1,0,1, history.getLastTick(Instrument.USDCAD).getBid() - 13 * Instrument.USDCAD.getPipValue(),   
                  history.getLastTick(Instrument.USDCAD).getBid() + 7 * Instrument.USDCAD.getPipValue());
                  order.waitForUpdate(3000, IOrder.State.FILLED);
            }
            else {     
                  engine.submitOrder("redbar", Instrument.USDCAD, OrderCommand.SELL, 1, 0, 1, history.getLastTick(Instrument.USDCAD).getAsk() + 7 * Instrument.USDCAD.getPipValue(),
                  history.getLastTick(Instrument.USDCAD).getAsk() - 13 * Instrument.USDCAD.getPipValue());
                  order.waitForUpdate(3000, IOrder.State.FILLED);
            }
        }
        else {
            ;
        }
    }   
}
       




Please check.

Author:  vadim_berezhnoj [ Tue 20 Sep, 2016, 14:41 ]
Post subject:  Re: I can't create new strategy

Your currently running strategy contains that code:

    public void onMessage(IMessage message) throws JFException {
 
       if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_TP)) {
          engine.submitOrder("order", Instrument.USDCAD, order.getOrderCommand(), 13);
        } else if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_SL)) {
   
           engine.submitOrder("order2",Instrument.USDCAD, order.isLong() ? OrderCommand.SELL : OrderCommand.BUY, 7);
        } else {
            console.getOut().println("Order closed either from outside the strategy. Stopping the strategy.");
   
        }
    }


So if it reads message that does not include "ORDER_CLOSED_BY_TP" or "ORDER_CLOSED_BY_SL" it wrights the message "Order closed either from outside the strategy. Stopping the strategy."
Then it reads the previous message and sends it again and again and again... enles cycle... then NPO.
If it trades on regular Demo account it acts the same.

Author:  Peggy37 [ Tue 20 Sep, 2016, 16:51 ]
Post subject:  Re: I can't create new strategy

Thank you much .

That looks like the strategy still executing old version ??
It didn't take new - actual version ??
I completed, onBbar, initiall order...
On stop has to be empty ??( i don't understand this strategy "loop".)

How to change it to new version ?

Author:  vadim_berezhnoj [ Mon 26 Sep, 2016, 13:48 ]
Post subject:  Re: I can't create new strategy

vadim_berezhnoj wrote:
How to change it to new version ?

You can upload new version of the strategy from your Contest Profile.
Only one version update per month is allowed.

vadim_berezhnoj wrote:
On stop has to be empty ?

It is not limited by the Rules.

vadim_berezhnoj wrote:
i don't understand this strategy "loop"

You can google by "Infinite loop".

Author:  Peggy37 [ Mon 26 Sep, 2016, 20:59 ]
Post subject:  Re: I can't create new strategy

Thanks, so its not working properly, because of oldest version.

I understand the (main() function an user defined functions) loop, but not the "jforex strategy" loop - (1order, then close, then open next order and so on.... ) - how jforex "reads" it and how to do it. - example: if(myOrder.getPipValue()=takeprofit) { ... *submit_Order...

Author:  vadim_berezhnoj [ Tue 27 Sep, 2016, 15:31 ]
Post subject:  Re: I can't create new strategy

https://en.wikipedia.org/wiki/Infinite_loop

Author:  Peggy37 [ Thu 29 Sep, 2016, 23:15 ]
Post subject:  Re: I can't create new strategy

vadim_berezhnoj wrote:
https://en.wikipedia.org/wiki/Infinite_loop

Sorry ?

And in jforex?

Im trying with "drawing" a sreategy in Visual j forex - i think it has "looping" but im not sure .

Author:  vadim_berezhnoj [ Fri 30 Sep, 2016, 16:12 ]
Post subject:  Re: I can't create new strategy

There is Infinite-loop in your strategy code.
As it was explained earlier, it is locking in the loop after order sent and it keeps spamming message: "Order closed either from outside the strategy. Stopping the strategy."
That triggers the condition to send the same message again and again. That condition is in the following part:

public void onMessage(IMessage message) throws JFException {

if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_TP)) {
engine.submitOrder("order", Instrument.USDCAD, order.getOrderCommand(), 13);
} else if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_SL)) {

engine.submitOrder("order2",Instrument.USDCAD, order.isLong() ? OrderCommand.SELL : OrderCommand.BUY, 7);
} else {
console.getOut().println("Order closed either from outside the strategy. Stopping the strategy.");

}
}

  Page 1 of 1