I am trying to add to a position for the second time. I copied the code that works well for the first increase and thought I could just adjust it a little bit and it will also work for the second one.
Unfortunately it does not. And it looks to me like it is simply ignoring some conditions in the if statement. The script is calculated OnPriceChange
if (Position.MarketPosition == MarketPosition.Short
&& secondAddOnDirectEntryPoint > 0
&& secondAddOnPullbackEntryPoint == 0
&& Close[0] <= (initialEntryPrice - (secondAddOnDirectEntryPoint * TickSize))
&& isSecondAdd == false
&& isFirstAdd == true || isFirstAddOnPullback == true)
{
//Print("-----------------------------------------------------------------------------");
//Print("isSecondAdd");
//Print(isSecondAdd.ToString());
isSecondAdd = true;
//Print("secondAddOnDirectEntryPoint (76)");
//Print(secondAddOnDirectEntryPoint.ToString());
//Print("secondAddOnPullbackEntryPoint (0)");
//Print(secondAddOnPullbackEntryPoint.ToString());
//Print("Close (0)");
//Print(Close[0].ToString());
//Print("initialEntryPrice");
//Print(initialEntryPrice.ToString());
//Print("initialEntryPrice - (secondAddOnDirectEntryPoint * TickSize)");
//var test = (initialEntryPrice - (secondAddOnDirectEntryPoint * TickSize));
//Print(test.ToString());
EnterShort(Convert.ToInt32(DefaultQuantity * 2), "Addon two"); //3rd Entry
SetStopLoss(CalculationMode.Price, initialEntryPrice - (secondAddOnStopSave * TickSize));
SetProfitTarget(CalculationMode.Price, takeProfitPrice);
isSecondAddOnLevelMet = true;
return;
}
I printed all of the values to the output window. Clearly Close[0] is not <= (initialEntryPrice - (secondAddOnDirectEntryPoint * TickSize)) when the entry happens.
But for some reason it ignores this and places the entry at the same price and at the same time where and when already the earlier entry took place?
Also I do not understand why it is printing several times because after isSecondAdd = true, it should not execute again, since the Boolean expression at least then evaluates to false.
Any help is very much appreciated!
Thank you


Comment