Thanks for comment. It appears that I've got that logic wrong. I just created a dummy strategy to check what you are saying and - yes, you are correct.
- Actual trailing SL is the difference (PRICE - SL PRICE) at the moment when trailing SL was created
- Server updates SL at the provided interval of pips (10+ pips), it is not the trailing SL
(All this is unnatural to me
- I see that 'trailing step' parameter absolutely useless and misleading, i see no reason someone will set it higher than 10pips and therefore it is more a boolean parameter - "use TSL with 10pips increments" or "do not user TSL")
Here sample strategy and its output for reference (I assume LIVE/DEMO works with the same logic as historical tester):
@Override
public void onStart(IContext context) throws JFException {
this.context = context;
o = context.getEngine().submitOrder("Test_TSL", EURUSD, BUYLIMIT,
/* amount */ 0.1,
/* price */ 1.181,
/* slippage */ 10,
/* stop-loss */ 0,
/* take-profit */ 1.191);
}
@Override public void onMessage(IMessage message) throws JFException {
IOrder o = message.getOrder();
switch( message.getType() ) {
case ORDER_FILL_OK:
info("" + message);
info(String.format("set tsl(price: %.5f, side: %s, pips: %s)",
o.getOpenPrice() - 15 * pip, OfferSide.BID, 25));
o.setStopLossPrice(o.getOpenPrice() - 15 * pip, OfferSide.BID, 25); <-- SL is 15 pips below, TSL: is 25 pips
oldSL = o.getStopLossPrice();
break;
case ORDER_CHANGED_OK:
double newSL = o.getStopLossPrice();
double slStep = oldSL == 0 ? 0 : (newSL - oldSL) / pip;
double priceToSL = (lastTick.getBid() - newSL) / pip;
info(String.format("%s, SL: %s, SL step: %.1f ---- Cur.price: %s, price-to-sl: %.1f pips",
message, newSL, slStep, lastTick.getBid(), priceToSL));
oldSL = newSL;
break;
}
}
Output, printed in reverse order: SL is updated each 25 pips, actual TSL ~= 15 pips.
Executed for EURUSD at 2017-11-30
ORDER_CHANGED_OK - Stop loss price changed order: FILLED BUY 0.1 @ 1.18097, SL: 1.1895, SL step: 25.1 ---- Cur.price: 1.19096, price-to-sl: 14.6 pips
ORDER_CHANGED_OK - Stop loss price changed order: FILLED BUY 0.1 @ 1.18097, SL: 1.18699, SL step: 25.1 ---- Cur.price: 1.18845, price-to-sl: 14.6 pips
ORDER_CHANGED_OK - Stop loss price changed order: FILLED BUY 0.1 @ 1.18097, SL: 1.18448, SL step: 25.1 ---- Cur.price: 1.18594, price-to-sl: 14.6 pips
ORDER_CHANGED_OK - Stop loss price changed order: FILLED BUY 0.1 @ 1.18097, SL: 1.18197, SL step: 25.0 ---- Cur.price: 1.18343, price-to-sl: 14.6 pips
ORDER_CHANGED_OK - Stop loss condition changed order: FILLED BUY 0.1 @ 1.18097, SL: 1.17947, SL step: 0.0 ---- Cur.price: 1.18093, price-to-sl: 14.6 pips
set tsl(price: 1.17947, side: Bid, pips: 25)
ORDER_FILL_OK - Order filled order: FILLED BUY 0.1 @ 1.18097