I've perused the forum but couldn't find an answer to my problem so sorry if it exists already and the double question.
using the NT8 script, I am able to enter the market, but placing and SL and TP1/TP2 arent being placed.
any help would be appreciated.
if (IsValidBullishPinBar(ema8, ema20, ema50) && CheckSlopeConditions(ema50, ema20, ema8, EmaSlopeThreshold))
{
Draw.ArrowUp(this, "Bull_PinBar_" + CurrentBar, true, 0, Low[0], Brushes.Yellow);
// Define SL and TP levels
double stopLossPrice = Low[0] - 1 * atrValue; // SL 1x ATR below the low of the bar
double tp1Price = Close[0] + TakeProfit1Ratio * atrValue; // TP1 level
double tp2Price = Close[0] + TakeProfit2Ratio * atrValue; // TP2 level
// Split the position for TP1 and TP2
int firstPositionSize = Convert.ToInt32(Math.Floor(PositionSize / 2.0)); // Cast to Int32
int secondPositionSize = Convert.ToInt32(PositionSize - firstPositionSize); // Remaining for TP2
// Enter the long position with the full size
EnterLong(Convert.ToInt32(PositionSize), "Bull_Entry_" + CurrentBar); // Cast to Int32 with unique entry name
// Print order details for debugging
Print("Entering Long for Bullish Pin Bar at price: " + Close[0]);
Print("SL: " + stopLossPrice + " TP1: " + tp1Price + " TP2: " + tp2Price);
}
// For Bearish Pin Bars - Enter SHORT position and manage SL, TP1, and TP2
if (IsValidBearishPinBar(ema8, ema20, ema50) && CheckSlopeConditions(ema50, ema20, ema8, EmaSlopeThreshold))
{
Draw.ArrowDown(this, "Bear_PinBar_" + CurrentBar, true, 0, High[0], Brushes.Red);
// Define SL and TP levels
double stopLossPrice = High[0] + 1 * atrValue; // SL 1x ATR above the high of the bar
double tp1Price = Close[0] - TakeProfit1Ratio * atrValue; // TP1 level
double tp2Price = Close[0] - TakeProfit2Ratio * atrValue; // TP2 level
// Split the position for TP1 and TP2
int firstPositionSize = Convert.ToInt32(Math.Floor(PositionSize / 2.0)); // Cast to Int32
int secondPositionSize = Convert.ToInt32(PositionSize - firstPositionSize); // Remaining for TP2
// Enter the short position with the full size
EnterShort(Convert.ToInt32(PositionSize), "Bear_Entry_" + CurrentBar); // Cast to Int32 with unique entry name
// Print order details for debugging
Print("Entering Short for Bearish Pin Bar at price: " + Close[0]);
Print("SL: " + stopLossPrice + " TP1: " + tp1Price + " TP2: " + tp2Price);
}
}
// OnPositionUpdate: Handles SL and TP1/TP2 once the entry is confirmed
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, MarketPosition marketPosition)
{
// If a Long position is confirmed
if (marketPosition == MarketPosition.Long && position.Quantity == PositionSize)
{
double stopLossPrice = Low[0] - 1 * atrValue; // SL recalculated
double tp1Price = averagePrice + TakeProfit1Ratio * atrValue; // Recalculate TP1
double tp2Price = averagePrice + TakeProfit2Ratio * atrValue; // Recalculate TP2
int firstPositionSize = Convert.ToInt32(Math.Floor(PositionSize / 2.0)); // Half position for TP1
int secondPositionSize = Convert.ToInt32(PositionSize - firstPositionSize); // Other half for TP2
// Place stop-loss and profit target orders after position is confirmed
SetStopLoss("Bull_Entry_SL_" + CurrentBar, CalculationMode.Price, stopLossPrice, false);
SetProfitTarget("Bull_Entry_TP1_" + CurrentBar, CalculationMode.Price, tp1Price); // TP1 for first half
SetProfitTarget("Bull_Entry_TP2_" + CurrentBar, CalculationMode.Price, tp2Price); // TP2 for second half
// Print debugging information
Print("SL placed at: " + stopLossPrice + " TP1 at: " + tp1Price + " TP2 at: " + tp2Price + " for Long position");
}
// If a Short position is confirmed
else if (marketPosition == MarketPosition.Short && position.Quantity == PositionSize)
{
double stopLossPrice = High[0] + 1 * atrValue; // SL recalculated
double tp1Price = averagePrice - TakeProfit1Ratio * atrValue; // Recalculate TP1
double tp2Price = averagePrice - TakeProfit2Ratio * atrValue; // Recalculate TP2
int firstPositionSize = Convert.ToInt32(Math.Floor(PositionSize / 2.0)); // Half position for TP1
int secondPositionSize = Convert.ToInt32(PositionSize - firstPositionSize); // Other half for TP2
// Place stop-loss and profit target orders after position is confirmed
SetStopLoss("Bear_Entry_SL_" + CurrentBar, CalculationMode.Price, stopLossPrice, false);
SetProfitTarget("Bear_Entry_TP1_" + CurrentBar, CalculationMode.Price, tp1Price); // TP1 for first half
SetProfitTarget("Bear_Entry_TP2_" + CurrentBar, CalculationMode.Price, tp2Price); // TP2 for second half
// Print debugging information
Print("SL placed at: " + stopLossPrice + " TP1 at: " + tp1Price + " TP2 at: " + tp2Price + " for Short position");
}
}

Comment