论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
前往
共 127 条
lhch
注册时间2006-05-05
[MT4-EA]顺势而为
楼主发表于:2008-05-30 13:47只看该作者
61楼 电梯直达
电梯直达
基于五线谱开仓出现的价位的滞后性,自己写了一个简单的EA,因为自己水平,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 = False; extern double Lots = 1.0; extern int Slippage = 3; extern bool UseStopLoss = True; extern int StopLoss = 30; extern bool UseTakeProfit = True; extern int TakeProfit = 250; extern bool UseTrailingStop = True; extern int TrailingStop = 55; 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; double Buy2; double Buy3; double Sell1; double Sell2; //均线;ADX; double MA100now =iMA(NULL, 0, 100, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double MA100a =iMA(NULL, 0, 100, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double MA200now =iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double MA200a =iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1); double Closenow =iClose(NULL, 0, Current + 0); double Close1 =iClose(NULL, 0, Current + 1); double pAO =iAO(NULL, 0, Current + 0); //buy信号 if(MA200now>=MA100now &&Closenow>MA200now&&Close1<=MA100a&&pAO>0) Buy1=true; if(MA200now>=MA100now &&Closenow>MA200now&&Close1<=MA200a&&pAO>0) Buy2=true; if(MA100now>=MA200now &&Closenow>MA100now&&Close1<=MA200a&&pAO>0) Buy3=true; //////////////////////////////////////// /////sell if(MA100now>=MA200now &&Closenow=MA200a&&pAO<0) Sell1=true; if(MA100now<=MA200now &&Closenow=MA200a&&pAO<0) Sell2=true; ///////////// double CloseBuy1_1 = pAO; double CloseBuy1_2 = 0; double CloseSell1_1 = pAO; double CloseSell1_2 = 0; //+------------------------------------------------------------------+ //| 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) | //+------------------------------------------------------------------+ if (CloseBuy1_1 <= CloseBuy1_2) Order = SIGNAL_CLOSEBUY; //+------------------------------------------------------------------+ //| 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) | //+------------------------------------------------------------------+ if (CloseSell1_1 >= CloseSell1_2) Order = SIGNAL_CLOSESELL; //+------------------------------------------------------------------+ //| 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==true || Buy2 ==true||Buy3==true) Order = SIGNAL_BUY; if (Sell1==true || Sell2==true) 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); } //+------------------------------------------------------------------+
个性签名

韬客社区www.talkfx.co

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告
雪天
注册时间2008-04-05
发表于:2008-05-31 01:33只看该作者
62楼
原帖由 lhch 于 2008-5-30 21:46 发表 http://www.talkfx.com/images/common/back.gif 开单加了魔术号码。。。但是。。。 //---- //A单 res =OrderSend(Symbol(),OP_BUY,getLots(),Ask,3,sl,0,expName,LHCHMAGIC+1,0,Red); if(res < 0) Print("Error opening Sel ...
原程序如下: //平仓= int modNum = 0.0; if (OrdersTotal() > 0) { for(i=OrdersTotal()-1; i>=0; i--) { modNum = 0; OrderSelect(i, SELECT_BY_POS, MODE_TRADES); modNum = MathMod(OrderMagicNumber(),4.0); /* if(OrderMagicNumber()==LHCHMAGIC+1) { if(OrderType()==OP_BUY) { if((dMA2>=Low[1]&&dMA2<=High[1])|| marketState == -1) OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); } if(OrderType()==OP_SELL) { if((dMA2>=Low[1]&&dMA2<=High[1])|| marketState == 1) OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); } } */ switch(modNum) { case 1: //平A仓 if(OrderType()==OP_BUY) { if((dMA2>=Low[1]&&dMA2<=High[1])|| marketState == -1) OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); } if(OrderType()==OP_SELL) { if((dMA2>=Low[1]&&dMA2<=High[1])|| marketState == 1) OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); } break; case 2: if(OrderType()==OP_BUY) { if((dMA3>=Low[1]&&dMA3<=High[1])|| marketState == -1) OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); } if(OrderType()==OP_SELL) { if((dMA3>=Low[1]&&dMA3<=High[1])|| marketState == 1) OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); } break; case 3: if(OrderType()==OP_BUY) { if((dMA4>=Low[1]&&dMA4<=High[1])|| marketState == -1) OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); } if(OrderType()==OP_SELL) { if((dMA4>=Low[1]&&dMA4<=High[1])|| marketState == 1) OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); } break; case 4: if(OrderType()==OP_BUY) { if((dMA5>=Low[1]&&dMA5<=High[1])|| marketState == -1) OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); } if(OrderType()==OP_SELL) { if((dMA5>=Low[1]&&dMA5<=High[1])|| marketState == 1) OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); } break; default: break; } } } //---- return(0); } 在复盘中,确实这样平仓,因为均线并不总是呈现多头或者空头顺序排列,有些问题,但是的确是按照您过去提的依次触发平仓的啊
雪天
注册时间2008-04-05
发表于:2008-06-03 09:14只看该作者
63楼
抱歉,最近几乎没有时间,上面您提到的五线谱平仓问题,是我理解不深 应该在触及均线的时候加入优先级来处理仓位 当时复盘的时候,就发现这个问题了,而且有时候价格剧烈变化的时候,您的平仓条件并不顺序触发
雪天
注册时间2008-04-05
发表于:2008-06-06 02:46只看该作者
64楼
俺终于从晋陕蒙边境活着回来了,还在吗lhch兄? 刚才浏览了下您所有回复,除了平仓信号需要加优先级,另外您新的EA开仓信号不同了 您在前面回复中讲,当价格突破通道的时候,往往在5分钟图中下一单,15分钟图中下一单,然后一小时回调的时候再下一单 需要这样子修改下单方式吗?
个性签名

