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

Odd behaviour with automated trading strategy
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=77&t=57408
Page 1 of 1

Author:  us_copiosus [ Thu 06 Aug, 2020, 22:28 ]
Post subject:  Odd behaviour with automated trading strategy

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

Author:  SFXbernhard [ Tue 18 Aug, 2020, 15:15 ]
Post subject:  Re: Odd behaviour with automated trading strategy

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.

Author:  fprophet [ Tue 15 Sep, 2020, 03:02 ]
Post subject:  Re: Odd behaviour with automated trading strategy

Can I ask what the "synchronized" statement does onTick / onBar?

Author:  SFXbernhard [ Tue 15 Sep, 2020, 13:50 ]
Post subject:  Re: Odd behaviour with automated trading strategy

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

Author:  fprophet [ Wed 16 Sep, 2020, 21:07 ]
Post subject:  Re: Odd behaviour with automated trading strategy

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 !!

Author:  SFXbernhard [ Thu 17 Sep, 2020, 08:33 ]
Post subject:  Re: Odd behaviour with automated trading strategy

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.

  Page 1 of 1