初学者的问题 MQL5 MT5 MetaTrader 5 - 页 1323 1...131613171318131913201321132213231324132513261327132813291330...1503 新评论 Sprut 185 2021.06.30 22:13 #13221 Alexey Viktorov:马丁应该只在指标信号相反时激活,还是不管?例如:根据指标建立了一个买入头寸。价格已经下跌了设定的距离,指标已经显示为卖出。应建立一个买入头寸? 简而言之,.....Martin只对趋势起作用,订单是向下的,而指标只对趋势起作用。 明天我将尝试在Photoshop上绘制它,我将发布文件。 SanAlex 2021.06.30 22:57 #13222 Sprut 185 :简而言之 - 同时.....马丁只逆势工作,订单为红色,根据指标,我们只处理趋势。明天我将尝试在Photoshop上绘制并发布文件我在这里做了一些事情——我自己用 100,000 卢布不明白。高达两百万 //+------------------------------------------------------------------+ //| 6 Sprut 185.mq5 | //| Copyright 2021, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Ltd." #property link " https://www.mql5.com " #property version "1.00" //--- #define MACD_MAGIC 1234502 //--- #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\PositionInfo.mqh> #include <Trade\AccountInfo.mqh> //--- double m_adjusted_point; // point value adjusted for 3 or 5 points CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object CPositionInfo m_position; // trade position object CAccountInfo m_account; // account info wrapper input group "---- : Parameters: ----" input int InpTProfit = 100000 ; // : Take Profit --> (In currency the amount) input double InpLotsRisk = 0.1 ; // : Maximum Risk in percentage input group "---- : Parameters: ----" input bool InpClOp = false ; // : Close opposite //--- int m_price_uno; int m_handle_macd; // MACD indicator handle int ExtTimeOut= 10 ; // time out in seconds between trade operations //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double OptimizedBuy( void ) { double PROFIT_BUY= 0.00 ; int total= PositionsTotal (); for ( int i=total- 1 ; i>= 0 ; i--) // returns the number of open positions { string position_GetSymbol= PositionGetSymbol (i); // GetSymbol позиции if (position_GetSymbol==m_symbol.Name()) { if (m_position.PositionType()== POSITION_TYPE_BUY ) { PROFIT_BUY=PROFIT_BUY+m_position.Select( Symbol ()); } } } double Lots=InpLotsRisk; double ab=PROFIT_BUY; if (ab> 0 && ab<= 1 ) Lots=InpLotsRisk* 2 ; if (ab> 1 && ab<= 2 ) Lots=InpLotsRisk* 4 ; if (ab> 2 && ab<= 3 ) Lots=InpLotsRisk* 8 ; if (ab> 3 ) Lots=InpLotsRisk* 16 ; return (Lots); } //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double OptimizedSell( void ) { double PROFIT_SELL= 0.00 ; int total= PositionsTotal (); for ( int i=total- 1 ; i>= 0 ; i--) // returns the number of open positions { string position_GetSymbol= PositionGetSymbol (i); // GetSymbol позиции if (position_GetSymbol==m_symbol.Name()) { if (m_position.PositionType()== POSITION_TYPE_SELL ) { PROFIT_SELL=PROFIT_SELL+m_position.Select( Symbol ()); } } } double Lots=InpLotsRisk; double ab=PROFIT_SELL; if (ab> 0 && ab<= 1 ) Lots=InpLotsRisk* 2 ; if (ab> 1 && ab<= 2 ) Lots=InpLotsRisk* 4 ; if (ab> 2 && ab<= 3 ) Lots=InpLotsRisk* 8 ; if (ab> 3 ) Lots=InpLotsRisk* 16 ; return (Lots); } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit () { //--- initialize common information m_symbol.Name( Symbol ()); // symbol m_trade.SetExpertMagicNumber(MACD_MAGIC); // magic m_trade.SetMarginMode(); m_trade.SetTypeFillingBySymbol( Symbol ()); //--- tuning for 3 or 5 digits int digits_adjust= 1 ; if (m_symbol. Digits ()== 3 || m_symbol. Digits ()== 5 ) digits_adjust= 10 ; m_adjusted_point=m_symbol. Point ()*digits_adjust; //--- set default deviation for trading in adjusted points m_trade.SetDeviationInPoints( 3 *digits_adjust); //--- create MACD indicator m_handle_macd= iCustom ( NULL , 0 , "StepMA_NRTR" ); if (m_handle_macd== INVALID_HANDLE ) { printf ( "Error creating MACD indicator" ); return ( false ); } //--- return ( INIT_SUCCEEDED ); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit ( const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick ( void ) { //--- if (ProfitBuy() || ProfitSell()) { return ; } static datetime limit_time= 0 ; // last trade processing time + timeout //--- don't process if timeout if ( TimeCurrent ()>=limit_time) { //--- check for data if ( Bars ( Symbol (), Period ())> 2 ) { //--- change limit time by timeout in seconds if processed if (Processing()) limit_time= TimeCurrent ()+ExtTimeOut; } } } //+------------------------------------------------------------------+ //| main function returns true if any position processed | //+------------------------------------------------------------------+ bool Processing( void ) { //--- refresh rates if (!m_symbol.RefreshRates()) return ( false ); double m_buff_MACD_main[],m_buff_MACD_signal[]; bool StNRUp,StNRDn; ArraySetAsSeries (m_buff_MACD_main, true ); ArraySetAsSeries (m_buff_MACD_signal, true ); int start_pos= 1 ,count= 3 ; if (!iGetArray(m_handle_macd, 0 ,start_pos,count,m_buff_MACD_main)|| !iGetArray(m_handle_macd, 1 ,start_pos,count,m_buff_MACD_signal)) { return ( false ); } //--- StNRUp=m_buff_MACD_main[ 0 ]<m_buff_MACD_signal[ 0 ]; StNRDn=m_buff_MACD_main[ 0 ]>m_buff_MACD_signal[ 0 ]; //--- BUY Signal if (StNRUp) { if (InpClOp) if (ShortClosed()) Sleep ( 1000 ); if (m_price_uno< 0 ) LongOpened(); m_price_uno=+ 1 ; return ( true ); } //--- SELL Signal if (StNRDn) { if (InpClOp) if (LongClosed()) Sleep ( 1000 ); if (m_price_uno> 0 ) ShortOpened(); m_price_uno=- 1 ; return ( true ); } //--- exit without position processing return ( false ); } //+------------------------------------------------------------------+ //| Check for long position closing | //+------------------------------------------------------------------+ bool LongClosed( void ) { bool res= false ; //--- should it be closed? ClosePositions( POSITION_TYPE_BUY ); //--- processed and cannot be modified res= true ; //--- result return (res); } //+------------------------------------------------------------------+ //| Check for short position closing | //+------------------------------------------------------------------+ bool ShortClosed( void ) { bool res= false ; //--- should it be closed? ClosePositions( POSITION_TYPE_SELL ); //--- processed and cannot be modified res= true ; //--- result return (res); } //+------------------------------------------------------------------+ //| Check for long position opening | //+------------------------------------------------------------------+ bool LongOpened( void ) { bool res= false ; //--- check for long position (BUY) possibility double price=m_symbol.Ask(); //--- check for free money if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_BUY ,OptimizedBuy(),price)< 0.0 ) printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin()); else { //--- open position if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_BUY ,OptimizedBuy(),price, 0.0 , 0.0 )) printf ( "Position by %s to be opened" , Symbol ()); else { printf ( "Error opening BUY position by %s : '%s'" , Symbol (),m_trade.ResultComment()); printf ( "Open parameters : price=%f" ,price); } PlaySound ( "ok.wav" ); } //--- in any case we must exit from expert res= true ; //--- result return (res); } //+------------------------------------------------------------------+ //| Check for short position opening | //+------------------------------------------------------------------+ bool ShortOpened( void ) { bool res= false ; //--- check for short position (SELL) possibility double price=m_symbol.Bid(); //--- check for free money if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_SELL ,OptimizedSell(),price)< 0.0 ) printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin()); else { //--- open position if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_SELL ,OptimizedSell(),price, 0.0 , 0.0 )) printf ( "Position by %s to be opened" , Symbol ()); else { printf ( "Error opening SELL position by %s : '%s'" , Symbol (),m_trade.ResultComment()); printf ( "Open parameters : price=%f" ,price); } PlaySound ( "ok.wav" ); } //--- in any case we must exit from expert res= true ; //--- result return (res); } //+------------------------------------------------------------------+ //| Refreshes the symbol quotes data | //+------------------------------------------------------------------+ bool RefreshRates() { //--- refresh rates if (!m_symbol.RefreshRates()) { return ( false ); } //--- protection against the return value of "zero" if (m_symbol.Ask()== 0 || m_symbol.Bid()== 0 ) { return ( false ); } //--- return ( true ); } //+------------------------------------------------------------------+ //| Check Freeze and Stops levels | //+------------------------------------------------------------------+ void FreezeStopsLevels( double &freeze, double &stops) { //--- check Freeze and Stops levels double coeff=( double ) 1 ; if (!RefreshRates() || !m_symbol.Refresh()) return ; //--- FreezeLevel -> for pending order and modification double freeze_level=m_symbol.FreezeLevel()*m_symbol. Point (); if (freeze_level== 0.0 ) if ( 1 > 0 ) freeze_level=(m_symbol.Ask()-m_symbol.Bid())*coeff; //--- StopsLevel -> for TakeProfit and StopLoss double stop_level=m_symbol.StopsLevel()*m_symbol. Point (); if (stop_level== 0.0 ) if ( 1 > 0 ) stop_level=(m_symbol.Ask()-m_symbol.Bid())*coeff; //--- freeze=freeze_level; stops=stop_level; //--- return ; } //+------------------------------------------------------------------+ //| Close positions | //+------------------------------------------------------------------+ void ClosePositions( const ENUM_POSITION_TYPE pos_type) { double freeze= 0.0 ,stops= 0.0 ; FreezeStopsLevels(freeze,stops); for ( int i= PositionsTotal ()- 1 ; i>= 0 ; i--) // returns the number of current positions if (m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if (m_position. Symbol ()==m_symbol.Name() && m_position.Magic()==MACD_MAGIC) if (m_position.PositionType()==pos_type) { if (m_position.PositionType()== POSITION_TYPE_BUY ) { bool take_profit_level=((m_position.TakeProfit()!= 0.0 && m_position.TakeProfit()-m_position.PriceCurrent()>=freeze) || m_position.TakeProfit()== 0.0 ); bool stop_loss_level=((m_position.StopLoss()!= 0.0 && m_position.PriceCurrent()-m_position.StopLoss()>=freeze) || m_position.StopLoss()== 0.0 ); if (take_profit_level && stop_loss_level) if (!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol Print ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "BUY PositionClose " ,m_position.Ticket(), ", " ,m_trade.ResultRetcodeDescription()); } if (m_position.PositionType()== POSITION_TYPE_SELL ) { bool take_profit_level=((m_position.TakeProfit()!= 0.0 && m_position.PriceCurrent()-m_position.TakeProfit()>=freeze) || m_position.TakeProfit()== 0.0 ); bool stop_loss_level=((m_position.StopLoss()!= 0.0 && m_position.StopLoss()-m_position.PriceCurrent()>=freeze) || m_position.StopLoss()== 0.0 ); if (take_profit_level && stop_loss_level) if (!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol Print ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "SELL PositionClose " ,m_position.Ticket(), ", " ,m_trade.ResultRetcodeDescription()); } PlaySound ( "ok.wav" ); } } //+------------------------------------------------------------------+ //| Filling the indicator buffers from the indicator | //+------------------------------------------------------------------+ bool iGetArray( const int handle, const int buffer, const int start_pos, const int count, double &arr_buffer[]) { bool result= true ; if (! ArrayIsDynamic (arr_buffer)) { return ( false ); } ArrayFree (arr_buffer); //--- reset error code ResetLastError (); //--- fill a part of the iBands array with values from the indicator buffer int copied= CopyBuffer (handle,buffer,start_pos,count,arr_buffer); if (copied!=count) { return ( false ); } return (result); } //+------------------------------------------------------------------+ //| ProfitOnTick closing | //+------------------------------------------------------------------+ bool ProfitBuy( void ) { bool res= false ; double PROFIT_BUY= 0.00 ; int total= PositionsTotal (); for ( int i=total- 1 ; i>= 0 ; i--) { string position_GetSymbol= PositionGetSymbol (i); if (position_GetSymbol==m_symbol.Name()) { if (m_position.PositionType()== POSITION_TYPE_BUY ) { PROFIT_BUY=PROFIT_BUY+ PositionGetDouble ( POSITION_PROFIT ); } } if (PROFIT_BUY>=InpTProfit) { if (LongClosed()) res= true ; if (ShortOpened()) res= true ; } } return (res); } //+------------------------------------------------------------------+ //| ProfitOnTick closing | //+------------------------------------------------------------------+ bool ProfitSell( void ) { bool res= false ; double PROFIT_SELL= 0.00 ; int total= PositionsTotal (); for ( int i=total- 1 ; i>= 0 ; i--) { string position_GetSymbol= PositionGetSymbol (i); if (position_GetSymbol==m_symbol.Name()) { if (m_position.PositionType()== POSITION_TYPE_SELL ) { PROFIT_SELL=PROFIT_SELL+ PositionGetDouble ( POSITION_PROFIT ); } } if (PROFIT_SELL>=InpTProfit) { if (ShortClosed()) res= true ; if (LongOpened()) res= true ; } } return (res); } //+------------------------------------------------------------------+ Vitaly Muzichenko 2021.06.30 23:01 #13223 现在需要给它重新命名,有了这样的测试,它肯定是鲱鱼,或者是偷来的,不知道什么是正确的。 //+------------------------------------------------------------------+ //| 6 Сопрут 185.mq5 | //| Copyright 2021, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ SanAlex 2021.06.30 23:08 #13224 Vitaly Muzichenko:我们现在需要给它重新命名,有了这样一个测试,它肯定会被窜改,或者被偷,我不知道什么是正确的词。 也许有人会发财--我不明白,我喜欢适度的生活。 Vitaly Muzichenko 2021.06.30 23:36 #13225 SanAlex:也许有人会发财--我不明白,我只是喜欢适度地生活。 这是我两年多来在测试器中运行的第一个EA。 我现在正在处理测试器,一切都发生了很大的变化,出现了许多不同的按钮。 到目前为止,我得出的结论是,我应该把它放在演示版上并运行几个星期。 无论如何,我已经偷了它;) Ivan Nagibin 2021.07.01 05:21 #13226 Aleksei Stepanenko:这不就是它的作用吗? 我也是这么做的,但缓冲区仍然为0,你可以自己试试。我唯一不明白的是我的mt5中的IndicatorBuffers()函数,我使用#propertyindicatorbuffers Fast235 2021.07.01 06:31 #13227 SanAlex:我在这里做错了什么--我不知道什么东西从10万卢布变成了200万。 你不应该这样做,他们即将在市场上推出它。 SanAlex 2021.07.01 07:16 #13228 Fast235:你不应该,他们即将在市场上推出它。 我不在乎--至少我在学习中会有所收获。我的脑海中有更多的想法。 \\\\\\\\\\\\\\\\\\\\ 你只需要两个功能。而且它们需要由编程专家适当改写,因为我是个学徒。 这些是功能 1.- 1.它们是手数倍增器。第一个位置被打开,然后第二个位置被倍增,以此类推。第一个位置被打开,然后第二个位置被乘以,以此类推。 //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double OptimizedBuy(void) { double PROFIT_BUY=0.00; int total=PositionsTotal(); for(int i=total-1; i>=0; i--) // returns the number of open positions { string position_GetSymbol=PositionGetSymbol(i); // GetSymbol позиции if(position_GetSymbol==m_symbol.Name()) { if(m_position.PositionType()==POSITION_TYPE_BUY) { PROFIT_BUY=PROFIT_BUY+m_position.Select(Symbol()); } } } double Lots=InpLotsRisk; double ab=PROFIT_BUY; if(ab>0 && ab<=1) Lots=InpLotsRisk*2; if(ab>1 && ab<=2) Lots=InpLotsRisk*4; if(ab>2 && ab<=3) Lots=InpLotsRisk*8; if(ab>3) Lots=InpLotsRisk*16; return(Lots); } //+------------------------------------------------------------------+ 和2 - 它关闭了货币的总金额,在买入中打开的头寸。 //+------------------------------------------------------------------+ //| ProfitOnTick closing | //+------------------------------------------------------------------+ bool ProfitBuy(void) { bool res=false; double PROFIT_BUY=0.00; int total=PositionsTotal(); for(int i=total-1; i>=0; i--) { string position_GetSymbol=PositionGetSymbol(i); if(position_GetSymbol==m_symbol.Name()) { if(m_position.PositionType()==POSITION_TYPE_BUY) { PROFIT_BUY=PROFIT_BUY+PositionGetDouble(POSITION_PROFIT); } } if(PROFIT_BUY>=InpTProfit) { if(LongClosed()) res=true; if(ShortOpened()) res=true; } } return(res); } //+------------------------------------------------------------------+ 当然还有下半场 Fast235 2021.07.01 07:18 #13229 SanAlex:我的脑海中有更多的想法。我的脑海中有更多的想法。 然后你应该把它放在代码库中,如果它值得的话。 SanAlex 2021.07.01 07:50 #13230 Vitaly Muzichenko:这是我两年多来在测试器中运行的第一个EA。我正在努力理解测试器,一切都发生了很大的变化,出现了很多不同的按钮。到目前为止,我得出的结论是,我应该把它放在演示版上并运行几个星期。简而言之,我偷了它;) 我还用专家顾问测试了一下--它在某种程度上取决于收盘金额。如果你投入较少的金额,它就会损失,如果你投入更多,它也会损失。 我在测试10万卢比和10万卢比 的利润,结果涨到了200万(去年在欧元/美元的1小时内)。 1...131613171318131913201321132213231324132513261327132813291330...1503 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
马丁应该只在指标信号相反时激活,还是不管?
例如:根据指标建立了一个买入头寸。价格已经下跌了设定的距离,指标已经显示为卖出。应建立一个买入头寸?
简而言之,.....Martin只对趋势起作用,订单是向下的,而指标只对趋势起作用。
明天我将尝试在Photoshop上绘制它,我将发布文件。
简而言之 - 同时.....马丁只逆势工作,订单为红色,根据指标,我们只处理趋势。
明天我将尝试在Photoshop上绘制并发布文件
我在这里做了一些事情——我自己用 100,000 卢布不明白。高达两百万
现在需要给它重新命名,有了这样的测试,它肯定是鲱鱼,或者是偷来的,不知道什么是正确的。
我们现在需要给它重新命名,有了这样一个测试,它肯定会被窜改,或者被偷,我不知道什么是正确的词。
也许有人会发财--我不明白,我喜欢适度的生活。
也许有人会发财--我不明白,我只是喜欢适度地生活。
这是我两年多来在测试器中运行的第一个EA。
我现在正在处理测试器,一切都发生了很大的变化,出现了许多不同的按钮。
到目前为止,我得出的结论是,我应该把它放在演示版上并运行几个星期。
无论如何,我已经偷了它;)
这不就是它的作用吗?
我在这里做错了什么--我不知道什么东西从10万卢布变成了200万。
你不应该这样做,他们即将在市场上推出它。
你不应该,他们即将在市场上推出它。
我不在乎--至少我在学习中会有所收获。我的脑海中有更多的想法。
\\\\\\\\\\\\\\\\\\\\
你只需要两个功能。而且它们需要由编程专家适当改写,因为我是个学徒。
这些是功能
1.- 1.它们是手数倍增器。第一个位置被打开,然后第二个位置被倍增,以此类推。第一个位置被打开,然后第二个位置被乘以,以此类推。
和2 - 它关闭了货币的总金额,在买入中打开的头寸。
当然还有下半场
我的脑海中有更多的想法。我的脑海中有更多的想法。
然后你应该把它放在代码库中,如果它值得的话。
这是我两年多来在测试器中运行的第一个EA。
我正在努力理解测试器,一切都发生了很大的变化,出现了很多不同的按钮。
到目前为止,我得出的结论是,我应该把它放在演示版上并运行几个星期。
简而言之,我偷了它;)
我还用专家顾问测试了一下--它在某种程度上取决于收盘金额。如果你投入较少的金额,它就会损失,如果你投入更多,它也会损失。
我在测试10万卢比和10万卢比 的利润,结果涨到了200万(去年在欧元/美元的1小时内)。