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

Incorrect trade and Incorrect number of trades
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=141&t=55134
Page 1 of 1

Author:  vtechdir [ Sun 09 Apr, 2017, 08:39 ]
Post subject:  Incorrect trade and Incorrect number of trades

Dear support,

I have a simple strategy to execute:
- on EMA cross SMMA up trigger buy order
- on EMA cross SMMA down trigger sell order
- a time filter to exclude Asian session (set in False)
- TP and SL set at start-up
- trailing stop (set in False)
- with a Martingale branch to be activated after a losing trade
a. if the lot is 0.001 - double the lot every time Martingale is activated
b. if the lot is >0.01 - increment the lot with Step set at start-up
- only one trade at the time is allowed, alternating, Long after Short and Short after Long, regardless of the outcome of previous trade.

The issue is that occasionally I get trades let's say Long when EMA< SMMA where the code says that this should only happen when EMA>SMMA and respectively opposite for shorts.
Every time this situation occurs, multiple positions are opened. At this run, Trailing Stop and Martingale are disabled. I run the strategy in Historical tester and I can measure the values as shown in the Word document. I also included the report file within the Word document to see the start parameters and trades.

The problem is two-fold:
- positions are opened in a direction where the code logic does not allow
- instead of only one position, there are 2 or multiple positions taken

I attached the vJForex, Java files and an error description Word document.
I cleared the cache, the Java cache a few hours before running the script.

Looking forward to your prompt and highly competent reply.

Regards
Virgil

Attachments:
PetersEMA.vfs [86.16 KiB]
Downloaded 269 times
PetersEMA.java [33.72 KiB]
Downloaded 264 times
Error_EMA_SMMA.docx [108.51 KiB]
Downloaded 219 times

Author:  amine_chourou [ Wed 12 Apr, 2017, 16:37 ]
Post subject:  Re: Incorrect trade and Incorrect number of trades

Hi !
Thanks for reaching out in the forum!
I've checked your strategy and I'm currently preparing an example based on your requirement.
I'll send you this asap.

Talk soon !

Author:  amine_chourou [ Thu 13 Apr, 2017, 15:26 ]
Post subject:  Re: Incorrect trade and Incorrect number of trades

Alright, here we go :

I've a made a simplified example for you and I intriduced the use of trade event which is much more efficient and less demanding in terms strategy data optimization.
here is what's implemented:

Quote:
- on EMA cross SMMA up trigger buy order
- on EMA cross SMMA down trigger sell order
-a time filter to exclude Asian session (set in False)
- TP and SL set at start-up
- trailing stop (set in False)
- with a Martingale branch to be activated after a losing trade
a. if the lot is 0.001 - double the lot every time Martingale is activated
b. if the lot is >0.01 - increment the lot with Step set at start-up
- only one trade at the time is allowed, alternating, Long after Short and Short after Long, regardless of the outcome of previous trade.


please test this and add the remaining requirements and let me know if you have any question.

Cheers

Attachments:
PetersEMA_V1.vfs [44.47 KiB]
Downloaded 278 times

Author:  vtechdir [ Sat 15 Apr, 2017, 07:19 ]
Post subject:  Re: Incorrect trade and Incorrect number of trades

Hello Amine,

I thank you very much for your effort to code for my requirements.

I also like the separation of events between "on Candle" and "TradeEvent". It makes the program very intelligible and easy to follow the code to ensure that it matches the requirements.
It's ok with the following:
- a time filter to exclude Asian session (set in False)
- TP and SL set at start-up
they have been covered previously.
I attach my findings in the Word document.

Kind Regards
Virgil

Attachments:
Error_EMA_SMMA.docx [485.63 KiB]
Downloaded 218 times

Author:  vtechdir [ Tue 18 Apr, 2017, 12:55 ]
Post subject:  Re: Incorrect trade and Incorrect number of trades

Hello Amine,

