when the RSI crosses above the upperband, we send an enterlong stop order 10 ticks above the closing price of this bar. If the RSI crosses below the lowerband, we send an entershort stop order 10 ticks below.
As I said, it works fine without the target, but when I set a profit target, it ignores the reversing order until the price reaches the target.
For example, the RSI crosses above the upperband and the price reaches the stop, so we are long and ninja submits the profit target order, 100 ticks above.
If the price reaches the target there is no problem.
But if the the RSI crosses below the lowerband before the price reaches the target (so ninja should cancel the target and submit an entershort stop) then ninja does nothing. It ignores the signal until the target get filled.
Do you know what’s wrong?
Thank you very much
Here is the code:
{
Add(RSI(14, 3));
Add(RSI(14, 3));
Add(RSI(14, 3));
SetProfitTarget("",CalculationMode.Ticks, 100);
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (CrossAbove(RSI(14, 3).Avg, Upperband, 1))
{
Variable0 = Close[0] + 10 * TickSize;
Timetobuy = true;
}
// Condition set 2
if (CrossBelow(RSI(14, 3).Avg, Lowerband, 1))
{
Variable1 = Close[0] - 10 * TickSize;
Timetosell = true;
}
// Condition set 3
if (RSI(14, 3).Avg[0] > Upperband
&& Timetobuy == true)
{
EnterLongStop(DefaultQuantity, Variable0, "");
}
// Condition set 4
if (RSI(14, 3).Avg[0] < Lowerband
&& Timetosell == true)
{
EnterShortStop(DefaultQuantity, Variable1, "");
}
// Condition set 5
if (RSI(14, 3).Avg[0] > Upperband
&& Position.MarketPosition == MarketPosition.Long)
{
Timetobuy=false;
}
// Condition set 6
if (RSI(14, 3).Avg[0] < Lowerband
&& Position.MarketPosition == MarketPosition.Short)
{
Timetosell=false;
}

Comment