如何编码? - 页 267 1...260261262263264265266267268269270271272273274...347 新评论 ixbone 2011.07.24 14:09 #2661 christinaLi: 我想对你所说的这个功能提供帮助,但似乎我不能简单地弄清楚你的逻辑。这真的与策略的其他逻辑没有关系。我只是想知道这一点。 如果你有1手在1.4110买入,2手在1.4200卖出。你认为你在什么价格上有6个点的收益? 你好,克里斯蒂娜。 在我的仓位管理中,从来都是在1手买入结束并获利后,才开始2手卖出。(卖出从来都是因为1手买入结束并获利,等待下一个信号) 回到你的例子。 但是在大约1.4175处有一条线,2手卖出(盈利上升,市场下降)和1手买入(盈利下降,市场下降)的价格相等(盈亏平衡0),所以在1.4169处6个点的利润已经准备好了 - 然后我将关闭所有订单 九 Min Li 2011.07.24 15:04 #2662 ixbone: 嗨,克里斯蒂娜。 在我的仓位管理中,从来都是在1手买入获利平仓后,才开始2手卖出。(卖出从来都是因为1手买入获利平仓,等待下一个信号)。 回到你的例子。 但在大约1.4175处有一条线,2手卖出(利润上升,市场下降)和1手买入(利润下降,市场下降)的价格相等(盈亏平衡0),所以在1.4169处6个点的利润已经准备好了 - 然后我会关闭所有订单 九 因为我的例子是1.4110和1.4200。下面是我的计算。 首先,在1.4170(不考虑点差)我们是收支平衡的。现在我们有2手卖出,每手收益30点,1手买入,损失60点,所以以美元计算,收支平衡。 如果完全按照我的例子,你在1.4164应该有6个点的整体收益。 在1.4164(不考虑点差),我们有2手卖出,每手收益36点,1手买入,损失54点,所以卖出收益72点,买入损失54点。总的来说,在这组交易中,你有3手,收益为18点。所以现在认为你有6个点的收益是比较合理的。 然而,由于点差的关系,事情又会变得复杂。因为如果买入价是1.4164,卖出价可能是1.4166,所以你的卖出价每笔只有34点收益。总的来说,这组交易中,你有3手,收益为14点。所以现在事实上你有4.7个点的收益。 如果我把这个例子再往前推一步,如果我们有2个买点和3个卖点。那么在1.4164的时候,你就收支平衡了。 如果我们不考虑点差,那么我们需要30个点的总收益来获得每手5个点的收益。因此,6个点的收益将是在1.4134的价格,这是正确的吗? 你的系统可能不会出现这种情况,这是我想得到的原则。你同意以上的计算吗? ixbone 2011.07.24 15:32 #2663 christinaLi: 因为我的例子是1.4110和1.4200。这是我的计算方法。首先,在1.4170(不考虑点差)我们实现了收支平衡。现在我们有2手卖出,每手收益30点,1手买入,损失60点,所以以美元计算,收支平衡。 如果完全按照我的例子,你在1.4164应该有6个点的整体收益。 在1.4164(不考虑点差),我们有2手卖出,每手收益36点,1手买入,损失54点,所以卖出收益72点,买入损失54点。总的来说,在这组交易中,你有3手,收益为18点。所以现在认为你有6个点的收益是比较合理的。 然而,由于点差的原因,事情将再次变得复杂。因为如果买入价是1.4164,卖出价可能是1.4166,所以你的卖出价每笔只有34点收益。总的来说,这组交易中,你有3手,收益为14点。所以现在事实上你有4.7个点的收益。 如果我把这个例子再往前推一步,如果我们有2个买点和3个卖点。那么在1.4164的时候,你就收支平衡了。 如果我们不考虑点差,那么我们需要30个点的总收益来获得每手5个点的收益。因此,6个点的收益将是在1.4134的价格,这是正确的吗? 你的系统可能不会出现这种情况,这是我想得到的原则。你同意以上的计算方法吗? 克里斯蒂娜。 我同意,你的两种计算方法都是100%正确的 Min Li 2011.07.25 22:10 #2664 嗨,迈克尔。 这几天我太忙了,我已经做了这个,但需要更多的时间来拼凑。一旦我在接下来的几天里找到一些时间,就会在这里发布。克里斯蒂纳 [删除] 2011.07.26 03:11 #2665 ixbone 2011.07.26 10:33 #2666 christinaLi: 嗨,迈克尔,这几天我太忙了,我已经做了这个,但需要更多的时间来拼凑。一旦我在接下来的几天里找到时间,就会把它贴在这里。克里斯蒂纳 嗨,克里斯蒂娜。 没问题,慢慢来,我一直很感谢你的建议! 迈克尔 xlsander 2011.07.26 18:39 #2667 gold2008 2011.07.27 11:52 #2668 我需要帮助 大家好! 这是我的想法:我需要在独立窗口中有两个指标缓冲区,1是devupBuffer[];2是devdwBuffer[]。例如,如果有五个数字1,2,3,4,5,它们的平均值是3。那么数据大于3 4和5的平均数 devupBuffer={【(4-平均数)*(4-平均数)】。】+【(5-平均)*(5-平均)】}/标准偏差(1,2,3,4,5)*标准偏差(1,2,3,4,5)。数据小于3个1和2的平均数 devdwBuffer={【(1-平均数)*(1-平均数)】。+【(2-平均)*(2-平均)】}/标准偏差(1,2,3,4,5)*标准偏差(1,2,3,4,5)。 [删除] 2011.07.28 09:51 #2669 为什么这个EA不能买入或卖出? 嗨,我是使用Meta编程的新手......请帮助我...... 我正在使用一个有两个级别的随机指数系统,25和75... 只有一个交易... 如果主线和信号都在25以下,并有交叉,买入。 如果主线和信号线在25以上交叉,关闭买入。 如果MAIN和SIGNAL都在75以上并且交叉,卖出。 如果主线和信号线交叉(不需要低于75),关闭卖出。 就是这样... //+------------------------------------------------------------------+ //| StochCross.mq4 | //| RobertEli | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "RobertEli" #property link "http://www.metaquotes.net" //--- input parameters extern double TakeProfit=250.0; extern double Lots=0.01; extern double TrailingStop=35.0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } int Confirm (double line1, double line2, int level_buy, int level_sell) { static int confirmation = 0; if ((line1 < level_buy) && (line2 < level_buy)) confirmation = 1; //confirm BUY, when two lines are below level_buy if ((line1 > level_sell) && (line2 > level_sell)) confirmation = 2; //confirm SELL, when two lines are above level_sell if ((line1 > level_buy) && (line2 > level_buy)) confirmation = 3; //confirm CLOSE BUY, when two lines are above level_buy if ((line1 < level_sell) && (line2 < level_sell)) confirmation = 4; //confirm CLOSE SELL, when two lines are below level_sell //if ((line1 > level_buy_close) && (line2 > level_buy_close)) confirmation = 3; //confirm CLOSE BUY //if ((line1 < level_sell_close) && (line2 < level_sell_close)) confirmation = 4; //confirm CLOSE SELL //else return (0); return (confirmation); } int Crossed (double line1, double line2) { static int last_direction = 0; static int current_direction = 0; if (line1 > line2) current_direction = 1; //UP if (line1 < line2) current_direction = 2; //DOWN if (current_direction != last_direction) //changed direction { last_direction = current_direction; return (last_direction); } else { return (0); } } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int cnt, ticket; double Stoch_main, Stoch_sign; if (Bars < 100) { Print("BARS less than 100"); return (0); } if (TakeProfit < 10) { Print("TakeProfit less than 10"); return (0); } /* Stoch_main = iStochastic (NULL,15,21,8,13,MODE_SMA,1,MODE_MAIN,0); Stoch_sign = iStochastic (NULL,15,21,8,13,MODE_SMA,1,MODE_SIGNAL,0); */ Stoch_main = iStochastic (NULL,0,30,20,12,MODE_SMA,1,MODE_MAIN,0); Stoch_sign = iStochastic (NULL,0,30,20,12,MODE_SMA,1,MODE_SIGNAL,0); /* Stoch_main = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,0); Stoch_sign = iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,0); */ int isCrossed = Crossed(Stoch_main,Stoch_sign); int isConfirmed = Confirm(Stoch_main,Stoch_sign,25,75); int total = OrdersTotal(); if (total == 0) { if ((isCrossed == 1) && (isConfirmed == 1)) { ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"Buy at " + Ask,24848,0,Green); if (ticket > 0) { if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY Order opened: " +Ask ,OrderOpenPrice()); else Print ("Error Opening BUY Order: ", GetLastError()); return (0); } } if ((isCrossed == 2) && (isConfirmed == 2)) { ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"Sell at " + Bid,24848,0,Red); if (ticket > 0) { if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL Order opened: " +Bid ,OrderOpenPrice()); else Print ("Error Opening SELL Order: ", GetLastError()); return (0); } } return (0); } else { for (cnt = total; cnt < 0; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) { if (OrderType() == OP_BUY) //the trade was a Buy position { //check for closing) if ((isCrossed == 2) && (isConfirmed == 3)) //if (isCrossed == 2) { //change of direction OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); //close Buy position return (0); } } else // the trade was a SELL position { //should it be closed? //if ((isCrossed == 1) && (isConfirmed == 4)) if (isCrossed == 1) //Closing the SELL need not to be below the level_buy... it's very dangerous to wait for it... { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //Sell position is now closed return (0); } } } } } //---- return(0); } //+------------------------------------------------------------------+ How to code? Ema Cross! 对EA的密码保护 [删除] 2011.07.30 09:35 #2670 EA不能做它应该做的事,请帮助我! 你好,我对mq4编程很陌生,但我读过codersgurus的教程(非常感谢!),所以我想我能理解一些东西......。但是,我做了这个基于移动平均数的EA......但它很糟糕地没有按照应有的方式运行!这里的规则非常简单......。 这里的规则非常简单... 1.MA_04_1H(指1小时时间框架 的移动平均线周期4)高于MA_14_1H。 用MA_04_4H高于MA_14_4H来确认(趋势是向上的)------>买入! 2.MA_04_1H在MA_14_1H下方交叉。 当MA_04_4H低于MA_14_4H时确认(趋势是向下的)------> 卖出! 3. 当MA_04_1H与MA_14_1H交叉时,关闭该订单(鉴于规则#1和#2,它可以开始一个新的订单) 4.只做一笔交易...(如果买入,关闭买入。之后,如果有必要,卖出) 我做了2个函数。交叉,和确认。 交叉是针对1小时的时间框架。 确认是针对4小时的时间框架。 谁能帮我调试一下这个东西? //+------------------------------------------------------------------+ //| MACross1TradeOnly.mq4 | //| RobertEli | //| | //+------------------------------------------------------------------+ // this will work on MA_04, and MA__14 #property copyright "RobertEli" #property link "" extern double Lots = 0.01; extern int stoploss_value = 10; // $10 bool up = 0, //UP direction, when MA_04 is above MA_14 down = 0, //DOWN direction, when MA_14 is above MA_04 change = 0, //when the MA_04 and MA_14 cross firsttime = true; //first time for direction_prev int direction_curr = 0; // 1 if UP, 2 if down... int direction_prev = 0; // this will hold previous value of direction_curr int direction_trend= 0; // trend direction for confirmation int cross = 0; // if direction_curr and direction_prev changes course //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } int Crossed (double line1, double line2) { static int last_direction = 0; static int current_direction = 0; if (line1 - line2 > 0)//(line1 > line2) { current_direction = 1; //UP if (firsttime == true) { current_direction = 0; last_direction = 1; firsttime = false; return (0); } } if (line1 - line2 < 0)//(line1 < line2) { current_direction = 2; //DOWN if (firsttime == true) { current_direction = 0; last_direction = 2; firsttime = false; return (0); } } if ((current_direction != last_direction) && (firsttime == false)) //changed direction { last_direction = current_direction; return (last_direction); } else { return (last_direction); } } int Confirmed (double line1, double line2) { int trend; if (line1 > line2) trend = 1; // trend direction is UP if (line1 < line2) trend = 2; // trend direction is DOWN return (trend); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int cnt,ticket, total; //double MA_04, MA_07 , MA_14 , MA_21 , MA_28; //MOVING AVERAGES with their corresponding period if (Bars < 100) { Print ("Bars less than 100."); return (0); } double MA_04_1H = iMA(NULL,60,04,0,MODE_EMA,PRICE_CLOSE,0); double MA_14_1H = iMA(NULL,60,14,0,MODE_EMA,PRICE_CLOSE,0); double MA_04_4H = iMA(NULL,240,04,0,MODE_EMA,PRICE_CLOSE,0); double MA_14_4H = iMA(NULL,240,14,0,MODE_EMA,PRICE_CLOSE,0); //double stoploss = stoploss_value / (Lots * 100000); //new code from v_1 cross = Crossed (MA_04_1H,MA_14_1H); // =1 for UP, =2 for DOWN direction_trend = Confirmed (MA_04_4H, MA_14_4H); // =1 for UP, =2 for DOWN total = OrdersTotal(); if (total == 0) { if((cross == 1) && (direction_trend == 1)) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,/*Ask-stoploss*/0,0,"Buy at: "+ Ask,12345,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice(),",<<<<",OrderStopLoss()); } else Print("Error opening BUY order : ",GetLastError()); cross = 0; return(0); } if((cross == 2) && (direction_trend == 2)) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,/*Bid+stoploss*/0,0,"Sell at: "+ Bid,12345,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); cross = 0; return(0); } } if (total == 1) { for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); // bool no_buy_sell = ((OrderTakeProfit() 0)); if ((OrderType()==OP_BUY) && (cross == 2) )// && (no_buy_sell)) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position //OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+stoploss,0,"Sell at: "+ Bid,12345,0,Red); return (0); } else if ((OrderType()==OP_SELL) && (cross == 1) )// && (no_buy_sell)) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position //OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-stoploss,0,"Buy at: "+ Ask,12345,0,Green); return (0); } } } else return (0); //---- return(0); } //+------------------------------------------------------------------+ 请忽略我之前的帖子......我已经放弃了那个想法......我现在正在做这个......所以请帮助我...... How to code? Ema Cross! 对EA的密码保护 1...260261262263264265266267268269270271272273274...347 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
我想对你所说的这个功能提供帮助,但似乎我不能简单地弄清楚你的逻辑。这真的与策略的其他逻辑没有关系。
我只是想知道这一点。
如果你有1手在1.4110买入,2手在1.4200卖出。你认为你在什么价格上有6个点的收益?你好,克里斯蒂娜。
在我的仓位管理中,从来都是在1手买入结束并获利后,才开始2手卖出。(卖出从来都是因为1手买入结束并获利,等待下一个信号)
回到你的例子。
但是在大约1.4175处有一条线,2手卖出(盈利上升,市场下降)和1手买入(盈利下降,市场下降)的价格相等(盈亏平衡0),所以在1.4169处6个点的利润已经准备好了 - 然后我将关闭所有订单
九
嗨,克里斯蒂娜。
在我的仓位管理中,从来都是在1手买入获利平仓后,才开始2手卖出。(卖出从来都是因为1手买入获利平仓,等待下一个信号)。
回到你的例子。
但在大约1.4175处有一条线,2手卖出(利润上升,市场下降)和1手买入(利润下降,市场下降)的价格相等(盈亏平衡0),所以在1.4169处6个点的利润已经准备好了 - 然后我会关闭所有订单
九因为我的例子是1.4110和1.4200。下面是我的计算。
首先,在1.4170(不考虑点差)我们是收支平衡的。现在我们有2手卖出,每手收益30点,1手买入,损失60点,所以以美元计算,收支平衡。
如果完全按照我的例子,你在1.4164应该有6个点的整体收益。
在1.4164(不考虑点差),我们有2手卖出,每手收益36点,1手买入,损失54点,所以卖出收益72点,买入损失54点。总的来说,在这组交易中,你有3手,收益为18点。所以现在认为你有6个点的收益是比较合理的。
然而,由于点差的关系,事情又会变得复杂。因为如果买入价是1.4164,卖出价可能是1.4166,所以你的卖出价每笔只有34点收益。总的来说,这组交易中,你有3手,收益为14点。所以现在事实上你有4.7个点的收益。
如果我把这个例子再往前推一步,如果我们有2个买点和3个卖点。那么在1.4164的时候,你就收支平衡了。
如果我们不考虑点差,那么我们需要30个点的总收益来获得每手5个点的收益。因此,6个点的收益将是在1.4134的价格,这是正确的吗?
你的系统可能不会出现这种情况,这是我想得到的原则。你同意以上的计算吗?
因为我的例子是1.4110和1.4200。这是我的计算方法。
首先,在1.4170(不考虑点差)我们实现了收支平衡。现在我们有2手卖出,每手收益30点,1手买入,损失60点,所以以美元计算,收支平衡。
如果完全按照我的例子,你在1.4164应该有6个点的整体收益。
在1.4164(不考虑点差),我们有2手卖出,每手收益36点,1手买入,损失54点,所以卖出收益72点,买入损失54点。总的来说,在这组交易中,你有3手,收益为18点。所以现在认为你有6个点的收益是比较合理的。
然而,由于点差的原因,事情将再次变得复杂。因为如果买入价是1.4164,卖出价可能是1.4166,所以你的卖出价每笔只有34点收益。总的来说,这组交易中,你有3手,收益为14点。所以现在事实上你有4.7个点的收益。
如果我把这个例子再往前推一步,如果我们有2个买点和3个卖点。那么在1.4164的时候,你就收支平衡了。
如果我们不考虑点差,那么我们需要30个点的总收益来获得每手5个点的收益。因此,6个点的收益将是在1.4134的价格,这是正确的吗?
你的系统可能不会出现这种情况,这是我想得到的原则。你同意以上的计算方法吗?克里斯蒂娜。
我同意,你的两种计算方法都是100%正确的
嗨,迈克尔。
这几天我太忙了,我已经做了这个,但需要更多的时间来拼凑。一旦我在接下来的几天里找到一些时间,就会在这里发布。克里斯蒂纳
嗨,迈克尔,这几天我太忙了,我已经做了这个,但需要更多的时间来拼凑。一旦我在接下来的几天里找到时间,就会把它贴在这里。克里斯蒂纳
嗨,克里斯蒂娜。
没问题,慢慢来,我一直很感谢你的建议!
迈克尔
我需要帮助
大家好!
这是我的想法:我需要在独立窗口中有两个指标缓冲区,1是devupBuffer[];2是devdwBuffer[]。例如,如果有五个数字1,2,3,4,5,它们的平均值是3。那么数据大于3 4和5的平均数 devupBuffer={【(4-平均数)*(4-平均数)】。】+【(5-平均)*(5-平均)】}/标准偏差(1,2,3,4,5)*标准偏差(1,2,3,4,5)。数据小于3个1和2的平均数 devdwBuffer={【(1-平均数)*(1-平均数)】。+【(2-平均)*(2-平均)】}/标准偏差(1,2,3,4,5)*标准偏差(1,2,3,4,5)。
为什么这个EA不能买入或卖出?
嗨,我是使用Meta编程的新手......请帮助我......
我正在使用一个有两个级别的随机指数系统,25和75...
只有一个交易...
如果主线和信号都在25以下,并有交叉,买入。
如果主线和信号线在25以上交叉,关闭买入。
如果MAIN和SIGNAL都在75以上并且交叉,卖出。
如果主线和信号线交叉(不需要低于75),关闭卖出。
就是这样...
//| StochCross.mq4 |
//| RobertEli |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "RobertEli"
#property link "http://www.metaquotes.net"
//--- input parameters
extern double TakeProfit=250.0;
extern double Lots=0.01;
extern double TrailingStop=35.0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int Confirm (double line1, double line2, int level_buy, int level_sell)
{
static int confirmation = 0;
if ((line1 < level_buy) && (line2 < level_buy)) confirmation = 1; //confirm BUY, when two lines are below level_buy
if ((line1 > level_sell) && (line2 > level_sell)) confirmation = 2; //confirm SELL, when two lines are above level_sell
if ((line1 > level_buy) && (line2 > level_buy)) confirmation = 3; //confirm CLOSE BUY, when two lines are above level_buy
if ((line1 < level_sell) && (line2 < level_sell)) confirmation = 4; //confirm CLOSE SELL, when two lines are below level_sell
//if ((line1 > level_buy_close) && (line2 > level_buy_close)) confirmation = 3; //confirm CLOSE BUY
//if ((line1 < level_sell_close) && (line2 < level_sell_close)) confirmation = 4; //confirm CLOSE SELL
//else return (0);
return (confirmation);
}
int Crossed (double line1, double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if (line1 > line2) current_direction = 1; //UP
if (line1 < line2) current_direction = 2; //DOWN
if (current_direction != last_direction) //changed direction
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int cnt, ticket;
double Stoch_main, Stoch_sign;
if (Bars < 100)
{
Print("BARS less than 100");
return (0);
}
if (TakeProfit < 10)
{
Print("TakeProfit less than 10");
return (0);
}
/*
Stoch_main = iStochastic (NULL,15,21,8,13,MODE_SMA,1,MODE_MAIN,0);
Stoch_sign = iStochastic (NULL,15,21,8,13,MODE_SMA,1,MODE_SIGNAL,0);
*/
Stoch_main = iStochastic (NULL,0,30,20,12,MODE_SMA,1,MODE_MAIN,0);
Stoch_sign = iStochastic (NULL,0,30,20,12,MODE_SMA,1,MODE_SIGNAL,0);
/*
Stoch_main = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,0);
Stoch_sign = iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,0);
*/
int isCrossed = Crossed(Stoch_main,Stoch_sign);
int isConfirmed = Confirm(Stoch_main,Stoch_sign,25,75);
int total = OrdersTotal();
if (total == 0)
{
if ((isCrossed == 1) && (isConfirmed == 1))
{
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"Buy at " + Ask,24848,0,Green);
if (ticket > 0)
{
if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY Order opened: " +Ask ,OrderOpenPrice());
else Print ("Error Opening BUY Order: ", GetLastError());
return (0);
}
}
if ((isCrossed == 2) && (isConfirmed == 2))
{
ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"Sell at " + Bid,24848,0,Red);
if (ticket > 0)
{
if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL Order opened: " +Bid ,OrderOpenPrice());
else Print ("Error Opening SELL Order: ", GetLastError());
return (0);
}
}
return (0);
}
else
{
for (cnt = total; cnt < 0; cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY) //the trade was a Buy position
{ //check for closing)
if ((isCrossed == 2) && (isConfirmed == 3))
//if (isCrossed == 2)
{ //change of direction
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); //close Buy position
return (0);
}
}
else // the trade was a SELL position
{
//should it be closed?
//if ((isCrossed == 1) && (isConfirmed == 4))
if (isCrossed == 1) //Closing the SELL need not to be below the level_buy... it's very dangerous to wait for it...
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //Sell position is now closed
return (0);
}
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+EA不能做它应该做的事,请帮助我!
你好,我对mq4编程很陌生,但我读过codersgurus的教程(非常感谢!),所以我想我能理解一些东西......。但是,我做了这个基于移动平均数的EA......但它很糟糕地没有按照应有的方式运行!这里的规则非常简单......。
这里的规则非常简单...
1.MA_04_1H(指1小时时间框架 的移动平均线周期4)高于MA_14_1H。
用MA_04_4H高于MA_14_4H来确认(趋势是向上的)------>买入!
2.MA_04_1H在MA_14_1H下方交叉。
当MA_04_4H低于MA_14_4H时确认(趋势是向下的)------> 卖出!
3. 当MA_04_1H与MA_14_1H交叉时,关闭该订单(鉴于规则#1和#2,它可以开始一个新的订单)
4.只做一笔交易...(如果买入,关闭买入。之后,如果有必要,卖出)
我做了2个函数。交叉,和确认。
交叉是针对1小时的时间框架。
确认是针对4小时的时间框架。
谁能帮我调试一下这个东西?
//| MACross1TradeOnly.mq4 |
//| RobertEli |
//| |
//+------------------------------------------------------------------+
// this will work on MA_04, and MA__14
#property copyright "RobertEli"
#property link ""
extern double Lots = 0.01;
extern int stoploss_value = 10; // $10
bool up = 0, //UP direction, when MA_04 is above MA_14
down = 0, //DOWN direction, when MA_14 is above MA_04
change = 0, //when the MA_04 and MA_14 cross
firsttime = true; //first time for direction_prev
int direction_curr = 0; // 1 if UP, 2 if down...
int direction_prev = 0; // this will hold previous value of direction_curr
int direction_trend= 0; // trend direction for confirmation
int cross = 0; // if direction_curr and direction_prev changes course
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int Crossed (double line1, double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if (line1 - line2 > 0)//(line1 > line2)
{
current_direction = 1; //UP
if (firsttime == true)
{
current_direction = 0;
last_direction = 1;
firsttime = false;
return (0);
}
}
if (line1 - line2 < 0)//(line1 < line2)
{
current_direction = 2; //DOWN
if (firsttime == true)
{
current_direction = 0;
last_direction = 2;
firsttime = false;
return (0);
}
}
if ((current_direction != last_direction) && (firsttime == false)) //changed direction
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (last_direction);
}
}
int Confirmed (double line1, double line2)
{
int trend;
if (line1 > line2) trend = 1; // trend direction is UP
if (line1 < line2) trend = 2; // trend direction is DOWN
return (trend);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int cnt,ticket, total;
//double MA_04, MA_07 , MA_14 , MA_21 , MA_28; //MOVING AVERAGES with their corresponding period
if (Bars < 100) { Print ("Bars less than 100."); return (0); }
double MA_04_1H = iMA(NULL,60,04,0,MODE_EMA,PRICE_CLOSE,0);
double MA_14_1H = iMA(NULL,60,14,0,MODE_EMA,PRICE_CLOSE,0);
double MA_04_4H = iMA(NULL,240,04,0,MODE_EMA,PRICE_CLOSE,0);
double MA_14_4H = iMA(NULL,240,14,0,MODE_EMA,PRICE_CLOSE,0);
//double stoploss = stoploss_value / (Lots * 100000);
//new code from v_1
cross = Crossed (MA_04_1H,MA_14_1H); // =1 for UP, =2 for DOWN
direction_trend = Confirmed (MA_04_4H, MA_14_4H); // =1 for UP, =2 for DOWN
total = OrdersTotal();
if (total == 0)
{
if((cross == 1) && (direction_trend == 1))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,/*Ask-stoploss*/0,0,"Buy at: "+ Ask,12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice(),",<<<<",OrderStopLoss());
}
else Print("Error opening BUY order : ",GetLastError());
cross = 0;
return(0);
}
if((cross == 2) && (direction_trend == 2))
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,/*Bid+stoploss*/0,0,"Sell at: "+ Bid,12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
cross = 0;
return(0);
}
}
if (total == 1)
{
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
// bool no_buy_sell = ((OrderTakeProfit() 0));
if ((OrderType()==OP_BUY) && (cross == 2) )// && (no_buy_sell))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
//OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+stoploss,0,"Sell at: "+ Bid,12345,0,Red);
return (0);
}
else if ((OrderType()==OP_SELL) && (cross == 1) )// && (no_buy_sell))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
//OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-stoploss,0,"Buy at: "+ Ask,12345,0,Green);
return (0);
}
}
}
else return (0);
//----
return(0);
}
//+------------------------------------------------------------------+请忽略我之前的帖子......我已经放弃了那个想法......我现在正在做这个......所以请帮助我......