//Here is my buy logic..
if(Position.MarketPosition == MarketPosition.Flat && currentTime >= TradeStartTime && currentTime <= TradeEndTime && !isTradeOn && isUptrend)
{
isTradeOn = true;
if(NumOfContractTpTwo == 0)
{
string orderName = $"LongEntry";
EnterLong(NumOfContractTpOne, orderName);
SetProfitTarget(orderName, CalculationMode.Ticks, TakeProfitTicksContract1);
SetStopLoss(orderName, CalculationMode.Ticks, StopLossTicks, false);
}
if(NumOfContractTpTwo >= 1)
{
for (int i = 1; i <= 2; i++)
{
string orderName = $"LongEntry{i}";
int numOfContracts = i == 1 ? NumOfContractTpOne : NumOfContractTpTwo;
EnterLong(numOfContracts, orderName);
SetStopLoss(orderName, CalculationMode.Ticks, StopLossTicks, false);
double takeProfitTicks = i == 1 ? TakeProfitTicksContract1 : TakeProfitTicksContract2;
SetProfitTarget(orderName, CalculationMode.Ticks, takeProfitTicks);
}
}
}
When TP 1 is hit I want to adjust my stop loss.
I am using the below method to look to see when TP1 is hit and then it shoud readjust.
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
// Check if the TP1 order is filled
if ((order.Name == "LongEntry1" || order.Name == "ShortEntry1") && order.OrderState == OrderState.Filled)
{
// Retrieve the average fill price of the entry order
double entryPrice = order.AverageFillPrice;
if (order.Name == "LongEntry1")
{
double ticksToBreakEven = (entryPrice - Close[0]) / TickSize;
SetStopLoss("LongEntry2", CalculationMode.Price, entryPrice, false);
Print("Moving Stop Loss for LongEntry2 to Break Even: " + entryPrice);
}
else if (order.Name == "ShortEntry1")
{
// Similarly, for 'ShortEntry2'
double ticksToBreakEven = (Close[0] - entryPrice) / TickSize;
SetStopLoss("ShortEntry2", CalculationMode.Price, entryPrice, false);
Print("Moving Stop Loss for ShortEntry2 to Break Even: " + entryPrice);
}
}
}
Anythoughts why this wouldnt be working?
Thanks,
Greg
Everything prints correctly but its not moving my stop loss =-(
Comment