I tried two constructions:
first with exits and enters:
//exit: short
if (Portfolio[symbol].IsShort) {
if (price > (bb.UpperBand * (1+tolerance)) && rsi > 70) {
Liquidate(symbol);
}
}
//exit: long
if (Portfolio[symbol].IsLong) {
if (price < (bb.LowerBand * (1+tolerance)) && rsi < 30) {
Liquidate(symbol);
}
}
//long
if (!Portfolio.HoldStock) {
if (price < (bb.LowerBand * (1+tolerance)) && rsi < 30) {
LimitOrder(symbol, Math.Abs(holdings) + quantity, high);
}
}
//short
if (!Portfolio.HoldStock) {
if (price > (bb.UpperBand * (1+tolerance)) && rsi > 70) {
LimitOrder(symbol, -(Math.Abs(holdings) + quantity), low);
}
}
and second:
if (holdings > 0 || holdings == 0) {
if (price > (bb.UpperBand * (1+tolerance)) && rsi > 70 ) {
LimitOrder(symbol, -(holdings + quantity), low);
}
} else if (holdings < 0 || holdings == 0) {
if (price < (bb.LowerBand * (1+tolerance)) && rsi < 30) {
LimitOrder(symbol, Math.Abs(holdings) + quantity, high);
}
}
So, why do I get different results? Where is the problem with my logic? Is there any template for enters and exits? Thank you for attention.