我用NewBing写了一段MT5代码,结果报错20多处,大神帮帮忙,我不会改了 新评论 kanicell 2023.06.06 05:45 我的要求是这的:9日均线上穿25日均线,全部平仓然后做多;下穿,全部平仓然后做空. 但是gpt写出来的mt5代码有很多是mt4里的内容. 可是我把这些代码放到mt4里面,结果报错更多了. 我把报错标出来,大神帮帮忙这个要怎么改,拜托拜托 //+------------------------------------------------------------------+ //| SimpleEA.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict input int FastMA = 9; // Fast moving average period input int SlowMA = 25; // Slow moving average period input double LotSize = 0.05; // Lot size per trade input int TakeProfit = 1500; // Take profit in points input int StopLoss = 500; // Stop loss in points double fast_ma[]; double slow_ma[]; int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,fast_ma); SetIndexBuffer(1,slow_ma); //--- return(INIT_SUCCEEDED); } void OnTick() { //--- calculate moving averages fast_ma[0] = iMA(_Symbol,_Period,FastMA,0,MODE_EMA,PRICE_CLOSE,0); //系统提示"wrong parament count" slow_ma[0] = iMA(_Symbol,_Period,SlowMA,0,MODE_EMA,PRICE_CLOSE,0); //系统提示"wrong parament count" //--- check for crossover signals if(fast_ma[0] > slow_ma[0] && fast_ma[1] < slow_ma[1]) // bullish crossover { CloseAll(); // close all orders OpenBuy(); // open a buy order } if(fast_ma[0] < slow_ma[0] && fast_ma[1] > slow_ma[1]) // bearish crossover { CloseAll(); // close all orders OpenSell(); // open a sell order } } //+------------------------------------------------------------------+ //| Custom function to open a buy order | //+------------------------------------------------------------------+ void OpenBuy() { double price = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); // get the ask price double sl = price - StopLoss*_Point; // calculate the stop loss price double tp = price + TakeProfit*_Point; // calculate the take profit price MqlTradeRequest request; MqlTradeResult result; request.action = TRADE_ACTION_DEAL; // immediate execution request.symbol = _Symbol; // symbol request.volume = LotSize; // volume in lots request.type = ORDER_TYPE_BUY; // order type request.price = price; // price request.sl = sl; // stop loss request.tp = tp; // take profit request.deviation = 10; // deviation in points request.magic = 12345; // magic number request.comment = "Buy order"; // comment if(!OrderSend(request,result)) // send the order { Print("OrderSend failed with error #",GetLastError()); // print the error message } } //+------------------------------------------------------------------+ //| Custom function to open a sell order | //+------------------------------------------------------------------+ void OpenSell() { double price = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); // get the bid price double sl = price + StopLoss*_Point; // calculate the stop loss price double tp = price - TakeProfit*_Point; // calculate the take profit price MqlTradeRequest request; MqlTradeResult result; request.action = TRADE_ACTION_DEAL; // immediate execution request.symbol = _Symbol; // symbol request.volume = LotSize; // volume in lots request.type = ORDER_TYPE_SELL; // order type request.price = price; // price request.sl = sl; // stop loss request.tp = tp; // take profit request.deviation = 10; // deviation in points request.magic = 12345; // magic number request.comment = "Sell order"; // comment if(!OrderSend(request,result)) // send the order { Print("OrderSend failed with error #",GetLastError()); // print the error message } } //+------------------------------------------------------------------+ //| Custom function to close all orders | //+------------------------------------------------------------------+ void CloseAll() { for(int i = OrdersTotal()-1; i >= 0; i--) // loop through all orders { if(OrderSelect(i,SELECT_BY_POS)) // select the order by position //前面的提示wrong parament count;后面的提示undeclared indentifier { if(OrderSymbol() == _Symbol && OrderMagicNumber() == 12345) // check the symbol and magic number // 提示undeclared indentifier { if(OrderType() == ORDER_TYPE_BUY) // if it is a buy order // 提示cannot convert enum { double price = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); // get the bid price MqlTradeRequest request; MqlTradeResult result; request.action = TRADE_ACTION_DEAL; // immediate execution request.symbol = _Symbol; // symbol request.volume = OrderLots(); // volume in lots // 提示undeclared indentifier request.type = ORDER_TYPE_SELL; // order type request.position = OrderTicket(); // position ticket // 提示undeclared indentifier request.price = price; // price request.deviation = 10; // deviation in points request.magic = 12345; // magic number request.comment = "Close buy order"; // comment if(!OrderSend(request,result)) // send the order { Print("OrderSend failed with error #",GetLastError()); // print the error message } } if(OrderType() == ORDER_TYPE_SELL) // if it is a sell order // 提示undeclared indentifier { double price = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); // get the ask price MqlTradeRequest request; MqlTradeResult result; request.action = TRADE_ACTION_DEAL; // immediate execution request.symbol = _Symbol; // symbol request.volume = OrderLots(); // volume in lots // 提示undeclared indentifier request.type = ORDER_TYPE_BUY; // order type request.position = OrderTicket(); // position ticket // 提示undeclared indentifier request.price = price; // price request.deviation = 10; // deviation in points request.magic = 12345; // magic number request.comment = "Close sell order"; // comment if(!OrderSend(request,result)) // send the order { Print("OrderSend failed with error #",GetLastError()); // print the error message } } } } } } //+------------------------------------------------------------------+ Discover new MetaTrader 5 opportunities with MQL5 community and services 2023.06.06www.mql5.com MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions Errors, bugs, questions Questions from a "dummy" How to close an order in MT5? James.LH 2023.06.07 07:20 #1 gpt会自己瞎编函数,这种简单的示例功能最好自己对照手册慢慢来,或者下载代码库里的范例教学,这么一股脑生成个代码啥也学不会,只能是玩具 kanicell 2023.06.08 11:12 #2 James.LH #: gpt会自己瞎编函数,这种简单的示例功能最好自己对照手册慢慢来,或者下载代码库里的范例教学,这么一股脑生成个代码啥也学不会,只能是玩具 是了,gpt把mq4的东西拿过来啥也不管就乱用.谢谢~ James.LH 2023.06.08 17:16 #3 慢慢学吧朋友,坑很多,准备两年以上时间 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
我的要求是这的:9日均线上穿25日均线,全部平仓然后做多;下穿,全部平仓然后做空.
但是gpt写出来的mt5代码有很多是mt4里的内容.
可是我把这些代码放到mt4里面,结果报错更多了.
我把报错标出来,大神帮帮忙这个要怎么改,拜托拜托
//+------------------------------------------------------------------+