Dukascopy
 
 
Wiki JStore Search Login

Incorrect trade and Incorrect number of trades
 Post subject: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Sun 09 Apr, 2017, 08:39 

User rating: 0
Joined: Mon 17 Jun, 2013, 23:30
Posts: 48
Location: Australia, Melbourne
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 97 times
PetersEMA.java [33.72 KiB]
Downloaded 88 times
Error_EMA_SMMA.docx [108.51 KiB]
Downloaded 57 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: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Wed 12 Apr, 2017, 16:37 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
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 !


 
 Post subject: Re: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Thu 13 Apr, 2017, 15:26 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
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 107 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: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Sat 15 Apr, 2017, 07:19 

User rating: 0
Joined: Mon 17 Jun, 2013, 23:30
Posts: 48
Location: Australia, Melbourne
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 57 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: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Tue 18 Apr, 2017, 12:55 

User rating: 0
Joined: Mon 17 Jun, 2013, 23:30
Posts: 48
Location: Australia, Melbourne
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 60 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: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Tue 25 Apr, 2017, 13:52 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
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


 
 Post subject: Re: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Wed 26 Apr, 2017, 03:28 

User rating: 0
Joined: Mon 17 Jun, 2013, 23:30
Posts: 48
Location: Australia, Melbourne
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


 
The Best Answer  Post subject: Re: Incorrect trade and Incorrect number of trades Post rating: 0   New post Posted: Fri 28 Apr, 2017, 15:09 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
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)


 

Jump to:  

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