Hello,
I want to sell all open positions in profit if price touch any Daily pivot line. My strategy works OnBar and i use OnTick to exit. My code has no compilation error but doesn't exit the winning positions.
Any suggestion to correct the problem ?
Thanks for any help...
public void onTick(Instrument instrument, ITick tick) throws JFException {
IBar DpivotBar = history.getBar(instrument, Period.DAILY_SUNDAY_IN_MONDAY, offerSide, 1);
IBar WpivotBar = history.getBar(instrument, Period.WEEKLY, offerSide, 1);
IBar MpivotBar = history.getBar(instrument, Period.MONTHLY, offerSide, 1);
double bid = history.getLastTick(instrument).getBid();
double ask = history.getLastTick(instrument).getAsk();
double DP = getPivotPrice(Pivot.P, DpivotBar);
double DS1 = getPivotPrice(Pivot.S1, DpivotBar);
double DS2 = getPivotPrice(Pivot.S2, DpivotBar);
double DS3 = getPivotPrice(Pivot.S3, DpivotBar);
double DR1 = getPivotPrice(Pivot.R1, DpivotBar);
double DR2 = getPivotPrice(Pivot.R2, DpivotBar);
double DR3 = getPivotPrice(Pivot.R3, DpivotBar);
if (bid == DS3 || bid == DS2 || bid == DS1 || bid == DP|| bid == DR1|| bid == DR2 || bid == DR3 ) {
for (IOrder ord : engine.getOrders(instrument)) {
if(order.getProfitLossInPips() >= 0) {
closeAllPositions();
}
}
}
}