我用AI寫了個策略
有沒有大神可以幫我看看哪裡有問題導致無法運行
編碼如下....
//設定參數
extern int TradeHourStart = 8; //開始交易時間
extern int TradeHourEnd = 22; //結束交易時間
extern double StopLoss = 100.0; //設置止損點數
extern double TakeProfit = 100.0; //設置止盈點數
extern double LotSize = 0.1; //開倉手數
extern int MagicNumber = 12345; //用於標識此EA的魔術數字
//設定變量
bool bStrategy1 = true; //使用策略1還是策略2的標誌
bool bHasOpenPosition = false; //是否有持倉
double dOpenPrice = 0.0; //開倉價格
double dTargetPrice = 0.0; //收益目標價格
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnTick()
{
double currentPrice = MarketInfo(Symbol(), MODE_LAST); //當前價格
int tradeHour = TimeHour(TimeLocal()); //當前時間的小時數
int lastTradeHour = TimeHour(TimeLocal() - Period() * 60); //上一根K線的時間的小時數
//開啟策略1的交易
if(bStrategy1 && tradeHour >= TradeHourStart && tradeHour < TradeHourEnd && !bHasOpenPosition)
{
int ticketBuy = OrderSend(Symbol(), OP_BUY, LotSize, currentPrice, 3, currentPrice - StopLoss * Point, currentPrice + TakeProfit * Point, "Strategy 1: Buy", MagicNumber, 0, Green);
int ticketSell = OrderSend(Symbol(), OP_SELL, LotSize, currentPrice, 3, currentPrice + StopLoss * Point, currentPrice - TakeProfit * Point, "Strategy 1: Sell", MagicNumber, 0, Red);
if(ticketBuy > 0)
{
Print("Strategy 1: Buy order opened at ", currentPrice);
bHasOpenPosition = true;
dOpenPrice = currentPrice;
dTargetPrice = dOpenPrice + TakeProfit * Point;
}
else
{
Print("Error opening buy order: ", GetLastError());
}
if(ticketSell > 0)
{
Print("Strategy 1: Sell order opened at ", currentPrice);
bHasOpenPosition = true;
dOpenPrice = currentPrice;
dTargetPrice = dOpenPrice - TakeProfit * Point;
}
else
{
Print("Error opening sell order: ", GetLastError());
}
}
//開啟策略2的交易
if(!bStrategy1 && lastTradeHour < TradeHourStart && tradeHour >= TradeHourStart && !bHasOpenPosition)
{
int ticketBuy = OrderSend(Symbol(), OP_BUY, LotSize, currentPrice, 3, currentPrice - StopLoss * Point, currentPrice + TakeProfit * Point, "Strategy 2: Buy", MagicNumber, 0, Green);
int ticketSell = OrderSend(Symbol(), OP_SELL, LotSize, currentPrice, 3, currentPrice + StopLoss
|