如何编码? - 页 145 1...138139140141142143144145146147148149150151152...347 新评论 [删除] 2008.11.18 13:01 #1441 嗨,Roger09。 再次感谢您的帮助。我的目标是使用一个脚本来移动我的止损,在买入交易中达到收支平衡加x点,或者在卖出交易中达到收支平衡减x点。我为该脚本设置了一个热键,这样当交易向我有利的方向发展时,我可以迅速锁定一些利润。我知道有些ES有这个功能,但我更喜欢使用脚本,这样我可以手动操作。 cgassfr67 2008.11.18 14:32 #1442 进程中不停止买入和停止卖出 你好。 我有一个使用CCI的EA。 我的程序在前一个条形图超过CCI>100时进行买入,但我想在最后一个条形图上高5点买入。 我想用同样的方法止损卖出(比最后的低点低5个点)。 这是我的EA,你能帮助我吗? 谢谢 /+------------------------------------------------------------------+ //| 这个MQL是由专家顾问生成器生成的。 //|MetaTrader 4的专家顾问生成器 //| | /+-------------------,不要删除这个标题 --------------------+ #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/" 外部int MagicNumber = 0; extern bool SignalMail = False; extern bool EachTickMode = False; 外置双倍数 Lots = 1.0; extern int Slippage = 30; 外部 bool UseStopLoss = True; 外置 int StopLoss = 200; 外部 bool UseTakeProfit = True; 外置 int TakeProfit = 600; 外部 bool UseTrailingStop = True; 外置 int TrailingStop = 250; int BarCount; int Current; bool TickCheck = False; //+------------------------------------------------------------------+ //| 专家初始化函数 | //+------------------------------------------------------------------+ int init() { BarCount = Bars; 如果(EachTickMode)Current = 0;否则Current = 1。 return(0); } //+------------------------------------------------------------------+ //| 专家去初始化功能| //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| 专家启动功能| //+------------------------------------------------------------------+ int start() { int Order = SIGNAL_NONE; int Total, Ticket; double StopLossLevel, TakeProfitLevel; 如果(EachTickMode && Bars != BarCount) TickCheck = False; Total = OrdersTotal(); 订单 = SIGNAL_NONE; //+------------------------------------------------------------------+ //| 变量开始 | //+------------------------------------------------------------------+ double Var1 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 0); double Var2 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 1); double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Buy2_1 = Var1 ; 双倍Buy2_2 = 100; double Buy3_1 = Var2 ; 双倍Buy3_2 = 100。 double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Sell2_1 = Var1 ; double Sell2_2 = - 100; double Sell3_1 = Var2 ; 双份Sell3_2 = - 100。 //+------------------------------------------------------------------+ //| 变量结束 | //+------------------------------------------------------------------+ //检查仓位 bool IsTrade = False; for (int i = 0; i < Total; i ++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES)。 如果(OrderType() <= OP_SELL && OrderSymbol() == Symbol() ) { IsTrade = True。 如果(OrderType() == OP_BUY){ //关闭 //+------------------------------------------------------------------+ //| 信号开始(退出买入)| //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 信号结束(退出买入)| //+------------------------------------------------------------------+ 如果(Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){ OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen)。 if (SignalMail) SendMail("[信号提示]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy"); if (!EachTickMode) BarCount = Bars; IsTrade = False; 继续。 } //拖曳止损 if(UseTrailingStop && TrailingStop > 0) { if(Bid - OrderOpenPrice() > Point * TrailingStop) { 如果(OrderStopLoss() < Bid - Point * TrailingStop) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen) 。 if (!EachTickMode) BarCount = Bars; 继续。 } } } } else { //关闭 //+------------------------------------------------------------------+ //| 信号开始(退出卖出)| //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 信号结束(退出卖出)| //+------------------------------------------------------------------+ 如果(Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){ OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange)。 如果(SignalMail) SendMail("[信号警报]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell"); if (!EachTickMode) BarCount = Bars; IsTrade = False。 继续。 } //拖曳止损 if(UseTrailingStop && TrailingStop > 0) { if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) { 如果((OrderStopLoss() > (Ask + Point * TrailingStop))|| (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange) 。 if (!EachTickMode) BarCount = Bars; 继续。 } } } } } } //+------------------------------------------------------------------+ //| Signal Begin(Entry) | //+------------------------------------------------------------------+ 如果(Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2 && Buy3_1 <= Buy3_2) Order = SIGNAL_BUY; 如果(Sell1_1 < Sell1_2 && Sell2_1 Sell3_2) Order = SIGNAL_SELL; //+------------------------------------------------------------------+ //| 信号结束 | //+------------------------------------------------------------------+ //买入 如果(Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){ if(!IsTrade) { //检查自由保证金 如果(AccountFreeMargin() < (1000 * Lots)) { Print("我们没有钱。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) 。 如果(Ticket > 0) { 如果(OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) { Print("BUY订单打开:", OrderOpenPrice())。 if (SignalMail) SendMail("[信号提示]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy"); } else { Print("打开买入订单出错。", GetLastError())。 } } if (EachTickMode) TickCheck = True; 如果(!EachTickMode) BarCount = Bars; return(0); } } //卖出 如果(Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){ if(!IsTrade) { //检查自由保证金 如果(AccountFreeMargin() < (1000 * Lots)) { Print("我们没有钱。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) 。 如果(Ticket > 0) { 如果(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("错误打开卖出订单。", GetLastError())。 } } if (EachTickMode) TickCheck = True; 如果(!EachTickMode) BarCount = Bars; return(0); } } 如果(!EachTickMode) BarCount = Bars; return(0); } //+------------------------------------------------------------------+ 问吧! ICustom函数 How to code? Roger09 2008.11.18 15:46 #1443 tk748: 嗨,Roger09,再次感谢您的帮助。我的目标是使用一个脚本来移动我的止损,在买入交易中达到收支平衡加x点,或者在卖出交易中达到收支平衡减x点。我为该脚本设置了一个热键,这样当交易向我有利的方向发展时,我可以迅速锁定一些利润。我知道有些ES有这个功能,但我更喜欢使用脚本,这样我可以手动操作。 如果你只需要设置一次止损,请使用此EA代码 extern int pips=10;// //+------------------------------------------------------------------+ //| 脚本程序启动功能| //+------------------------------------------------------------------+ int start() { //---- int ot = OrdersTotal(); for (int i=0; i<ot; i++) { int o = OrderSelect(i, SELECT_BY_POS); 如果(OrderSymbol() == Symbol()&&OrderType() <2) { double sl = 0。 如果(OrderType() == OP_BUY&& OrderStopLoss() =pips*Point) sl = OrderOpenPrice() +pips*Point; 如果(OrderType() == OP_SELL && (OrderStopLoss() > OrderOpenPrice()||OrderStopLoss() ==0) &&OrderOpenPrice()-Ask>=pips*Point) sl = OrderOpenPrice() -pips*Point; 如果(!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0)) Print("Error_Modifying - ",GetLastError())。 } } //---- return(0); } How to code? 初学者的问题 MQL4 MT4 MetaTrader 退出策略。阶梯式止损与拖曳式止损 Roger09 2008.11.18 16:10 #1444 cgassfr67: 你好。我有一个使用CCI的EA。 我的程序在前一个条形图超过CCI>100时进行买入,但我想在最后一个条形图上高5点买入。 我想用同样的方法止损卖出(比最后的低点低5个点)。 这是我的EA,你能帮助我吗? 谢谢 替换 double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Buy2_1 = Var1 ; double Buy2_2 = 100; double Buy3_1 = Var2 ; double Buy3_2 = 100; double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Sell2_1 = Var1 ; double Sell2_2 = - 100; double Sell3_1 = Var2 ; double Sell3_2 = - 100;[/CODE] To [CODE] double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Buy2_1 = Var1 ; double Buy2_2 = 105; double Buy3_1 = Var2 ; double Buy3_2 = 105; double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Sell2_1 = Var1 ; double Sell2_2 = - 105; double Sell3_1 = Var2 ; double Sell3_2 = - 105; cgassfr67 2008.11.18 16:29 #1445 Roger09: 替换double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Buy2_1 = Var1 ; double Buy2_2 = 100; double Buy3_1 = Var2 ; double Buy3_2 = 100; double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Sell2_1 = Var1 ; double Sell2_2 = - 100; double Sell3_1 = Var2 ; double Sell3_2 = - 100;[/CODE] To [CODE] double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Buy2_1 = Var1 ; double Buy2_2 = 105; double Buy3_1 = Var2 ; double Buy3_2 = 105; double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Sell2_1 = Var1 ; double Sell2_2 = - 105; double Sell3_1 = Var2 ; double Sell3_2 = - 105; 是的,但是使用这个代码,我将在下一个交易日的开盘时进入,而且我确信下一个交易日会增加,所以必须在最后一个高点之上5个点买入。 pap0007 2008.11.18 18:15 #1446 每小时的顶部交易 你好,我想根据一天的时间来调用我的EA,也许是早上5点和下午5点,或者每30分钟,等等。 我怎样才能做到这一点? 非常感谢任何帮助。 凯文 Roger09 2008.11.18 19:08 #1447 也许这可以帮助你。 如果((TimeHour(TimeLocal( ))!=5&&TimeMinute(TimeLocal( ))!=0)|(TimeHour(TimeLocal( ))=17 &&TimeMinute(TimeLocal( ))!=0))返回()。 把它放在start()的开头。 Beno 2008.11.18 20:58 #1448 谁能看一下这个,让我知道为什么它不能工作。 我想把它作为一个注释使用。 Double AvgWin() { double CountTrades = 0; 双倍CountPips = 0。 for(int Ticket=0;Ticket<OrdersHistoryTotal(); Ticket++) { OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY); 如果(MyAccount==AccountNumber() &&OrderSymbol()==Symbol() &&OrderMagicNumber() == MagicNumber) { //------>>>> 如果(OrderType()==OP_BUY &&OrderClosePrice()>=OrderOpenPrice() CountTrades++; { 如果(OrderProfit() >= 0) CountPips++; } 如果(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice() CountTrades++; { 如果(OrderProfit() >= 0) CountPips++; } } } 如果(CountPips < 0) 返回(MathRound(CountPips/CountTrades)*10)。 否则 Print("Real Time AvgWin not Available"); return(mAvgWin); } How to code? 问吧! 初学者的问题 MQL4 MT4 MetaTrader Roger09 2008.11.18 22:37 #1449 首先,将 SELECT_BY_TICKET改为SELECT_BY_POS 第二,CountPips总是大于0。 Beno 2008.11.18 23:17 #1450 Roger09: 首先是替换SELECT_BY_TICKET改为SELECT_BY_POS 第二,CountPips总是大于0。 这样做可以吗? 平均赢钱() { int CountTrades = 0; int CountPips = 0; for(int Ticket=0;Ticket<OrdersHistoryTotal(); Ticket++) { OrderSelect(Ticket,SELECT_BY_POS,MODE_HISTORY); 如果(MyAccount==AccountNumber() &&OrderSymbol()==Symbol() &&OrderMagicNumber() == MagicNumber) { //------>>>> 如果(OrderType()==OP_BUY &&OrderClosePrice()>=OrderOpenPrice() CountTrades++; { 如果(OrderProfit() >= 0) CountPips++; } 如果(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice() CountTrades++; { 如果(OrderProfit() >= 0) CountPips++; } } } 如果(CountPips > 0) 返回(MathRound(CountPips/CountTrades)*10)。 否则 Print("Real Time AvgWin not Available"); return(mAvgWin); } How to code? 新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 [存档!]任何菜鸟问题,为了不使论坛变得混乱。专业人士,不要路过。没有你,哪里都不能去 - 4. 1...138139140141142143144145146147148149150151152...347 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
嗨,Roger09。
再次感谢您的帮助。我的目标是使用一个脚本来移动我的止损,在买入交易中达到收支平衡加x点,或者在卖出交易中达到收支平衡减x点。我为该脚本设置了一个热键,这样当交易向我有利的方向发展时,我可以迅速锁定一些利润。我知道有些ES有这个功能,但我更喜欢使用脚本,这样我可以手动操作。
进程中不停止买入和停止卖出
你好。
我有一个使用CCI的EA。
我的程序在前一个条形图超过CCI>100时进行买入,但我想在最后一个条形图上高5点买入。
我想用同样的方法止损卖出(比最后的低点低5个点)。
这是我的EA,你能帮助我吗?
谢谢
/+------------------------------------------------------------------+
//| 这个MQL是由专家顾问生成器生成的。
//|MetaTrader 4的专家顾问生成器
//| |
/+-------------------,不要删除这个标题 --------------------+
#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/"
外部int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
外置双倍数 Lots = 1.0;
extern int Slippage = 30;
外部 bool UseStopLoss = True;
外置 int StopLoss = 200;
外部 bool UseTakeProfit = True;
外置 int TakeProfit = 600;
外部 bool UseTrailingStop = True;
外置 int TrailingStop = 250;
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| 专家初始化函数 |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;
如果(EachTickMode)Current = 0;否则Current = 1。
return(0);
}
//+------------------------------------------------------------------+
//| 专家去初始化功能|
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| 专家启动功能|
//+------------------------------------------------------------------+
int start() {
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
如果(EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
订单 = SIGNAL_NONE;
//+------------------------------------------------------------------+
//| 变量开始 |
//+------------------------------------------------------------------+
double Var1 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 0);
double Var2 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 1);
double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Buy2_1 = Var1 ;
双倍Buy2_2 = 100;
double Buy3_1 = Var2 ;
双倍Buy3_2 = 100。
double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Sell2_1 = Var1 ;
double Sell2_2 = - 100;
double Sell3_1 = Var2 ;
双份Sell3_2 = - 100。
//+------------------------------------------------------------------+
//| 变量结束 |
//+------------------------------------------------------------------+
//检查仓位
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES)。
如果(OrderType() <= OP_SELL && OrderSymbol() == Symbol() ) {
IsTrade = True。
如果(OrderType() == OP_BUY){
//关闭
//+------------------------------------------------------------------+
//| 信号开始(退出买入)|
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| 信号结束(退出买入)|
//+------------------------------------------------------------------+
如果(Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen)。
if (SignalMail) SendMail("[信号提示]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
继续。
}
//拖曳止损
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
如果(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen) 。
if (!EachTickMode) BarCount = Bars;
继续。
}
}
}
} else {
//关闭
//+------------------------------------------------------------------+
//| 信号开始(退出卖出)|
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| 信号结束(退出卖出)|
//+------------------------------------------------------------------+
如果(Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange)。
如果(SignalMail) SendMail("[信号警报]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False。
继续。
}
//拖曳止损
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
如果((OrderStopLoss() > (Ask + Point * TrailingStop))|| (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange) 。
if (!EachTickMode) BarCount = Bars;
继续。
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+
如果(Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2 && Buy3_1 <= Buy3_2) Order = SIGNAL_BUY;
如果(Sell1_1 < Sell1_2 && Sell2_1 Sell3_2) Order = SIGNAL_SELL;
//+------------------------------------------------------------------+
//| 信号结束 |
//+------------------------------------------------------------------+
//买入
如果(Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){
if(!IsTrade) {
//检查自由保证金
如果(AccountFreeMargin() < (1000 * Lots)) {
Print("我们没有钱。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) 。
如果(Ticket > 0) {
如果(OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY订单打开:", OrderOpenPrice())。
if (SignalMail) SendMail("[信号提示]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("打开买入订单出错。", GetLastError())。
}
}
if (EachTickMode) TickCheck = True;
如果(!EachTickMode) BarCount = Bars;
return(0);
}
}
//卖出
如果(Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){
if(!IsTrade) {
//检查自由保证金
如果(AccountFreeMargin() < (1000 * Lots)) {
Print("我们没有钱。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) 。
如果(Ticket > 0) {
如果(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("错误打开卖出订单。", GetLastError())。
}
}
if (EachTickMode) TickCheck = True;
如果(!EachTickMode) BarCount = Bars;
return(0);
}
}
如果(!EachTickMode) BarCount = Bars;
return(0);
}
//+------------------------------------------------------------------+
嗨,Roger09,再次感谢您的帮助。我的目标是使用一个脚本来移动我的止损,在买入交易中达到收支平衡加x点,或者在卖出交易中达到收支平衡减x点。我为该脚本设置了一个热键,这样当交易向我有利的方向发展时,我可以迅速锁定一些利润。我知道有些ES有这个功能,但我更喜欢使用脚本,这样我可以手动操作。
如果你只需要设置一次止损,请使用此EA代码
extern int pips=10;//
//+------------------------------------------------------------------+
//| 脚本程序启动功能|
//+------------------------------------------------------------------+
int start()
{
//----
int ot = OrdersTotal();
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
如果(OrderSymbol() == Symbol()&&OrderType() <2)
{
double sl = 0。
如果(OrderType() == OP_BUY&& OrderStopLoss() =pips*Point)
sl = OrderOpenPrice() +pips*Point;
如果(OrderType() == OP_SELL && (OrderStopLoss() > OrderOpenPrice()||OrderStopLoss() ==0)
&&OrderOpenPrice()-Ask>=pips*Point)
sl = OrderOpenPrice() -pips*Point;
如果(!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0))
Print("Error_Modifying - ",GetLastError())。
}
}
//----
return(0);
}
你好。
我有一个使用CCI的EA。
我的程序在前一个条形图超过CCI>100时进行买入,但我想在最后一个条形图上高5点买入。
我想用同样的方法止损卖出(比最后的低点低5个点)。
这是我的EA,你能帮助我吗?
谢谢
替换
double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Buy2_1 = Var1 ;
double Buy2_2 = 100;
double Buy3_1 = Var2 ;
double Buy3_2 = 100;
double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Sell2_1 = Var1 ;
double Sell2_2 = - 100;
double Sell3_1 = Var2 ;
double Sell3_2 = - 100;[/CODE]
To
[CODE]
double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Buy2_1 = Var1 ;
double Buy2_2 = 105;
double Buy3_1 = Var2 ;
double Buy3_2 = 105;
double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Sell2_1 = Var1 ;
double Sell2_2 = - 105;
double Sell3_1 = Var2 ;
double Sell3_2 = - 105;替换
double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Buy2_1 = Var1 ;
double Buy2_2 = 100;
double Buy3_1 = Var2 ;
double Buy3_2 = 100;
double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Sell2_1 = Var1 ;
double Sell2_2 = - 100;
double Sell3_1 = Var2 ;
double Sell3_2 = - 100;[/CODE]
To
[CODE]
double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Buy2_1 = Var1 ;
double Buy2_2 = 105;
double Buy3_1 = Var2 ;
double Buy3_2 = 105;
double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Sell2_1 = Var1 ;
double Sell2_2 = - 105;
double Sell3_1 = Var2 ;
double Sell3_2 = - 105;是的,但是使用这个代码,我将在下一个交易日的开盘时进入,而且我确信下一个交易日会增加,所以必须在最后一个高点之上5个点买入。
每小时的顶部交易
你好,我想根据一天的时间来调用我的EA,也许是早上5点和下午5点,或者每30分钟,等等。
我怎样才能做到这一点?
非常感谢任何帮助。
凯文
也许这可以帮助你。
如果((TimeHour(TimeLocal( ))!=5&&TimeMinute(TimeLocal( ))!=0)|(TimeHour(TimeLocal( ))=17
&&TimeMinute(TimeLocal( ))!=0))返回()。
把它放在start()的开头。
谁能看一下这个,让我知道为什么它不能工作。
我想把它作为一个注释使用。
Double AvgWin()
{
double CountTrades = 0;
双倍CountPips = 0。
for(int Ticket=0;Ticket<OrdersHistoryTotal(); Ticket++)
{
OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);
如果(MyAccount==AccountNumber() &&OrderSymbol()==Symbol() &&OrderMagicNumber() == MagicNumber)
{
//------>>>>
如果(OrderType()==OP_BUY &&OrderClosePrice()>=OrderOpenPrice()
CountTrades++;
{
如果(OrderProfit() >= 0)
CountPips++;
}
如果(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice()
CountTrades++;
{
如果(OrderProfit() >= 0)
CountPips++;
}
}
}
如果(CountPips < 0)
返回(MathRound(CountPips/CountTrades)*10)。
否则
Print("Real Time AvgWin not Available");
return(mAvgWin);
}
首先,将
SELECT_BY_TICKET改为SELECT_BY_POS
第二,CountPips总是大于0。
首先是替换
SELECT_BY_TICKET改为SELECT_BY_POS
第二,CountPips总是大于0。这样做可以吗?
平均赢钱()
{
int CountTrades = 0;
int CountPips = 0;
for(int Ticket=0;Ticket<OrdersHistoryTotal(); Ticket++)
{
OrderSelect(Ticket,SELECT_BY_POS,MODE_HISTORY);
如果(MyAccount==AccountNumber() &&OrderSymbol()==Symbol() &&OrderMagicNumber() == MagicNumber)
{
//------>>>>
如果(OrderType()==OP_BUY &&OrderClosePrice()>=OrderOpenPrice()
CountTrades++;
{
如果(OrderProfit() >= 0)
CountPips++;
}
如果(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice()
CountTrades++;
{
如果(OrderProfit() >= 0)
CountPips++;
}
}
}
如果(CountPips > 0)
返回(MathRound(CountPips/CountTrades)*10)。
否则
Print("Real Time AvgWin not Available");
return(mAvgWin);
}