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)")
public double tpPercent = 1;
@Configurable("Total stop loss (% of account)")
public double slPct = 1; 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();
console.getOut().println("First balance "+(new DecimalFormat("#.#######")).format(balance));
}
public void onAccount(IAccount account) throws JFException {
double Total = 0;
//Total = context.getAccount().getBaseEquity();
console.getOut().println("Total "+ Total);
for (IOrder ord : engine.getOrders()) {
Total += context.getAccount().getBaseEquity();
}
Total = context.getAccount().getBaseEquity();
console.getOut().println("Total2 "+ Total);
TPbalance = ((balance * 0.01 * tpPercent)+balance);
SLbalance = ((- balance * 0.01 * slPct)+balance);
console.getOut().println("TPbalance "+TPbalance);
console.getOut().println("SLbalance "+SLbalance);
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) ||
(Total < SLbalance )) {
for (IOrder order : engine.getOrders()) {
if(order.getState() != IOrder.State.CLOSED && order.getState() != IOrder.State.CANCELED) {
order.close();
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