MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 1271 1...126412651266126712681269127012711272127312741275127612771278...1953 새 코멘트 Dmitri Custurov 2020.10.10 19:33 #12701 터미널을 수동으로 다시 시작할 때 변경 사항이 항상 기본 프로필에 저장되는 것은 아닙니다. 뭐가 될수 있었는지? 어떤 상황에서 설정이 저장되었습니까? 설정 을 디스크로 재설정하려면 Expert Advisors/Indicators가 최소 시간 동안 정지해야 합니까? Windows Server 2012 R2 Standard x64, IE 11, RDP, UAC, 2 x Intel Xeon E3-12xx v2(Ivy Bridge, IBRS), 메모리: 2970/3999Mb, 디스크: 2/19Gb 터미널 MT4. 여러 브로커를 시도했습니다. Any questions from newcomers MetaQuotes VPS service specification MQL5 bug when working graf1976 2020.10.10 21:01 #12702 안녕하세요. 도와주세요. MQL4에서 파일 작업을 처리할 수 없습니다. 코드는 다음과 같습니다. double Lot; string file_name = "Test " + Symbol ()+ ".csv" ; int filehandle; //+------------------------------------------------------------------+ int OnInit () { //----- Создание файла ResetLastError (); if (! FileIsExist (file_name)) { Print ( "Файл <" ,file_name, "> отсутствует. Создание файла." ); filehandle= FileOpen (file_name, FILE_WRITE | FILE_CSV ); if (filehandle!= INVALID_HANDLE ) { FileWrite (filehandle, 0.1 ); //FileWriteDouble(filehandle,0.1,DOUBLE_VALUE); FileClose (filehandle); } else Comment ( "Файл не создан, ошибка " , GetLastError ()); } else Print ( "Файл <" ,file_name, "> существует" ); //----- Чтение файла ResetLastError (); filehandle= FileOpen (file_name, FILE_READ | FILE_BIN ); if (filehandle!= INVALID_HANDLE ) { Print ( "Файл <" ,file_name, "> открыт для чтения" ); Lot= FileReadDouble (filehandle,DOUBLE_VALUE); Print ( "Lot = " ,Lot); FileClose (filehandle); } else Comment ( "Файл не создан, ошибка " , GetLastError ()); return ( INIT_SUCCEEDED ); } //+------------------------------------------------------------------+ void OnDeinit ( const int reason) { FileDelete (file_name); } //+------------------------------------------------------------------+ void OnTick () { //--- } //+------------------------------------------------------------------+ 테스트 EURUSD.csv 파일을 만듭니다. 모든 것이 정상입니다. 파일에 "0.1" 항목이 있습니다. 그러나 그는 읽고 싶지 않습니다. 로그에 "Lot = 0.0"이 표시됩니다. 컴파일할 때 오류가 발생하지 않습니다. 나는 이미 "내 두뇌를 망가뜨렸다" - 나는 실수가 어디에 있는지 이해하지 못한다. 도움을 주신 모든 분들께 미리 감사드립니다. Sysmart 2020.10.10 21:30 #12703 Vladimir Pastushak : 모든 코드를 제공하십시오 거의 전체. 그러나 나는 또한 별도로 계산했습니다. double iK2 = (numPosOr - numStepCount) / numPosOr - 결과 = 0 Alekseu Fedotov 2020.10.11 05:18 #12704 graf1976 : 안녕하세요. 도와주세요. MQL4에서 파일 작업을 처리할 수 없습니다. 코드는 다음과 같습니다. 테스트 EURUSD.csv 파일을 만듭니다. 모든 것이 정상입니다. 파일에 "0.1" 항목이 있습니다. 그러나 그는 읽고 싶지 않습니다. 로그에 "Lot = 0.0"이 표시됩니다. 컴파일할 때 오류가 발생하지 않습니다. 나는 이미 "내 두뇌를 망가뜨렸다" - 나는 실수가 어디에 있는지 이해하지 못한다. 도움을 주신 모든 분들께 미리 감사드립니다. 오류가 여기에 있다고 생각합니다. filehandle= FileOpen (file_name, FILE_READ | FILE_BIN ); // надо FILE_CSV graf1976 2020.10.11 07:40 #12705 Alekseu Fedotov : 오류가 여기에 있다고 생각합니다. 감사합니다. 하지만 도움이 되지 않았습니다. 로그에서 모두 0의 결과를 가져왔습니다. Alekseu Fedotov 2020.10.11 08:21 #12706 graf1976 : 감사합니다. 하지만 도움이 되지 않았습니다. 로그에서 모두 0의 결과를 가져왔습니다. graf1976 : 감사합니다. 하지만 도움이 되지 않았습니다. 로그에서 모두 0의 결과를 가져왔습니다. 더 기능을 교체 FileReadDouble (filehandle,DOUBLE_VALUE); 에 FileReadNumber (filehandle); graf1976 2020.10.11 08:34 #12707 Alekseu Fedotov : 더 기능을 교체 에 알렉스, 정말 감사합니다. 기능 교체 후 - 적립. [삭제] 2020.10.11 11:40 #12708 그런 전문가를 위한 준비가 맞는지, 아니면 다른 방식으로 논리를 정리하는 것이 좋은지 전문가들에게 묻고 싶다. //+------------------------------------------------------------------+ //| 01 Sample.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #define MACD_MAGIC 1234503 //--- #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\PositionInfo.mqh> #include <Trade\AccountInfo.mqh> //--- CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object CPositionInfo m_position; // trade position object CAccountInfo m_account; // account info wrapper //--- input double MaximumRisk = 0.02 ; // Maximum Risk in percentage input double DecreaseFactor = 3 ; // Descrease factor input int InpMACDOpenLevel = 3 ; // MACD open level (in pips) input int InpMACDCloseLevel= 2 ; // MACD close level (in pips) input int InpMATrendPeriod = 26 ; // MA trend period //--- double m_macd_open_level = 0.0 ; // double m_macd_close_level = 0.0 ; // datetime ExtPrevBars = 0 ; // "0" -> D'1970.01.01 00:00'; datetime ExtPrevBars_0 = 0 ; // "0" -> D'1970.01.01 00:00'; int m_handle_macd; // MACD indicator handle int m_handle_ema; // Moving Average indicator handle double m_adjusted_point; // point value adjusted for 3 or 5 points //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double TradeSizeOptimized( void ) { double price= 0.0 ; double margin= 0.0 ; //--- select lot size if (! SymbolInfoDouble ( _Symbol , SYMBOL_ASK ,price)) return ( 0.0 ); if (! OrderCalcMargin ( ORDER_TYPE_BUY , _Symbol , 1.0 ,price,margin)) return ( 0.0 ); if (margin<= 0.0 ) return ( 0.0 ); double lot= NormalizeDouble ( AccountInfoDouble ( ACCOUNT_MARGIN_FREE )*MaximumRisk/margin, 2 ); //--- calculate number of losses orders without a break if (DecreaseFactor> 0 ) { //--- select history for access HistorySelect ( 0 , TimeCurrent ()); //--- int orders= HistoryDealsTotal (); // total history deals int losses= 0 ; // number of losses orders without a break for ( int i=orders- 1 ; i>= 0 ; i--) { ulong ticket= HistoryDealGetTicket (i); if (ticket== 0 ) { Print ( "HistoryDealGetTicket failed, no trade history" ); break ; } //--- check symbol if ( HistoryDealGetString (ticket, DEAL_SYMBOL )!= _Symbol ) continue ; //--- check Expert Magic number if ( HistoryDealGetInteger (ticket, DEAL_MAGIC )!=MACD_MAGIC) continue ; //--- check profit double profit= HistoryDealGetDouble (ticket, DEAL_PROFIT ); if (profit> 0.0 ) break ; if (profit< 0.0 ) losses++; } //--- if (losses> 1 ) lot= NormalizeDouble (lot-lot*losses/DecreaseFactor, 1 ); } //--- normalize and check limits double stepvol= SymbolInfoDouble ( _Symbol , SYMBOL_VOLUME_STEP ); lot=stepvol* NormalizeDouble (lot/stepvol, 0 ); double minvol= SymbolInfoDouble ( _Symbol , SYMBOL_VOLUME_MIN ); if (lot<minvol) lot=minvol; double maxvol= SymbolInfoDouble ( _Symbol , SYMBOL_VOLUME_MAX ); if (lot>maxvol) lot=maxvol; //--- return trading volume return (lot); } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit () { //--- initialize common information m_symbol.Name( Symbol ()); // symbol RefreshRates(); 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_macd_open_level =InpMACDOpenLevel*m_adjusted_point; m_macd_close_level=InpMACDCloseLevel*m_adjusted_point; //--- set default deviation for trading in adjusted points m_trade.SetDeviationInPoints( 3 *digits_adjust); //--- //--- create MACD indicator m_handle_macd= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ); //--- if the handle is not created if (m_handle_macd== INVALID_HANDLE ) { //--- tell about the failure and output the error code PrintFormat ( "Failed to create handle of the handle_iCustom indicator for the symbol %s/%s, error code %d" , Symbol (), EnumToString ( Period ()), GetLastError ()); //--- the indicator is stopped early return ( INIT_FAILED ); } //--- Moving Average indicator m_handle_ema= iMA ( NULL , 0 ,InpMATrendPeriod, 0 , MODE_EMA , PRICE_CLOSE ); //--- if the handle is not created if (m_handle_ema== INVALID_HANDLE ) { //--- tell about the failure and output the error code PrintFormat ( "Failed to create handle of the handle_iCustom indicator for the symbol %s/%s, error code %d" , Symbol (), EnumToString ( Period ()), GetLastError ()); //--- the indicator is stopped early return ( INIT_FAILED ); } //--- return ( INIT_SUCCEEDED ); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit ( const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick () { //--- refresh rates RefreshRates(); CheckForOpen(); CheckForClose(); } //+------------------------------------------------------------------+ //| Check for long position closing | //+------------------------------------------------------------------+ bool LongClosed( void ) { bool res= false ; //--- should it be closed? 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 ()== Symbol ()) { if (m_position.PositionType()== POSITION_TYPE_BUY ) { ClosePosition(m_position. Symbol ()); // close a position by the specified symbo printf ( "Long position by %s to be closed : '%s'" , Symbol (),m_trade.ResultComment()); //--- 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? 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 ()== Symbol ()) { if (m_position.PositionType()== POSITION_TYPE_SELL ) { ClosePosition(m_position. Symbol ()); // close a position by the specified symbo printf ( "Short position by %s to be closed : '%s'" , Symbol (),m_trade.ResultComment()); //--- 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(); //--- open position if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_BUY ,TradeSizeOptimized(),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,TP=%f" ,price, 0.0 ); } //--- 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(); //--- open position if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_SELL ,TradeSizeOptimized(),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,TP=%f" ,price, 0.0 ); } //--- in any case we must exit from expert res= true ; //--- result return (res); } //+------------------------------------------------------------------+ //| Check for open position conditions | //+------------------------------------------------------------------+ bool CheckForOpen( void ) { bool res= false ; //--- we work only at the time of the birth of new bar datetime time_0= iTime ( Symbol (), Period (), 0 ); if (time_0==ExtPrevBars) return ( false ); ExtPrevBars=time_0; if (!RefreshRates()) { ExtPrevBars= 0 ; return ( false ); } //--- double main[],signal[],ma[]; ArraySetAsSeries (main, true ); ArraySetAsSeries (signal, true ); ArraySetAsSeries (ma, true ); int start_pos= 0 ,count= 3 ; if (!iGetArray(m_handle_macd, MAIN_LINE ,start_pos,count,main) || !iGetArray(m_handle_macd, SIGNAL_LINE ,start_pos,count,signal) || !iGetArray(m_handle_ema, 0 ,start_pos,count,ma)) { ExtPrevBars= 0 ; return ( false ); } //--- check for long position (BUY) possibility if (main[ 0 ]< 0 ) if (main[ 0 ]>signal[ 0 ] && main[ 1 ]<signal[ 1 ]) if ( MathAbs (main[ 0 ])>(m_macd_open_level) && ma[ 0 ]>ma[ 1 ]) { LongOpened(); res= true ; } //--- check for short position (SELL) possibility if (main[ 0 ]> 0 ) if (main[ 0 ]<signal[ 0 ] && main[ 1 ]>signal[ 1 ]) if (main[ 0 ]>(m_macd_open_level) && ma[ 0 ]<ma[ 1 ]) { ShortOpened(); res= true ; } //--- return ( true ); } //+------------------------------------------------------------------+ //| Check for close position conditions | //+------------------------------------------------------------------+ bool CheckForClose( void ) { bool res= false ; //--- we work only at the time of the birth of new bar datetime time_0= iTime ( Symbol (), Period (), 0 ); if (time_0==ExtPrevBars_0) return ( false ); ExtPrevBars_0=time_0; if (!RefreshRates()) { ExtPrevBars_0= 0 ; return ( false ); } //--- double main[],signal[],ma[]; ArraySetAsSeries (main, true ); ArraySetAsSeries (signal, true ); ArraySetAsSeries (ma, true ); int start_pos= 0 ,count= 3 ; if (!iGetArray(m_handle_macd, MAIN_LINE ,start_pos,count,main) || !iGetArray(m_handle_macd, SIGNAL_LINE ,start_pos,count,signal) || !iGetArray(m_handle_ema, 0 ,start_pos,count,ma)) { ExtPrevBars_0= 0 ; return ( false ); } //--- should it be closed? if (main[ 0 ]< 0 ) if (main[ 0 ]>signal[ 0 ] && main[ 1 ]<signal[ 1 ]) if ( MathAbs (main[ 0 ])>m_macd_close_level) { ShortClosed(); res= true ; } //--- should it be closed? if (main[ 0 ]> 0 ) if (main[ 0 ]<signal[ 0 ] && main[ 1 ]>signal[ 1 ]) if (main[ 0 ]>m_macd_close_level) { LongClosed(); res= true ; } //--- return ( true ); } //+------------------------------------------------------------------+ //| Get value of buffers | //+------------------------------------------------------------------+ double iGetArray( const int handle, const int buffer, const int start_pos, const int count, double &arr_buffer[]) { bool result= true ; if (! ArrayIsDynamic (arr_buffer)) { Print ( "This a no dynamic array!" ); 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) { //--- if the copying fails, tell the error code PrintFormat ( "Failed to copy data from the indicator, error code %d" , GetLastError ()); //--- quit with zero result - it means that the indicator is considered as not calculated return ( false ); } return (result); } //+------------------------------------------------------------------+ //| Refreshes the symbol quotes data | //+------------------------------------------------------------------+ bool RefreshRates() { //--- refresh rates if (!m_symbol.RefreshRates()) { Print ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "RefreshRates error" ); return ( false ); } //--- protection against the return value of "zero" if (m_symbol.Ask()== 0 || m_symbol.Bid()== 0 ) { Print ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "Ask == 0.0 OR Bid == 0.0" ); return ( false ); } //--- return ( true ); } //+------------------------------------------------------------------+ //| Close selected position | //+------------------------------------------------------------------+ void ClosePosition( const string symbol) { if (InitTrade(symbol)) m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbo PlaySound ( "ok.wav" ); } //+------------------------------------------------------------------+ //| Init trade object | //+------------------------------------------------------------------+ bool InitTrade( const string symbol) { if (!m_symbol.Name(symbol)) // sets symbol name return ( false ); //--- if (IsFillingTypeAllowed(symbol, SYMBOL_FILLING_FOK )) m_trade.SetTypeFilling( ORDER_FILLING_FOK ); else if (IsFillingTypeAllowed(symbol, SYMBOL_FILLING_IOC )) m_trade.SetTypeFilling( ORDER_FILLING_IOC ); else m_trade.SetTypeFilling( ORDER_FILLING_RETURN ); //--- return ( true ); //--- } //+------------------------------------------------------------------+ //| Checks if the specified filling mode is allowed | //+------------------------------------------------------------------+ bool IsFillingTypeAllowed( string symbol, int fill_type) { //--- Obtain the value of the property that describes allowed filling modes int filling=( int ) SymbolInfoInteger (symbol, SYMBOL_FILLING_MODE ); //--- Return true, if mode fill_type is allowed return ((filling & fill_type)==fill_type); } //+------------------------------------------------------------------+ Sysmart 2020.10.11 12:17 #12709 Sysmart : numPosOr = 4; numStepCount = 1; iK = (numPosOr - numStepCount) / numPosOr; 이 계산에서 iK = 0이 되는 이유는 무엇입니까? 조언해줄 사람이 없나요? [삭제] 2020.10.11 12:57 #12710 Sysmart : 조언해줄 사람이 없나요? 그리고 당신의 캐치는 무엇입니까? 당신은 당신의 기능에서 무엇을 원하는가? 간단히 말해서 - 아마도 나는 이해할 것입니다. 그러면 우리는 함께 해결책을 찾을 것입니다. 1...126412651266126712681269127012711272127312741275127612771278...1953 새 코멘트 트레이딩 기회를 놓치고 있어요: 무료 트레이딩 앱 복사용 8,000 이상의 시그널 금융 시장 개척을 위한 경제 뉴스 등록 로그인 공백없는 라틴 문자 비밀번호가 이 이메일로 전송될 것입니다 오류 발생됨 Google으로 로그인 웹사이트 정책 및 이용약관에 동의합니다. 계정이 없으시면, 가입하십시오 MQL5.com 웹사이트에 로그인을 하기 위해 쿠키를 허용하십시오. 브라우저에서 필요한 설정을 활성화하시지 않으면, 로그인할 수 없습니다. 사용자명/비밀번호를 잊으셨습니까? Google으로 로그인
터미널을 수동으로 다시 시작할 때 변경 사항이 항상 기본 프로필에 저장되는 것은 아닙니다. 뭐가 될수 있었는지? 어떤 상황에서
설정이 저장되었습니까? 설정 을 디스크로 재설정하려면 Expert Advisors/Indicators가 최소 시간 동안 정지해야 합니까?
Windows Server 2012 R2 Standard x64, IE 11, RDP, UAC, 2 x Intel Xeon E3-12xx v2(Ivy Bridge, IBRS), 메모리: 2970/3999Mb, 디스크: 2/19Gb
터미널 MT4. 여러 브로커를 시도했습니다.
안녕하세요.
도와주세요. MQL4에서 파일 작업을 처리할 수 없습니다. 코드는 다음과 같습니다.
테스트 EURUSD.csv 파일을 만듭니다. 모든 것이 정상입니다. 파일에 "0.1" 항목이 있습니다.
그러나 그는 읽고 싶지 않습니다. 로그에 "Lot = 0.0"이 표시됩니다.
컴파일할 때 오류가 발생하지 않습니다.
나는 이미 "내 두뇌를 망가뜨렸다" - 나는 실수가 어디에 있는지 이해하지 못한다.
도움을 주신 모든 분들께 미리 감사드립니다.
모든 코드를 제공하십시오
거의 전체. 그러나 나는 또한 별도로 계산했습니다. double iK2 = (numPosOr - numStepCount) / numPosOr - 결과 = 0
안녕하세요.
도와주세요. MQL4에서 파일 작업을 처리할 수 없습니다. 코드는 다음과 같습니다.
테스트 EURUSD.csv 파일을 만듭니다. 모든 것이 정상입니다. 파일에 "0.1" 항목이 있습니다.
그러나 그는 읽고 싶지 않습니다. 로그에 "Lot = 0.0"이 표시됩니다.
컴파일할 때 오류가 발생하지 않습니다.
나는 이미 "내 두뇌를 망가뜨렸다" - 나는 실수가 어디에 있는지 이해하지 못한다.
도움을 주신 모든 분들께 미리 감사드립니다.
오류가 여기에 있다고 생각합니다.
오류가 여기에 있다고 생각합니다.
감사합니다. 하지만 도움이 되지 않았습니다. 로그에서 모두 0의 결과를 가져왔습니다.
감사합니다. 하지만 도움이 되지 않았습니다. 로그에서 모두 0의 결과를 가져왔습니다.
더
기능을 교체
FileReadDouble (filehandle,DOUBLE_VALUE);
에
FileReadNumber (filehandle);
더
기능을 교체
에
알렉스, 정말 감사합니다.
기능 교체 후 - 적립.
그런 전문가를 위한 준비가 맞는지, 아니면 다른 방식으로 논리를 정리하는 것이 좋은지 전문가들에게 묻고 싶다.
numPosOr = 4;
numStepCount = 1;
iK = (numPosOr - numStepCount) / numPosOr;
이 계산에서 iK = 0이 되는 이유는 무엇입니까?
조언해줄 사람이 없나요?
조언해줄 사람이 없나요?
그리고 당신의 캐치는 무엇입니까? 당신은 당신의 기능에서 무엇을 원하는가?
간단히 말해서 - 아마도 나는 이해할 것입니다. 그러면 우리는 함께 해결책을 찾을 것입니다.