Hi,
I am no coder and I need help. I used ChatGPT to generate MT5 EA code to set Automatic SL (5 pips )and partial TP ( 50% of the trade size at 10 Pips ), However when i try to compile the code it is giving errors.
I appreciate if anyone can help me here to fix the issue.
Here is the code.
//#property copyright "Copyright 2023, OpenAI"
//#property version "1.00"
//#property expert "Stop Loss and Partial Take Profit EA"
input double TakeProfit = 10.0; // take profit distance from entry
input double StopLoss = 5.0; // stop loss distance from entry
void OnTick()
{
double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
if (OrderSelect(OrderTicket(), SELECT_BY_TICKET))
{
if (OrderType() != OP_SELL && OrderType() != OP_BUY)
return;
// only set SL and TP for manual orders
if(OrderMagicNumber() == 0)
{
double partial_tp_level = OrderOpenPrice() + (TakeProfit*Point) * (OrderLots()/2);
OrderModify(OrderTicket(), OrderOpenPrice(), partial_tp_level, OrderOpenPrice() - StopLoss*Point, 0, Blue);
}
}
}
I am no coder and I need help. I used ChatGPT to generate MT5 EA code to set Automatic SL (5 pips )and partial TP ( 50% of the trade size at 10 Pips ), However when i try to compile the code it is giving errors.
I appreciate if anyone can help me here to fix the issue.
Here is the code.
//#property copyright "Copyright 2023, OpenAI"
//#property version "1.00"
//#property expert "Stop Loss and Partial Take Profit EA"
input double TakeProfit = 10.0; // take profit distance from entry
input double StopLoss = 5.0; // stop loss distance from entry
void OnTick()
{
double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
if (OrderSelect(OrderTicket(), SELECT_BY_TICKET))
{
if (OrderType() != OP_SELL && OrderType() != OP_BUY)
return;
// only set SL and TP for manual orders
if(OrderMagicNumber() == 0)
{
double partial_tp_level = OrderOpenPrice() + (TakeProfit*Point) * (OrderLots()/2);
OrderModify(OrderTicket(), OrderOpenPrice(), partial_tp_level, OrderOpenPrice() - StopLoss*Point, 0, Blue);
}
}
}