论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
查看:1136回复:0
fenyou
注册时间2006-12-26
请高手帮忙把该模板修改两个指令,谢谢!
楼主发表于:2008-09-28 13:21只看该作者倒序浏览
1楼 电梯直达
电梯直达
请高手帮忙把该模板修改两个指令: 1.当盈利大于开仓价30点时,开始启动跟踪止损,跟踪止损20点; 2.强制性买、卖交替开仓。 ———————————————————————————————————————————— //+------------------------------------------------------------------+ //| ea模板.mq4 | //| Copyright @2007, http://hexun.com/pckr
| //| | //| | | //+------------------------------------------------------------------+ #property copyright "Copyright @2006, pckr" #property link "http://hexun.com/pckr" #include //******************************************************************** //******************************************************************** //+---------------------------------------------------+ //---- User Inputs | //+---------------------------------------------------+ extern int Slippage =10; // 滑点 extern double TakeProfit = 12;// 最大止赢 extern double StopLoss = 30; // 最大止损 extern double TrailingStop = 0; // 移动止损 //---- Money Management extern int mm =1; // 设为0不接受资金管理, extern double Riskpercent =20; // 下单占资金的百分比 extern double DecreaseFactor =2; // 亏损减少下单手数 extern double Margincutoff =80; // 资金低于Margincutoff不交易 extern double Lots =5; // 设置期望的手数(如果忽略资金管理). extern int tradeSymbolNum =3; // 交易笔数 //---- Account functions extern int AccountIsMini =2; // 设为1使用迷你账户,设为2使用超迷你账户 //---- 用户自定义参数 //******************************************************************** //******************************************************************** //---- 系统变量 string OrderText =""; // 在函数中使用"Buy" or "Sell"为条件 double lotMM =0; int TradesInThisSymbol =0; // 外汇交易数 datetime LastTime; // 最后订单时间 double Sl =0; // 止损 double Tr =0; // 止赢 int NumBuys =0; int NumSells =0; int MagicNumber; //---- 用户变量 //******************************************************************** //******************************************************************** //+------------------------------------------------------------------+ //| 初始化函数 | //+------------------------------------------------------------------+ int init() { return(0); } //******************************************************************** //******************************************************************** //+------------------------------------------------------------------+ //| 取消初始化函数 | //+------------------------------------------------------------------+ int deinit() { return(0); } //******************************************************************** //******************************************************************** //+------------------------------------------------------------------+ //| 启动 start() | //+------------------------------------------------------------------+ int start() { //---- Start functions variables int donttrade = 0; int allexit = 0; int ExitCondition; //int MagicNumber =20050610; MagicNumber = 3000 + func_Symbol2Val(Symbol())*100; string setup="hexun.com/pckr" + Symbol() + "_" + func_TimeFrame_Val2String(func_TimeFrame_Const2Val(Period())); if(Bars<100 || IsTradeAllowed()==false) return; //+------------------------------------------------------------------+ //| 这里输入需要的数据如指标等 | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 周五平仓 | //+------------------------------------------------------------------+ if(DayOfWeek()==5 && Hour()>=21) donttrade=1; // 21时禁止交易 if(DayOfWeek()==5 && Hour()>=22) allexit=1; //22时平所有合约 //+------------------------------------------------------------------+ //| 检查未平仓合约 | //+------------------------------------------------------------------+ NumBuys = CheckOpenBuyPositions(MagicNumber); // 如果有买合约,看看是否应该关闭。 if (NumBuys > 0) TryClosePositions("BUY",allexit); NumSells = CheckOpenSellPositions(MagicNumber); // 如果有卖合约,看看是否应该关闭。 if (NumSells > 0) TryClosePositions("SELL",allexit); TradesInThisSymbol = CheckOpenPositions(MagicNumber); // 更新TradesInThisSymbol值 //+------------------------------------------------------------------+ //| New Position Controls | //+------------------------------------------------------------------+ if(AccountFreeMargin() < Margincutoff) // 检查,以确保账户有足够的资金。 { return(0); } if(TradesInThisSymbol > tradeSymbolNum) // 只允许每个货币对有TradesInThisSymbol张合约 { return(0); } if(CurTime() < LastTime) { return(0); } if(mm == 1) // 检查资金管理是否选定的。 lotMM = LotsOptimized(MagicNumber, Lots, Riskpercent, DecreaseFactor, AccountIsMini); else lotMM = Lots; // 如资金管理未选定,Lots为预设值 OrderText = ""; if((CheckBuyCondition() == 1)) // 如果买入的条件存在着,传递参数给doorder ( ) 。 { OrderText = "BUY"; if (StopLoss>0) { Sl = Ask-StopLoss*Point; } else { Sl=0; } if (TakeProfit == 0) Tr = 0; else Tr = Ask+TakeProfit*Point; } if (CheckSellCondition() == 1) // 如果卖出的条件存在着,传递参数给doorder ( ) 。 { OrderText = "SELL"; if (StopLoss>0) { Sl = Bid+StopLoss*Point; } else { Sl = 0; } if (TakeProfit == 0) Tr = 0; else Tr = Bid-TakeProfit*Point; } if(OrderText != "" && TradesInThisSymbol == 0 && donttrade == 0 ) { LastTime = DoTrades(OrderText,setup,MagicNumber, lotMM, Sl, Tr, CurTime(), Slippage); return(0); } Comment("更多信息请访问hexun.com/pckr"); return(0); } //******************************************************************** //******************************************************************** //+----------------------------------------------+ //| CheckExitCondition() | //| | //| 平仓条件 | //| return 0 for 条件不满足 | //| return 1 for 条件满足 | //+----------------------------------------------+ int CheckExitCondition(string type) { if (type == "BUY") { if(true) return(1); //输入条件 else return(0); } if (type == "SELL") //输入条件 { if(true) return (1); else return(0); } } //******************************************************************** //******************************************************************** //+------------------------------------------+ //| CheckBuyCondition() | //| | //| 定义买入条件 | //| | //| return 0 for 条件不满足 | //| return 1 for 条件满足 | //+------------------------------------------+ int CheckBuyCondition() { if( true ) return(1); else return (0); } //******************************************************************** //******************************************************************** //+------------------------------------------+ //| CheckSellCondition | //| | //| 定义卖出条件 | //| | //| return 0 for 条件不满足 | //| return 1 for 条件满足 | //+------------------------------------------+ int CheckSellCondition() { if( true ) return(1); else return (0); } //******************************************************************** //******************************************************************** //+--------------------------------------------------------+ //| TryClosePositions | //+--------------------------------------------------------+ int TryClosePositions(string type,int exitall) { int ExitCondition; // Print(type); if (type == "BUY") { ExitCondition = CheckExitCondition("BUY"); // First check if indicators cause exit if(exitall==1) ExitCondition = 1; // Then check if Friday HandleBuys(ExitCondition,Slippage,TakeProfit,MagicNumber); } if (type == "SELL") { ExitCondition = CheckExitCondition("SELL"); // First check if indicators cause exit if(exitall==1) ExitCondition = 1; // Then check if Friday HandleSells(ExitCondition,Slippage,TakeProfit,MagicNumber); } return (0); }
TK29帖子1楼右侧xm竖版广告90-240
个性签名

韬客社区www.talkfx.co

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告

本站免责声明:

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

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

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

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

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

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