Quote:
@@@i would like to add a nr, that will represent the risk, than i would like to have a sp.for the Sl pipps, and the strategy needs to calc. the lot size, that the trade will be executed. example.: Sl 10 risk percentage:2 in this case lets say, the balance its 1000$,then then the lot will be 0.002<it means,that i can risk with the 10pips 20$>
Here is sample code to compute the lot:
import com.dukascopy.api.*;
public class GetLotStrat implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
@Configurable("risk in percent")
public int risk = 2;
public void onStart(IContext context) throws JFException {
IAccount account = context.getAccount();
if(risk < 1 || risk > 100) {
throw new JFException("Invalid risk value: "+risk);
}
double lot = account.getEquity() * account.getLeverage() * risk / 100;
lot = lot / 1000000; // convert to millions
context.getConsole().getOut().println(lot);
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}
Quote:
@@@posibility for adding a trailing st
There is a strategy that updates stop loss price. Please see the following forum topic:
viewtopic.php?f=65&t=42122&hilit=update+stop+lossnote that it is possible to iterate orders using the following code:
for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() == IOrder.State.FILLED) {
...
}
}
Quote:
@@@option to set with a click the pos.to BE
Here is a topic where break even strategy is discussed:
viewtopic.php?f=65&t=44322&hilit=filledQuote:
@@@scale out 50%of the position, when the trade reaches an xammount of pipps...
This code may be useful for that:
viewtopic.php?f=65&t=12283&p=16486&hilit=+partial+close+#p16486