어떤 식으로든 ORDERS를 제어하지 않으며 코드에서 POSITION의 번호와 유형을 확인합니다. 게다가 - POSITIONS를 잘못 사용했습니다(계정 유형이 헤징인 경우 'PositionSelect(_Symbol)' 사용 오류). 알고리즘에 심각한 설계 오류가 있습니다.
해야 할 일:
1. 새로운 바가 탄생할 때 독점적으로 일하십시오. 새 막대가 없으면 아무 것도하지 말고 불필요한 움직임을 수행하지 마십시오.
2. 이 항목은 1번 항목이 완료된 후 공개됩니다.
안녕하세요 블라디미르님
힌트를 주셔서 다시 한번 감사드립니다. 상황을 파악하는 데 시간이 좀 걸렸습니다.
귀하의 팁을 기반으로 내가 변경한 사항:
- 오픈 및 클로즈 로직을 헷징 버전으로 변경하였습니다.
- 나는 이제 일부 계산/주문 배치를 위한 새로운 막대의 탄생과 함께 일하고 있습니다.
이러한 변경 사항이 적용되었기 때문에 주문은 이제 한 번만 열리고 닫힙니다. 하지만 지금은 백테스팅에 문제가 있습니다. 121행의 배열이 범위를 벗어났다는 오류가 발생합니다. 올바른 방향으로 나를 가리켜 주시겠습니까? 종가와 copyClose에 이중 유형의 배열을 사용하려고 시도했지만 여전히 오류가 발생합니다.
하지만 직접 해보면 정말 그렇게 어렵나요?
하지만 직접 해보면 정말 그렇게 어렵나요?
나는 그것을 시도했다.
"스위치"에 대한 F1의 내부 도움말 때문에 그런 질문이 있었기 때문입니다. 거기에는 Print만 지정됩니다. 그리고 앞서 언급한 논평() 무효 OnTick() 코드 실행이 크게 느려집니다.
아무도 내가 이것을 할 수 있는 방법에 대해 나를 도울 수 있습니까?
kduarte 로그인을 사용하고 있고 MQL5 계정 비밀번호가 10자 이하인지 확인하십시오.
어떤 식으로든 ORDERS를 제어하지 않으며 코드에서 POSITION의 번호와 유형을 확인합니다. 게다가 - POSITIONS를 잘못 사용했습니다(계정 유형이 헤징인 경우 'PositionSelect(_Symbol)' 사용 오류). 알고리즘에 심각한 설계 오류가 있습니다.
해야 할 일:
1. 새로운 바가 탄생할 때 독점적으로 일하십시오. 새 막대가 없으면 아무 것도하지 말고 불필요한 움직임을 수행하지 마십시오.
2. 이 항목은 1번 항목이 완료된 후 공개됩니다.
안녕하세요 블라디미르님
힌트를 주셔서 다시 한번 감사드립니다. 상황을 파악하는 데 시간이 좀 걸렸습니다.
귀하의 팁을 기반으로 내가 변경한 사항:
- 오픈 및 클로즈 로직을 헷징 버전으로 변경하였습니다.
- 나는 이제 일부 계산/주문 배치를 위한 새로운 막대의 탄생과 함께 일하고 있습니다.
이러한 변경 사항이 적용되었기 때문에 주문은 이제 한 번만 열리고 닫힙니다. 하지만 지금은 백테스팅에 문제가 있습니다. 121행의 배열이 범위를 벗어났다는 오류가 발생합니다. 올바른 방향으로 나를 가리켜 주시겠습니까? 종가와 copyClose에 이중 유형의 배열을 사용하려고 시도했지만 여전히 오류가 발생합니다.
2번 항목도 기대해주세요 :)
지금까지 코드:
노란색으로 121행을 강조 표시했습니다.
작업 결과를 확인하십시오.
작업 결과를 확인하십시오.
위험 비율을 로트 크기로 변경하거나 EA 분류에서 로트를 수정하는 방법 전문가: 분류.
//+------------------------------------------------------------------+ //| breakdown(barabashkakvn's edition).mq5 | //| Arist0 | //| arist0.rr@gmail.com | //+------------------------------------------------------------------+ #property copyright "Arist0" #property link "arist0.rr@gmail.com" #property version "1.001" //--- #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\AccountInfo.mqh> #include <Trade\OrderInfo.mqh> #include <Expert\Money\MoneyFixedMargin.mqh> CPositionInfo m_position; // trade position object CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object CAccountInfo m_account; // account info wrapper COrderInfo m_order; // pending orders object CMoneyFixedMargin *m_money; //--- input parameters input ushort InpStopLoss = 50 ; // Stop Loss (in pips) input ushort InpTakeProfit = 50 ; // Take Profit (in pips) input ushort InpTrailingStop = 5 ; // Trailing Stop (in pips) input ushort InpTrailingStep = 5 ; // Trailing Step (in pips) input ushort InpMinDistance = 25 ; // Minimum distance input double Risk = 5 ; // Risk in percent for a deal from a free margin input ulong m_magic = 585000550 ; // magic number //--- ulong m_slippage= 10 ; // slippage double ExtStopLoss= 0.0 ; double ExtTakeProfit= 0.0 ; double ExtTrailingStop= 0.0 ; double ExtTrailingStep= 0.0 ; double ExtMinDistance= 0.0 ; double m_adjusted_point; // point value adjusted for 3 or 5 points bool bln_delete_all= false ; datetime dt_last_delete= 0 ; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit () { if (InpTrailingStop!= 0 && InpTrailingStep== 0 ) { string text=( TerminalInfoString ( TERMINAL_LANGUAGE )== "Russian" )? "Трейлинг невозможен: параметр \"Trailing Step\" равен нулю!" : "Trailing is not possible: parameter \"Trailing Step\" is zero!" ; Alert ( __FUNCTION__ , " ERROR! " ,text); return ( INIT_PARAMETERS_INCORRECT ); } if (!m_symbol.Name( Symbol ())) // sets symbol name return ( INIT_FAILED ); RefreshRates(); //--- m_trade.SetExpertMagicNumber(m_magic); m_trade.SetMarginMode(); m_trade.SetTypeFillingBySymbol(m_symbol.Name()); m_trade.SetDeviationInPoints(m_slippage); //--- 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; ExtStopLoss = InpStopLoss * m_adjusted_point; ExtTakeProfit = InpTakeProfit * m_adjusted_point; ExtTrailingStop= InpTrailingStop * m_adjusted_point; ExtTrailingStep= InpTrailingStep * m_adjusted_point; ExtMinDistance = InpMinDistance * m_adjusted_point; //--- if (m_money!= NULL ) delete m_money; m_money= new CMoneyFixedMargin; if (m_money!= NULL ) { if (!m_money.Init( GetPointer (m_symbol), Period (),m_symbol. Point ()*digits_adjust)) return ( INIT_FAILED ); m_money.Percent(Risk); } else { Print ( __FUNCTION__ , ", ERROR: Object CMoneyFixedMargin is NULL" ); return ( INIT_FAILED ); } //--- bln_delete_all= false ; dt_last_delete= 0 ; //--- return ( INIT_SUCCEEDED ); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit ( const int reason) { //--- if (m_money!= NULL ) delete m_money; } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick () { //--- if (bln_delete_all) { if (IsPendingOrdersExists()) { DeleteAllPendingOrders(); //dt_last_delete=iTime(m_symbol.Name(),Period(),0); return ; } else { bln_delete_all= false ; dt_last_delete= iTime (m_symbol.Name(), PERIOD_D1 , 0 ); } } //--- if (IsPendingOrdersExists() && dt_last_delete< iTime (m_symbol.Name(), PERIOD_D1 , 0 )) { bln_delete_all= true ; return ; } //--- if (!IsPendingOrdersExists()) { if (!RefreshRates()) return ; //--- double price= iHigh (m_symbol.Name(), PERIOD_D1 , 1 )+ExtMinDistance; double sl=(InpStopLoss== 0 )? 0.0 :price-ExtStopLoss; double tp=(InpTakeProfit== 0 )? 0.0 :price+ExtTakeProfit; PendingBuyStop(price,sl,tp); //--- price= iLow (m_symbol.Name(), PERIOD_D1 , 1 )-ExtMinDistance; sl=(InpStopLoss== 0 )? 0.0 :price+ExtStopLoss; tp=(InpTakeProfit== 0 )? 0.0 :price-ExtTakeProfit; PendingSellStop(price,sl,tp); dt_last_delete= iTime (m_symbol.Name(), PERIOD_D1 , 0 ); return ; } //--- Trailing(); } //+------------------------------------------------------------------+ //| TradeTransaction function | //+------------------------------------------------------------------+ void OnTradeTransaction ( const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { //--- double res= 0.0 ; int losses= 0.0 ; //--- get transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type=trans.type; //--- if transaction is result of addition of the transaction in history if (type== TRADE_TRANSACTION_DEAL_ADD ) { long deal_ticket = 0 ; long deal_order = 0 ; long deal_time = 0 ; long deal_time_msc = 0 ; long deal_type =- 1 ; long deal_entry =- 1 ; long deal_magic = 0 ; long deal_reason =- 1 ; long deal_position_id = 0 ; double deal_volume = 0.0 ; double deal_price = 0.0 ; double deal_commission = 0.0 ; double deal_swap = 0.0 ; double deal_profit = 0.0 ; string deal_symbol = "" ; string deal_comment = "" ; string deal_external_id = "" ; if ( HistoryDealSelect (trans.deal)) { deal_ticket = HistoryDealGetInteger (trans.deal, DEAL_TICKET ); deal_order = HistoryDealGetInteger (trans.deal, DEAL_ORDER ); deal_time = HistoryDealGetInteger (trans.deal, DEAL_TIME ); deal_time_msc = HistoryDealGetInteger (trans.deal, DEAL_TIME_MSC ); deal_type = HistoryDealGetInteger (trans.deal, DEAL_TYPE ); deal_entry = HistoryDealGetInteger (trans.deal, DEAL_ENTRY ); deal_magic = HistoryDealGetInteger (trans.deal, DEAL_MAGIC ); deal_reason = HistoryDealGetInteger (trans.deal, DEAL_REASON ); deal_position_id = HistoryDealGetInteger (trans.deal, DEAL_POSITION_ID ); deal_volume = HistoryDealGetDouble (trans.deal, DEAL_VOLUME ); deal_price = HistoryDealGetDouble (trans.deal, DEAL_PRICE ); deal_commission = HistoryDealGetDouble (trans.deal, DEAL_COMMISSION ); deal_swap = HistoryDealGetDouble (trans.deal, DEAL_SWAP ); deal_profit = HistoryDealGetDouble (trans.deal, DEAL_PROFIT ); deal_symbol = HistoryDealGetString (trans.deal, DEAL_SYMBOL ); deal_comment = HistoryDealGetString (trans.deal, DEAL_COMMENT ); deal_external_id = HistoryDealGetString (trans.deal, DEAL_EXTERNAL_ID ); } else return ; if (deal_symbol==m_symbol.Name() && deal_magic==m_magic) if (deal_entry== DEAL_ENTRY_IN ) if (deal_type== DEAL_TYPE_BUY || deal_type== DEAL_TYPE_SELL ) DeleteAllPendingOrders(); } } //+------------------------------------------------------------------+ //| Refreshes the symbol quotes data | //+------------------------------------------------------------------+ bool RefreshRates( void ) { //--- refresh rates if (!m_symbol.RefreshRates()) { Print ( "RefreshRates error" ); return ( false ); } //--- protection against the return value of "zero" if (m_symbol.Ask()== 0 || m_symbol.Bid()== 0 ) return ( false ); //--- return ( true ); } //+------------------------------------------------------------------+ //| Pending order of Buy Stop | //+------------------------------------------------------------------+ void PendingBuyStop( double price, double sl, double tp) { sl=m_symbol.NormalizePrice(sl); tp=m_symbol.NormalizePrice(tp); double check_open_long_lot=m_money.CheckOpenLong(m_symbol.Ask(),sl); Print ( "sl=" , DoubleToString (sl,m_symbol. Digits ()), ", CheckOpenLong: " , DoubleToString (check_open_long_lot, 2 ), ", Balance: " , DoubleToString (m_account.Balance(), 2 ), ", Equity: " , DoubleToString (m_account.Equity(), 2 ), ", FreeMargin: " , DoubleToString (m_account.FreeMargin(), 2 )); if (check_open_long_lot== 0.0 ) { Print ( __FUNCTION__ , ", ERROR: method CheckOpenLong returned the value of \"0.0\"" ); return ; } //--- check volume before OrderSend to avoid "not enough money" error (CTrade) double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_long_lot,m_symbol.Ask(), ORDER_TYPE_BUY ); if (check_volume_lot!= 0.0 ) { if (check_volume_lot>=check_open_long_lot) { if (m_trade.BuyStop(check_open_long_lot,m_symbol.NormalizePrice(price), m_symbol.Name(),m_symbol.NormalizePrice(sl),m_symbol.NormalizePrice(tp))) { if (m_trade.ResultOrder()== 0 ) { Print ( "#1 Buy Stop -> false. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); PrintResultTrade(m_trade,m_symbol); } else { Print ( "#2 Buy Stop -> true. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); PrintResultTrade(m_trade,m_symbol); } } else { Print ( "#3 Buy Stop -> false. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); PrintResultTrade(m_trade,m_symbol); } } else { Print ( __FUNCTION__ , ", ERROR: method CheckVolume (" , DoubleToString (check_volume_lot, 2 ), ") " , "< method CheckOpenLong (" + DoubleToString (check_open_long_lot, 2 )+ ")" ); return ; } } else { Print ( __FUNCTION__ , ", ERROR: method CheckVolume returned the value of \"0.0\"" ); return ; } //--- } //+------------------------------------------------------------------+ //| Pending order of Sell Stop | //+------------------------------------------------------------------+ void PendingSellStop( double price, double sl, double tp) { sl=m_symbol.NormalizePrice(sl); tp=m_symbol.NormalizePrice(tp); double check_open_short_lot=m_money.CheckOpenShort(m_symbol.Bid(),sl); Print ( "sl=" , DoubleToString (sl,m_symbol. Digits ()), ", CheckOpenLong: " , DoubleToString (check_open_short_lot, 2 ), ", Balance: " , DoubleToString (m_account.Balance(), 2 ), ", Equity: " , DoubleToString (m_account.Equity(), 2 ), ", FreeMargin: " , DoubleToString (m_account.FreeMargin(), 2 )); if (check_open_short_lot== 0.0 ) { Print ( __FUNCTION__ , ", ERROR: method CheckOpenShort returned the value of \"0.0\"" ); return ; } //--- check volume before OrderSend to avoid "not enough money" error (CTrade) double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_short_lot,m_symbol.Bid(), ORDER_TYPE_SELL ); if (check_volume_lot!= 0.0 ) { if (check_volume_lot>=check_open_short_lot) { if (m_trade.SellStop(check_open_short_lot,m_symbol.NormalizePrice(price), m_symbol.Name(),m_symbol.NormalizePrice(sl),m_symbol.NormalizePrice(tp))) { if (m_trade.ResultOrder()== 0 ) { Print ( "#1 Sell Stop -> false. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); PrintResultTrade(m_trade,m_symbol); } else { Print ( "#2 Sell Stop -> true. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); PrintResultTrade(m_trade,m_symbol); } } else { Print ( "#3 Sell Stop -> false. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); PrintResultTrade(m_trade,m_symbol); } } else { Print ( __FUNCTION__ , ", ERROR: method CheckVolume (" , DoubleToString (check_volume_lot, 2 ), ") " , "< method CheckOpenShort (" + DoubleToString (check_open_short_lot, 2 )+ ")" ); return ; } } else { Print ( __FUNCTION__ , ", ERROR: method CheckVolume returned the value of \"0.0\"" ); return ; } //--- } //+------------------------------------------------------------------+ //| Print CTrade result | //+------------------------------------------------------------------+ void PrintResultTrade(CTrade &trade,CSymbolInfo &symbol) { Print ( "Code of request result: " + IntegerToString (trade.ResultRetcode())); Print ( "code of request result as a string: " +trade.ResultRetcodeDescription()); Print ( "Deal ticket: " + IntegerToString (trade.ResultDeal())); Print ( "Order ticket: " + IntegerToString (trade.ResultOrder())); Print ( "Volume of deal or order: " + DoubleToString (trade.ResultVolume(), 2 )); Print ( "Price, confirmed by broker: " + DoubleToString (trade.ResultPrice(),symbol. Digits ())); Print ( "Current bid price: " + DoubleToString (symbol.Bid(),symbol. Digits ())+ " (the requote): " + DoubleToString (trade.ResultBid(),symbol. Digits ())); Print ( "Current ask price: " + DoubleToString (symbol.Ask(),symbol. Digits ())+ " (the requote): " + DoubleToString (trade.ResultAsk(),symbol. Digits ())); Print ( "Broker comment: " +trade.ResultComment()); } //+------------------------------------------------------------------+ //| Is pendinf orders exists | //+------------------------------------------------------------------+ bool IsPendingOrdersExists( void ) { for ( int i= OrdersTotal ()- 1 ;i>= 0 ;i--) // returns the number of current orders if (m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties if (m_order. Symbol ()==m_symbol.Name() && m_order.Magic()==m_magic) return ( true ); //--- return ( false ); } //+------------------------------------------------------------------+ //| Delete all pending orders | //+------------------------------------------------------------------+ void DeleteAllPendingOrders( void ) { for ( int i= OrdersTotal ()- 1 ;i>= 0 ;i--) // returns the number of current orders if (m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties if (m_order. Symbol ()==m_symbol.Name() && m_order.Magic()==m_magic) m_trade.OrderDelete(m_order.Ticket()); } //+------------------------------------------------------------------+ //| Trailing | //+------------------------------------------------------------------+ void Trailing() { if (InpTrailingStop== 0 ) return ; for ( int i= PositionsTotal ()- 1 ;i>= 0 ;i--) // returns the number of open positions if (m_position.SelectByIndex(i)) if (m_position. Symbol ()==m_symbol.Name() && m_position.Magic()==m_magic) { if (m_position.PositionType()== POSITION_TYPE_BUY ) { if (m_position.PriceCurrent()-m_position.PriceOpen()>ExtTrailingStop+ExtTrailingStep) if (m_position.StopLoss()<m_position.PriceCurrent()-(ExtTrailingStop+ExtTrailingStep)) { if (!m_trade.PositionModify(m_position.Ticket(), m_symbol.NormalizePrice(m_position.PriceCurrent()-ExtTrailingStop), m_position.TakeProfit())) Print ( "Modify " ,m_position.Ticket(), " Position -> false. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); RefreshRates(); m_position.SelectByIndex(i); PrintResultModify(m_trade,m_symbol,m_position); continue ; } } else { if (m_position.PriceOpen()-m_position.PriceCurrent()>ExtTrailingStop+ExtTrailingStep) if ((m_position.StopLoss()>(m_position.PriceCurrent()+(ExtTrailingStop+ExtTrailingStep))) || (m_position.StopLoss()== 0 )) { if (!m_trade.PositionModify(m_position.Ticket(), m_symbol.NormalizePrice(m_position.PriceCurrent()+ExtTrailingStop), m_position.TakeProfit())) Print ( "Modify " ,m_position.Ticket(), " Position -> false. Result Retcode: " ,m_trade.ResultRetcode(), ", description of result: " ,m_trade.ResultRetcodeDescription()); RefreshRates(); m_position.SelectByIndex(i); PrintResultModify(m_trade,m_symbol,m_position); } } } } //+------------------------------------------------------------------+ //| Print CTrade result | //+------------------------------------------------------------------+ void PrintResultModify(CTrade &trade,CSymbolInfo &symbol,CPositionInfo &position) { Print ( "Code of request result: " + IntegerToString (trade.ResultRetcode())); Print ( "code of request result as a string: " +trade.ResultRetcodeDescription()); Print ( "Deal ticket: " + IntegerToString (trade.ResultDeal())); Print ( "Order ticket: " + IntegerToString (trade.ResultOrder())); Print ( "Volume of deal or order: " + DoubleToString (trade.ResultVolume(), 2 )); Print ( "Price, confirmed by broker: " + DoubleToString (trade.ResultPrice(),symbol. Digits ())); Print ( "Current bid price: " + DoubleToString (symbol.Bid(),symbol. Digits ())+ " (the requote): " + DoubleToString (trade.ResultBid(),symbol. Digits ())); Print ( "Current ask price: " + DoubleToString (symbol.Ask(),symbol. Digits ())+ " (the requote): " + DoubleToString (trade.ResultAsk(),symbol. Digits ())); Print ( "Broker comment: " +trade.ResultComment()); Print ( "Price of position opening: " + DoubleToString (position.PriceOpen(),symbol. Digits ())); Print ( "Price of position's Stop Loss: " + DoubleToString (position.StopLoss(),symbol. Digits ())); Print ( "Price of position's Take Profit: " + DoubleToString (position.TakeProfit(),symbol. Digits ())); Print ( "Current price by position: " + DoubleToString (position.PriceCurrent(),symbol. Digits ())); } //+------------------------------------------------------------------+
안녕하세요, 전문가 여러분, 오류가 무엇인지 알아낼 수 있도록 도와주세요. mt5 데모 계정에 pinconnector를 통해 거래 보기에서 표시기를 연결했습니다. 신호가 전달되지 않습니다. 잡지의 스크린샷을 첨부했습니다.