for (IndDataAndFeed indDataAndFeed : calculatableIndicators) {
double value = indDataAndFeed.getCurrentValue();
i = i + 1;
if (i == 1) {
macdd = value;
}
if (i == 2) {
rsim = value;
}
if (i == 3) {
rsih = value;
}
if (i == 4) {
cciq = value;
print("cci 15 minutes =%s", cciq);
}
if (i == 5) {
ccih = value;
print("cci 1 heure =%s", ccih);
}
if (i == 6) {
ccic = value;
print("cci 5 minutes =%s", ccic);
}
if (cciq > 100 && ccih > 100 && ccic > 100
&& engine.getOrder("abuy") == null) {
engine.submitOrder("abuy", instrument, OrderCommand.BUY, 100);
w = 300;
}
if (cciq < -100 && ccih < -100 && ccic < -100
&& engine.getOrder("asell") == null) {
engine.submitOrder("asell", instrument, OrderCommand.SELL, 100);
w = 400;
}
if (engine.getOrder("abuy") != null && ccic < -100) {
engine.getOrder("abuy").close();
engine.getOrder("abuy").waitForUpdate(IOrder.State.CLOSED);
}
if (engine.getOrder("asell") != null && ccic > 100) {
engine.getOrder("asell").close();
engine.getOrder("asell").waitForUpdate(IOrder.State.CLOSED);
}
}
I see your coding is quite not right.
1. you have engine.xxx() inside loop block, It should be outside.
2. you need to verify if there is opened positition
BEFORE submitting your order.
Ie: If (ccic < -100) you want close long position but you already opened short position.
From your code it's look like there is possibilities to submit multiple order --problematic--.
3. use unique label is better than "abuy" or "asell"
It works on demo or backtesting because there's no constrain on a number of opened position.
On contest you can only have one opened position.