| Dukascopy Support Board http://www.dukascopy.com/swiss/english/forex/jforex/forum/ |
|
| Equity Change Strategy http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=50121 |
Page 1 of 1 |
| Author: | Chubbly [ Tue 01 Oct, 2013, 01:36 ] |
| Post subject: | Equity Change Strategy |
I am trying to write a strategy that looks at the value of the equity and then closes all positions when when it reaches a value + or - as a % of the starting equity. For some reason the if statement that calculates if the current equity is greater or less than the TP or SL + and - values is not working. I may have the syntax incorrect. I am not sure package jforex.strategies; |
|
| Author: | API Support [ Tue 01 Oct, 2013, 09:39 ] |
| Post subject: | Re: Equity Change Strategy |
Chubbly wrote: For some reason the if statement that calculates if the current equity is greater or less than the TP or SL + and - values is not working Could you please provide a case when the strategy does not work as expected?
|
|
| Author: | Chubbly [ Tue 01 Oct, 2013, 11:33 ] |
| Post subject: | Re: Equity Change Strategy |
API Support wrote: Chubbly wrote: For some reason the if statement that calculates if the current equity is greater or less than the TP or SL + and - values is not working Could you please provide a case when the strategy does not work as expected?I run the code with a DEMO account Starting Base Equity 80738.89 I select values of 1% when the strategy starts @Configurable("Total take profit (% of account)")The Strategy puts out the following message Quote: 10:16:49 SLbalance 79931.5011 10:16:49 TPbalance 81546.2789 10:16:49 Total2 80738.89 10:16:49 Total 0.0 10:16:49 First balance 80738.89 These values were calculated on the following lines balance = context.getAccount().getBaseEquity(); From the message we see that it calculated what the Base equity would be at -1% (SLbalance 79931.5011) and +1% (TPbalance 81546.2789) When either of these values are reached the the strategy is supposed to close all positions and start over and calculate new +1% and -1% values if ( (Total > TPbalance) || I forced the Equity down by purposely losing trades to 78500 but the if statement is not triggered. If you run the code you will see this |
|
| Author: | tcsabina [ Tue 01 Oct, 2013, 12:06 ] |
| Post subject: | Re: Equity Change Strategy |
Hi, In the past I had issues to compare an order's SL/TP with an actual tick's price. I ended up using Double.compare(): if (Double.compare(anOrder.getStopLossPrice(),0) == 0) {You could give it a try to modify the code to use the mentioned function, but maybe this is not relevant at all... |
|
| Author: | jlongo [ Tue 01 Oct, 2013, 12:47 ] |
| Post subject: | Re: Equity Change Strategy |
Hi... I see some problem logic with your strategy: for (IOrder ord : engine.getOrders()) {In my view you will need to use getEquity() and getBaseEquity() to see the diference... see -> http://www.dukascopy.com/client/javadoc ... count.html. Also, you need to take in consideration that the values returned from this functions can have some delay... the javadoc refer 5 seconds. I hope that helps Trade well JL |
|
| Author: | Chubbly [ Tue 01 Oct, 2013, 14:07 ] |
| Post subject: | Re: Equity Change Strategy |
Hi The reason I am using getBaseEquity() is because I do not open Profit/Loss to be calculated in. I run a basket of 10 strategies, when then the total equity reaches a value I want to close all positions to lock in profits or to stop the strategies from losing more equity. So this way I can look at the 10 strategies as a single group instead of as individual strategies. So I want to get the Base Equity at the start and constantly compare the change to see if the target TP Equity or SL Equity have been meet. I commented out those lines but then the Total value becomes 0 and the strategy just closes all positions immediately for (IOrder ord : engine.getOrders()) {
|
|
| Author: | jlongo [ Tue 01 Oct, 2013, 14:32 ] |
| Post subject: | Re: Equity Change Strategy |
Hi: Support will correct me if i'm wrong but: getBaseEquity() returns the value of equity *without* taking in consideration the loss/profit of open orders getEquity() returns the actual value of equity taking in consideration open orders and their profit/loss. javadoc: getEquity double getEquity() Returns current equity. Value returned by this function is for information purposes and can be incorrect right after order changes, as it is updated about every 5 seconds Returns: equity getBaseEquity double getBaseEquity() Returns current base equity (No open Profit/Loss). Value returned by this function is for information purposes and can be incorrect right after order changes, as it is updated about every 5 seconds. Returns: base equity - equity without open positions' profit/loss So, you can see you are calculating always the equity value without considering the open orders. In my view you use getBaseEquity() to calculate the SL and TP profit equity values and them compare with getEquity() values. This way you can compare sl/tp value with the real change on equity value. Can you see the difference ? Trade well JL |
|
| Author: | Chubbly [ Tue 01 Oct, 2013, 14:54 ] |
| Post subject: | Re: Equity Change Strategy |
Ok, I see the difference now. I have made the change you suggested and it seems to be working now Thanks for the help double Total = 0; |
|
| Page 1 of 1 |