听起来你已经意识到,编码是容易的部分......可以教你如何编码,什么是变量类型,什么是代码语法......但你在这里问的是解决问题。 这就更难教了......。
我可以给你的最好建议是写下你想做的事情 ...... 然后写下你在手动交易时如何做 ...... 然后一步步扩展,就像你在向一个完全陌生的MT4新手展示一样 ...... 然后你就会有一些可以编码的东西。
好吧,我就这么做。
谢谢你的建议。 这肯定会是一次冒险。
好的,我已经用以下方法解决了沿前一栏的方向开盘的问题
(Bar 1 Close > Bar 1 Open; OP_BUY)
(Bar 1 Close < Bar 1 Open; OP_SELL)
现在我想知道,是否有一个代码用于在前一个订单关闭时开仓?
好的,我已经用以下方法解决了沿前一栏的方向开盘的问题
(Bar 1 Close > Bar 1 Open; OP_BUY)
(Bar 1 Close < Bar 1 Open; OP_SELL)
现在我想知道,是否有一个代码用于在前一个订单关闭时开仓?
这不可能是你在mq4中的写法
你不需要怀疑是否有在前一个订单收盘时开仓的代码。
你只需要知道如何去做...
您需要在您的订单历史中找到您的EA的最后一笔平仓交易,然后查看其订单开盘价、订单平仓价和订单类型。
谢谢你。
我只是需要一些线索来确定我的正确方向,而你所提供的信息可能会对我有帮助。
好的,这是我在专家顾问生成器网站上生成的代码,用于开启第一笔交易。
//+------------------------------------------------------------------+ //| This MQL is generated by Expert Advisor Builder | //| http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ | //| | //| In no event will author be liable for any damages whatsoever. | //| Use at your own risk. | //| | //+------------------- DO NOT REMOVE THIS HEADER --------------------+
#define SIGNAL_NONE 0 #define SIGNAL_BUY 1 #define SIGNAL_SELL 2 #define SIGNAL_CLOSEBUY 3 #define SIGNAL_CLOSESELL 4
#property copyright "Expert Advisor Builder" #property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"
extern int MagicNumber = 0; extern bool SignalMail = False; extern bool EachTickMode = True; extern double Lots = 0.01; extern int Slippage = 3; extern bool UseStopLoss = False; extern int StopLoss = 30; extern bool UseTakeProfit = False; extern int TakeProfit = 60; extern bool UseTrailingStop = True; extern int TrailingStop = 30;
int BarCount; int Current; bool TickCheck = False; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int Order = SIGNAL_NONE; int Total, Ticket; double StopLossLevel, TakeProfitLevel;
if (EachTickMode && Bars != BarCount) TickCheck = False; Total = OrdersTotal(); Order = SIGNAL_NONE;
//+------------------------------------------------------------------+ //| Variable Begin | //+------------------------------------------------------------------+
double Buy1_1 = iClose(NULL, 0, Current + 1); double Buy1_2 = iOpen(NULL, 0, Current + 1);
double Sell1_1 = iClose(NULL, 0, Current + 1); double Sell1_2 = iOpen(NULL, 0, Current + 1);
//+------------------------------------------------------------------+ //| Variable End | //+------------------------------------------------------------------+
//Check position bool IsTrade = False;
for (int i = 0; i < Total; i ++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) { IsTrade = True; if(OrderType() == OP_BUY) { //Close
//+------------------------------------------------------------------+ //| Signal Begin(Exit Buy) | //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| Signal End(Exit Buy) | //+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) { OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen); if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy"); if (!EachTickMode) BarCount = Bars; IsTrade = False; continue; } //Trailing stop if(UseTrailingStop && TrailingStop > 0) { if(Bid - OrderOpenPrice() > Point * TrailingStop) { if(OrderStopLoss() < Bid - Point * TrailingStop) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen); if (!EachTickMode) BarCount = Bars; continue; } } } } else { //Close
//+------------------------------------------------------------------+ //| Signal Begin(Exit Sell) | //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| Signal End(Exit Sell) | //+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) { OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange); if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell"); if (!EachTickMode) BarCount = Bars; IsTrade = False; continue; } //Trailing stop if(UseTrailingStop && TrailingStop > 0) { if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) { if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange); if (!EachTickMode) BarCount = Bars; continue; } } } } } }
//+------------------------------------------------------------------+ //| Signal Begin(Entry) | //+------------------------------------------------------------------+
if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;
if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;
//+------------------------------------------------------------------+ //| Signal End | //+------------------------------------------------------------------+
//Buy if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) { if(!IsTrade) { //Check free margin if (AccountFreeMargin() < (1000 * Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); }
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0; if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue); if(Ticket > 0) { if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) { Print("BUY order opened : ", OrderOpenPrice()); if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy"); } else { Print("Error opening BUY order : ", GetLastError()); } } if (EachTickMode) TickCheck = True; if (!EachTickMode) BarCount = Bars; return(0); } }
//Sell if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) { if(!IsTrade) { //Check free margin if (AccountFreeMargin() < (1000 * Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); }
if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0; if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink); if(Ticket > 0) { if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) { Print("SELL order opened : ", OrderOpenPrice()); if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell"); } else { Print("Error opening SELL order : ", GetLastError()); } } if (EachTickMode) TickCheck = True; if (!EachTickMode) BarCount = Bars; return(0); } }
if (!EachTickMode) BarCount = Bars;
return(0); } //+------------------------------------------------------------------+ And this is a loop that's been suggested to me that I'd like to add but am unsure of where to apply it. for(int i=0;i < OrdersHistoryTotal() ;i++) { OrderSelect(i, SELECT_BY_POS) if (OrderMagicNumber() == InstanceID) lastClosedDirection = OrderType() ; } Can anyone tell me where this should be applied?
好的,这是我在专家顾问生成器网站上生成的代码,用于开启第一笔交易。
而这是有人向我建议的一个循环,我想加入,但不确定在哪里应用。
好的,这是我在专家顾问生成器网站上生成的用于开启第一笔交易的代码。
当我在大学时,我们关于计算机的第一次讲座是让讲师打招呼。然后他说 "买书,然后继续学习"。"如果你有问题,那么会有实验课,你可以问研究生"--他们需要在这些实验课上提供帮助。你不倾向于教计算机;你允许人学习。在定义C编程语言的书中,第一个程序之一是向屏幕上写 "HELLO WORLD"。为什么不给你一个1000行的程序并告诉你对它进行修改是有原因的!这就是所谓的专家顾问生成器。
这种所谓的专家顾问生成器对任何认真制作EA并进行交易赚钱的人来说都是一种负担。您需要能够查看您的EA中的任何一行代码,并知道它在做什么和为什么。我不会使用其他人的代码。看看他们在做什么,并通过各种手段做一些类似的事情,但如果你是认真的,就自己写每一行。
EA构建器的代码不是好的代码,IMHO。
我已经完成了付钱给别人来建立我的EA。现在终于到了我自己做这件事的时候了。
我想创建一个模板,我可以在此基础上进一步发展,称为ASAR(ATR止损和反向),但我不确定如何开始,因为这将是我的第一个EA。因为未经修改的模板只是一个带有ATR手数的ATR追踪止损(和反向),它将在一周内从开市到收市不停地运行。因此,开市时的交易信号将仅仅是朝前一个条形图(恰好是前一个市场收盘 的最后一个条形图)的方向打开。由于这只在本周初发生一次,这是否需要一个脚本?
我怎样才能知道如何编写这个代码?
我见过一些例子,让人了解编码过程,但这些例子的问题是,它们并没有真正向人展示如何弄清那些没有介绍的东西。例如,MetaQuotes的MQL4书很好地解释了基础知识,并附有具体的例子,但在我读过的所有东西中,我不记得遇到过能让我弄清我为模板选择的初始交易信号的编码的信息。