Dukascopy
 
 
Wiki JStore Search Login

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.

How to specify, what manually entered orders to be further handled by a strategy?
 Post subject: How to specify, what manually entered orders to be further handled by a strategy? Post rating: 0   New post Posted: Wed 13 Jan, 2021, 16:12 

User rating: 1
Joined: Tue 10 Jul, 2012, 11:51
Posts: 25
Location: Czech Republic,
Hi,
I have a strategy for automatic adjustment of SL of manual trades. But I want to manually select positions, which the strategy should be applied to. Others shouldn’t be touched.

I tried to use a keyword in position comment. My assumption was, that I put a keyword into comment of particular positions/trades while the same keyword is a parameter of my strategy.
But I realised Iorder.getComment() returns only comment that was set when order was submitted, not the one I entered manually after the position was manually opened in jforex. So this is probably not the way…

Any ideas?
Thank you


 
 Post subject: Re: How to specify, what manually entered orders to be further handled by a strategy? Post rating: 0   New post Posted: Wed 13 Jan, 2021, 20:54 
User avatar

User rating: 1
Joined: Fri 14 Sep, 2012, 02:25
Posts: 54
Location: New Zealand, Christchurch
the platform display Pos.Id so you can use getId() to match IOrder in your logic


 
 Post subject: Re: How to specify, what manually entered orders to be further handled by a strategy? Post rating: 0   New post Posted: Thu 14 Jan, 2021, 00:27 
User avatar

User rating: 6
Joined: Wed 05 Mar, 2014, 12:00
Posts: 116
Location: Ukraine, Odessa
I think that HAPPYMAN meant that he would like to manage specific orders that were opened and mark them with a comment.

Image

But the problem is that he can't recognize the order with Iorder.getComment() method, it doesn't work.
I remember some years ago someone asks about the feature that allows you to change comment and return it after the order was filled!


Attachments:
Снимок экрана 2021-01-14 012325.png [17.79 KiB]
Downloaded 351 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: How to specify, what manually entered orders to be further handled by a strategy? Post rating: 0   New post Posted: Thu 14 Jan, 2021, 08:38 

User rating: 1
Joined: Tue 10 Jul, 2012, 11:51
Posts: 25
Location: Czech Republic,
Illya, you're right. My strategy runs silently in the background. Once in a day or two I manually open a trade which I want to be handled by the strategy. I'd like to mark the trade somehow the strategy recognise it (without a need to relaunch the strategy and setting which trade to handle). In addition there can be more such trades in the same time.


 
 Post subject: Re: How to specify, what manually entered orders to be further handled by a strategy? Post rating: 1   New post Posted: Thu 14 Jan, 2021, 11:36 

User rating: 1
Joined: Sat 02 Jan, 2021, 23:10
Posts: 2
Location: GermanyGermany
Hello,

One idea is to use the onMessage method.
a little example maybe it will help you.

package jforex;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;

import javax.swing.*;

import java.util.*;

public class ForumTestStrategy implements IStrategy {
        private IEngine engine;
        private IConsole console;
        private IHistory history;
        private IContext context;
        private IIndicators indicators;
        private IUserInterface userInterface;
       
        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 {
                if (IMessage.Type.ORDER_SUBMIT_OK == message.getType()) {
                        IOrder order = message.getOrder();
                        if (!order.getLabel().startsWith("strat_")) {
                                OrderAlert alert = new OrderAlert(order);
                                Thread alertThread = new Thread(alert);
                                alertThread.run();
                        }
                }
        }

        public void onStop() throws JFException {

        }

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

        }

        public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
                // simulate Strategie
                if (period.equals(Period.ONE_HOUR)) {
                        engine.submitOrder("strat_" + bidBar.getTime(), instrument, OrderCommand.BUY, 0.001);
                }

                // simulate Manual
                if (period.equals(Period.FOUR_HOURS)) {
                        engine.submitOrder("man_" + bidBar.getTime(), instrument, OrderCommand.BUY, 0.001);

                }

        }

        class OrderAlert extends Thread {

                IOrder order;

                public OrderAlert(IOrder newOrder) {
                        this.order = newOrder;
                }

                public void run() {
                        showPopup(this.toString());
                }

                private void showPopup(String text) {
                        Object[] options = { "Yes", "No" };
                        int n = JOptionPane.showConfirmDialog(null, "Add Order " + order.getId() + " to Stratagy?");

                        console.getOut().println(n);
                        if (n == 0) {
                                try {

                                        order.setComment("newCommand");
                                } catch (JFException e) {
                                        console.getErr().println(e.getMessage());
                                }
                        }

                }
        }
}


 

Jump to:  

cron
  © 1998-2024 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