韬客社区www.talkfx.co

你好啊
注册时间2008-11-18
zhangpb888
注册时间2008-12-02
发表于:2008-12-04 10:06只看该作者
67楼
55555555555555555555
kangwei
注册时间2008-11-05
发表于:2009-01-04 14:36只看该作者
68楼
看过了 有一定的启发
晓明
注册时间2009-03-14
离骚
注册时间2009-03-19
发表于:2009-03-21 09:03只看该作者
70楼
支持一下 新手学习中
icefish
注册时间2009-08-10
linmu
注册时间2008-12-10
发表于:2010-05-27 18:02只看该作者
72楼
支持一下 新手学习中
wzhwzh
注册时间2010-10-17
发表于:2010-10-23 19:53只看该作者
73楼
:) :) :) :) :) :) :) :) :)
个性签名

韬客社区www.talkfx.co

musicar
注册时间2010-12-08
发表于:2010-12-15 12:18只看该作者
74楼
在哪呢?!!!
rainbowdj
注册时间2010-08-26
发表于:2011-01-13 00:57只看该作者
76楼
ddddddddddd
祝之
注册时间2011-04-06
marshalhan
注册时间2012-03-03
发表于:2012-03-04 18:15只看该作者
78楼
你好,我想知道一下,这个系统最后的测试结果令人满意么?能够做成EA使用么?
xiaoheidan
注册时间2012-08-22
发表于:2012-08-23 10:40只看该作者
79楼
感受很多,受教了。收藏一下。lhch 和雪天兄都是高高手啊。
发表于:2012-08-23 11:30只看该作者
80楼
期待下文,学到了很多:handshake
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
前往
共 127 条

本站免责声明:

1、本站所有广告及宣传信息均与韬客无关,如需投资请依法自行决定是否投资、斟酌资金安全及交易亏损风险;

2、韬客是独立的、仅为投资者提供交流的平台,网友发布信息不代表韬客的观点与意思表示,所有因网友发布的信息而造成的任何法律后果、风险与责任,均与韬客无关;

3、金融交易存在极高法律风险,未必适合所有投资者,请不要轻信任何高额投资收益的诱导而贸然投资;投资保证金交易导致的损失可能超过您投入的资金和预期。请您考虑自身的投资经验及风险承担能力,进行合法、理性投资;

4、所有投资者的交易帐户应仅限本人使用,不应交由第三方操作,对于任何接受第三方喊单、操盘、理财等操作的投资和交易,由此导致的任何风险、亏损及责任由投资者个人自行承担;

5、韬客不隶属于任何券商平台,亦不受任何第三方控制,韬客不邀约客户投资任何保证金交易,不接触亦不涉及投资者的任何资金及账户信息,不代理任何交易操盘行为,不向客户推荐任何券商平台,亦不存在其他任何推荐行为。投资者应自行选择券商平台,券商平台的任何行为均与韬客无关。投资者注册及使用韬客即表示其接受和认可上述声明,并自行承担法律风险。

版权所有:韬客外汇论坛 www.talkfx.com 联络我们:[email protected]