I'm getting a very interesting behaviour, to say the least. Since I cannot see everything in vJForex, I exported the script in Java (using the vJForex File->Export->Java option) and imported in Historical tester. I manually edited the script with the following values:
@Configurable("_EMA_Period:")
public int _EMA_Period = 13;
@Configurable("defaultTakeProfit:")
public int defaultTakeProfit = 14;
@Configurable("defaultInstrument:")
public Instrument defaultInstrument = Instrument.EURUSD;
@Configurable("defaultSlippage:")
public int defaultSlippage = 1;
@Configurable("defaultTradeAmount:")
public double defaultTradeAmount = 0.001;
@Configurable("defaultStopLoss:")
public int defaultStopLoss = 7;
@Configurable("_SMMA_Period:")
public int _SMMA_Period = 21;
@Configurable("defaultPeriod:")
public Period defaultPeriod = Period.ONE_MIN;

compiled and run it.
I included the HTML report in the attached word document. The issues:

1. There are only 3 trades, when by visually inspecting the chart it is obvious that there are more entries.
2. The EMA and SMA are drawn with different Periods than the ones entered. EMA is 34 and SMMA is 8(quite far from 13 and 21 in the script). It thus makes the program misbehave since SMMA will be faster than EMA.

Thus now I am unsure which parameters are within the program.

Kind Regards
Virgil

Attachments:
Error_EMA_SMMA.docx [490.09 KiB]
Downloaded 226 times

Author:  amine_chourou [ Tue 25 Apr, 2017, 13:52 ]
Post subject:  Re: Incorrect trade and Incorrect number of trades

Hi,

Thanks for the detailed description but it would be great if you can attach the strategy "Martigale & MA Cross" that you used so that I can check it.

Thanks

Author:  vtechdir [ Wed 26 Apr, 2017, 03:28 ]
Post subject:  Re: Incorrect trade and Incorrect number of trades

Hi Amine,

I am referring to this thread:
https://www.dukascopy.com/swiss/english ... ale#p85187

Also, after some testing and comparing notes it seems to me that the "Trade Command" block only accept one input and the multiple trades may be related to flow from multiple inputs, is there any truth in this statement?

Thank you very much and all the best
Regards
Virgil

Author:  amine_chourou [ Fri 28 Apr, 2017, 15:09 ]
Post subject:  Re: Incorrect trade and Incorrect number of trades

Hi there!

Thanks for your patience in this matter.

From your latest notes in the document:

Quote:
The program runs with your Default variables, it does not yet accept variable input (I’ll come back to this). I attach the run report to see that even though I selected EMA faster than SMMA it did not work and variables used your values

I've actually tested "MartinGale_SMACross" and modified the default variables and it works well for me. You have to make sure that the modified variable is effectively used in the block in question: example: the SMAs are not using default variable therefore will never be impacted by a change of "Default variable".
Quote:
As per your Martingale and MA cross strategies( posted in the forum) and it is to declare the variable at the beginning of “On Candle” and make it Global.

That's the right way to do to be able to change the setting on-the-fly when lauching the strategy

Quote:
I also noted that it requires negative logic, if it is a Boolean variable, better set it to False to be able to switch it to True, could not change from default True to False.


Can you please point out which Boolean variable is behaving this way ?
Quote:
If I want to have a position in the opposite direction (Long, whilst the initial position is Short), should I use one of the “Trade Message Position” of “TradeEvent” variables?


Simply add a new trade command block with the opposite side (Buy) and link it with the appropriate conditions to trigger a long position
Quote:
Question:
I can inspect the positions with “Position Viewer”, how can I identify the positions (if one is Long and the other one is Short), Label. Message? Are those variable applicable only for closed trades?


Nope: whether it is "Positions" type or "Trade Event" there is a Boolean called "Position is long": This is to identify the side of the trade : True if Long and False if short. It's quite ambiguis I agree but I've explained this in the User Guide (Help menu > User Guide)

  Page 1 of 1