Dukascopy
 
 
Wiki JStore Search Login

Odd behaviour with automated trading strategy
 Post subject: Odd behaviour with automated trading strategy Post rating: 0   New post Posted: Thu 06 Aug, 2020, 22:28 
User avatar

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

Am seeking comments from the community - not support - on the following situation

I have a strategy which runs on the JForex platform of Dukascopy

The filtering it contains is not rocket science - when comparing numeric values, we basically have the three outcomes:- <, = and > and I guess 'NULL'

I use this basic type of filtering to trade only with the currency pairs I am interest in, only on the days I wish to trade and only between certain hours of the day

I understand that at the start we are subscribed to every currency pair and it one of the requirements of the strategy to filter out unwanted pairs

This filtering goes for unwanted days, unwanted hours, unwanted spreads etc etc.

Recently - I have seen my strategy trade in a currency pair that I DON'T subscribe to and have filtered OUT, and trade on a day that I have filtered OUT

I am struggling to understand why this happens periodically

For 99% of the time my strategy works as it should

Does anybody have any comments about this behaviour - any pointers as to how I can eliminate the 'odd' behaviour

Kind regards

Bob M
New Zealand


 
 Post subject: Re: Odd behaviour with automated trading strategy Post rating: 0   New post Posted: Tue 18 Aug, 2020, 15:15 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 413
Location: Germany, Munich
Maybe we can help.
I have a few questions:
1) Is your strategy executed remote or local run?
2) Have you already tried to synchronize onbar and ontick methods? e.g.

public synchronized void onTick(Instrument instrument, ITick tick) throws JFException {
}
public synchronized void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}

3) Have you tried to separate your strategy in different sub-classes. Best if you use a sub class holding each instrument runtime trading variables.


 
 Post subject: Re: Odd behaviour with automated trading strategy Post rating: 0   New post Posted: Tue 15 Sep, 2020, 03:02 
User avatar

User rating: 1
Joined: Fri 14 Sep, 2012, 02:25
Posts: 54
Location: New Zealand, Christchurch
Can I ask what the "synchronized" statement does onTick / onBar?


 
 Post subject: Re: Odd behaviour with automated trading strategy Post rating: 0   New post Posted: Tue 15 Sep, 2020, 13:50 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 413
Location: Germany, Munich
Find a description of this Java keyword here
https://www.baeldung.com/java-synchronized

You would avoid a repeatable function call while the same function is still computing your code from a previous trigger call.
e.g. the onBar function call could happen several times in the same moment. Consider the time 08:15h, the following basic time bars would trigger this function: 10 secs, 1 min, 5 mins, 10 mins, 15 mins


 
 Post subject: Re: Odd behaviour with automated trading strategy Post rating: 0   New post Posted: Wed 16 Sep, 2020, 21:07 
User avatar

User rating: 1
Joined: Fri 14 Sep, 2012, 02:25
Posts: 54
Location: New Zealand, Christchurch
thanks, much appreciated.
My onBar logic for one period is usually different from my onBar logic for another period - and I implement as:

public void onBar(Instrument Instr, Period period, IBar askBar, IBar bidBar) throws JFException {

if (Instr != selectedInstrument) return;
if (period == period1) {
// period1 logic
}
if (period == period2) {
// period2 logic
} else return;
}

This always seems to work ok without issues (so far) and if period1 = 1sec and period2 = 15min then I get both executed on a 15M Bar.
If I'm reading you right I think you are saying I might be in trouble if my 1sec logic somehow conflicts with my 15M logic (i.e. should never execute at the same time). So the 'synchronized' will force my 15M logic to wait until my 1sec logic is done.

Sounds like adding synchronized would always be a good default thing to have in place !!


 
 Post subject: Re: Odd behaviour with automated trading strategy Post rating: 0   New post Posted: Thu 17 Sep, 2020, 08:33 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 413
Location: Germany, Munich
No, synchronized is not always good.
It could produce a traffic jam of execution requests because only one thread can execute the function at a time. The others have to wait.
Sometimes you even prefer parallel execution of the same method because you are faster in the market or also out of the market.
All you need to do is to make your function thread safe for multiple execution, e.g. avoid writing and reading global variables.


 

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