#property copyright "TEST"
\#property link "https://www.mql5.com"
\#property version "1.00"
\#property strict
// Define input parameters
input int TradeType = OP_SELL;
input double LotSize = 0.01;
input double StopLoss = 20;
input double TakeProfit = 200;
input double TrailingStop = 5;
// Define global variables
int ticket = 0;
double trailing_stop;
bool is_sell = false;
void OnTick()
{
// Calculate CCI values
double cci1 = iCCI(\_Symbol, PERIOD_M1, 3, PRICE_TYPICAL, 0);
double cci2 = iCCI(\_Symbol, PERIOD_M1, 14, PRICE_TYPICAL, 0);
double cci3 = iCCI(\_Symbol, PERIOD_M1, 21, PRICE_TYPICAL, 0);
double cci4 = iCCI(\_Symbol, PERIOD_M1, 40, PRICE_TYPICAL, 0);
// Check if all CCI values are above/below the threshold
bool all_above_50 = (cci1 \> 50) && (cci2 \> 50) && (cci3 \> 50) && (cci4 \> 50);
bool all_below_minus_50 = (cci1 \< -50) && (cci2 \< -50) && (cci3 \<
-50) && (cci4 \< -50);
// Check if there is an open position
if (ticket == 0)
{
if (all_below_minus_50 && !is_sell)
{
// Place multiple sell orders
for (int i = 0; i \< 10; i++)
{
ticket = OrderSend(\_Symbol, TradeType, LotSize, Bid, 3, Ask + StopLoss \* Point, Ask - TakeProfit \* Point, "Successful = " + "😃");
if (ticket \> 0)
{
// Update global variables
is_sell = true;
trailing_stop = Bid - TrailingStop \* Point; // Initialize trailing_stop
Alert("Sell order executed with ticket number ", ticket);
}
else
{
// Print a message to the Experts tab in the Terminal
Alert("Order Send Error = " + "??", ticket);
}
}
}
else if (all_above_50 && is_sell)
{
// Close the sell position
OrderClose(ticket, LotSize, Bid, 3, Yellow);
// Reset global variables
ticket = 0;
is_sell = false;
Alert("Sell position closed with ticket number ", ticket);
}
}
else
{
// Check the status of the open position
if (OrderSelect(ticket, SELECT_BY_TICKET))
{
if (OrderCloseTime() == 0)
{
// Enforce hard stop
double hard_stop_loss = OrderOpenPrice() + StopLoss \* Point;
// Update the trailing stop
trailing_stop = MathMin(trailing_stop, OrderOpenPrice() - TrailingStop \* Point);
Print("Trailing stop: ", trailing_stop);
if (OrderOpenPrice() - Bid \> TakeProfit \* Point)
{
// Close the sell position
OrderClose(ticket, LotSize, Bid, 3, Yellow);
// Reset global variables
ticket = 0;
is_sell = false;
Alert("Sell position closed with ticket number ", ticket);
}
else if (Bid \<= trailing_stop || Bid \<= hard_stop_loss)
{
// Move the trailing stop
trailing_stop = MathMax(OrderOpenPrice() - TrailingStop \* Point, hard_stop_loss);
Print("Trailing stop: ", trailing_stop);
OrderModify(ticket, OrderOpenPrice(), trailing_stop, OrderTakeProfit(), 0, Yellow);
}
}
else
{
// Reset global variables
ticket = 0;
is_sell = false;
}
}
}
嗨,这是我的 EA,我的追踪止损不起作用,这是平台代码的问题吗,这是我的 C++ 代码,运行代码时一切正常,但追踪止损不起作用