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.

Creating a delay until a certain condition is reached
 Post subject: Creating a delay until a certain condition is reached Post rating: 0   New post Posted: Mon 05 Oct, 2015, 18:02 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi

My scenario...................

I have a master control strategy which performs certain calculations onBar (hourly)
I also have several cloned trading strategies - each a different currency pair - also onBar (hourly)

I wish to implement two delays:-

(1) the master strategy WAITS until it has received a broadcast message from EACH and EVERY trading strategy - before continuing
(2) each trading strategy, after broadcasting the message in (1) above, WAITS until it receives a return message from the master strategy - before continuing

I have read about CyclicBarrier and CountDownLatch in java but am wondering if there is a more straight forward method I should be considering ?

Thanks

Bob M


 
 Post subject: Re: Creating a delay until a certain condition is reached Post rating: 0   New post Posted: Fri 09 Oct, 2015, 14:32 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Broadcast messages are not very suitable in this case because it is not possible to send more than 1 broadcast message per second.
A better solution would be to use socket connections between the strategies.
1) master strategy could act as socket server, other strategies would act as socket clients,
2) when a new client strategy is started it would send a subscribe message to master strategy,
3) when an event happens, each client strategy would send a message to the master strategy,
4) master strategy would wait for all subscribed strategies to notify it.

Here is an example of socket communication: https://www.dukascopy.com/wiki/#Socket_Connection


 
 Post subject: Re: Creating a delay until a certain condition is reached Post rating: 0   New post Posted: Sun 11 Oct, 2015, 08:06 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Thank you for the suggestion of using socket connections.................

Not sure I understand all of the code in the example provided but...........

I have added the 'server' code to my Master strategy
and added the 'client' code to one of my trading strategies

My questions:

1) exactly how do I code the Master strategy to wait until it has received a prospective trade (or message) from ALL clients ?

I'm thinking that each client should let the server know when it starts and if it stops - that way the server knows how many clients there are at any point in time

2) exactly how do I code each trading strategy to WAIT after it has sent the message in (1), until it receives a return message from the Master strategy (the message being a list of optimized trades)

Many thanks
Bob M


 
 Post subject: Re: Creating a delay until a certain condition is reached Post rating: 0   New post Posted: Thu 22 Oct, 2015, 21:59 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi Support

Can you answer my questions in the previous post please

BobM


 
 Post subject: Re: Creating a delay until a certain condition is reached Post rating: 0   New post Posted: Fri 23 Oct, 2015, 07:31 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Quote:
1) exactly how do I code the Master strategy to wait until it has received a prospective trade (or message) from ALL clients ?

One way could be to have an array of flags. The array would contain information on whether each trading strategy has sent a signal.
When all the flags in the array are set, manger strategy can start its job.

Quote:
2) exactly how do I code each trading strategy to WAIT after it has sent the message in (1), until it receives a return message from the Master strategy (the message being a list of optimized trades)

Where could be a flag that would indicate that trading strategy is waiting for manager strategy.
The flag would be set when trading strategy sends the message to the manager strategy.
Trading functions would do nothing if this flag is set.
When master strategy has finished and sent notification back to the trading strategy this flag would be removed.


 
 Post subject: Re: Creating a delay until a certain condition is reached Post rating: 0   New post Posted: Tue 27 Oct, 2015, 22:38 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Quote:
Trading functions would do nothing if this flag is set.


Exactly how does this work ?

The delay is of a few seconds maximum..while all the trading strategies return their prospective trades to the Master strategy and it then calculates the list of optimized trades and sends it to all trading strategies.

So how do we pause each trading strategy while it is in the middle of the onBar calulations and we wish it to perform the balance of the onBar code once it has received the list of optimized trades from the Master strategy ?


 
 Post subject: Re: Creating a delay until a certain condition is reached Post rating: 0   New post Posted: Wed 28 Oct, 2015, 13:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
In this forum we try to focus on JForex API issues. There are a number of external programmers who can program the strategy for you:
https://www.dukascopy.com/fxcomm/member ... am_service


 

Jump to:  

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