Metatrader 4에서 시간 기반 항목 신호를 생성하는 방법에 대한 예제 코드가 있습니까? 예 : 특정 시간과 분 단위로 매일MT4 MetaTrader4의 시간 기반 항목 신호
답변
난 그냥 그런 기능을 작업했습니다. 커스터마이징이 필요합니다. 좀 더 일반적인 버전을 만들기 위해 노력하고 있습니다. 너무 크고 지루해지기 때문에 자체 파일 include
이 필요합니다. 그러나 코드를 변경하지 않고도 다른 차트에 붙일 수있는 가치가있을 것입니다. 그것은 기본적으로 하나의 커다란 성명서가 될 것입니다.
어떤 작업을하셨습니까? 시간과 외환에 관심을 가져 주셔서 감사합니다!
bool existordertime(datetime time, int otype = -37) {
// +---------------------------------------------------------------+
// | this function is intended for use inside of if() and other conditionals
// | usually called with TimeCurrent() example:
// |
// | if (!existordertime(TimeCurrent()))
// |
// | it accepts a datetime. A datetime is:
// | a number of seconds elapsed from 00:00 January 1, 1970
// | they can be treated as integers as such or accessed with other functions
// | so that if statements can be commented in and out easily based on what
// | timeframe we plan on looking at.
// | there is an optional parameter for an order type if you need it.
// |
// | KEEP IN MIND if you want to use this to trade something like a 5min 15min
// | or 4hr your gonna need a lot of if statements like:
// |
// | if ( MathMod(Minute() + 5, 5) == 0)
// |
// +------------------------------------------------------------------+
for (int cnt = 0; cnt < OrdersTotal(); cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == otype || -37 == otype)
// COMMENT OUT THE if()S YOU DON'T NEED HERE:
// also add new lines as needed
// if ( MathMod(TimeMinute(time) + 5, 5) == 0) // 5min chart
// if ( MathMod(TimeMinute(time) + 15, 15) == 0) // 15min chart
// if ( MathMod(TimeMinute(time) + 30, 30) == 0) // 30min chart
// if ( MathMod(TimeHour( time) + 4, 4) == 0) // 4hour chart
int dbOrderOpenTime = OrderOpenTime(); // re-use SAVEs dbPOOL-access time ...
if ( TimeSeconds(time) == TimeSeconds(dbOrderOpenTime))
if ( TimeMinute( time) == TimeMinute( dbOrderOpenTime))
if ( TimeHour( time) == TimeHour( dbOrderOpenTime))
if ( TimeDay( time) == TimeDay( dbOrderOpenTime))
if ( TimeMonth( time) == TimeMonth( dbOrderOpenTime))
if ( TimeYear( time) == TimeYear( dbOrderOpenTime))
return (TRUE);
}
for (cnt = 0; cnt < OrdersHistoryTotal(); cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);
if (OrderType() == otype || -37 == otype)
// COMMENT OUT THE if()S YOU DON'T NEED HERE:
// also add new lines as needed
// if ( MathMod(TimeMinute(time) + 5, 5) == 0) // 5min chart
// if ( MathMod(TimeMinute(time) + 15, 15) == 0) // 15min chart
// if ( MathMod(TimeMinute(time) + 30, 30) == 0) // 30min chart
// if ( MathMod(TimeHour( time) + 4, 4) == 0) // 4hour chart
int dbOrderOpenTime = OrderOpenTime(); // re-use SAVEs dbPOOL-access time ...
if ( TimeSeconds(time) == TimeSeconds(dbOrderOpenTime))
if ( TimeMinute( time) == TimeMinute( dbOrderOpenTime))
if ( TimeHour( time) == TimeHour( dbOrderOpenTime))
if ( TimeDay( time) == TimeDay( dbOrderOpenTime))
if ( TimeMonth( time) == TimeMonth( dbOrderOpenTime))
if ( TimeYear( time) == TimeYear( dbOrderOpenTime))
return (TRUE);
}
return (FALSE);
}
코드가 코드처럼 보이지 않습니다. 또한, 그것은 인간이 편집 할 수 없습니다. 전체 4 칸으로 들여 쓰기를 도와 주시겠습니까? 그것은 가독성을 높일 것입니다 – eeerahul
@eeerahul 네, 맞아. MQL4 커뮤니티는 MQL 코드 (C-syntax)를 생성하는 것처럼 매우 이상한 습관을 가지고 있습니다.이 습관은 IMO가 아닌 개혁 할 수 있습니다. 마지막으로 이것은 360KB 플로피 디스크 시대에, 큰 LISP 기반 소프트웨어 모듈이 문자 적으로 "필요한"chars만을 유지하기 위해 문자 그대로 제거되었고 코드는 다음과 같이 적합 할 필요가 있기 때문에 해시 코드 -d를 미리 보았다 FDD 미디어의 저장 용량 제한. (아이들은 일부 PC에는 HDD가없고 부팅 + FDD에서 실행 ... 잘 ...) – user3666197
@nbrooks 코드 블록의 여러 가지 재 편집 후, 친절하게 계정을 고려, 처음에는 저자는 손대지 않는 알고리즘에 대한 접근을 남겨 두려는 의도. 포맷팅과 로직을 모두 수정하면 'Time [iShift (...)]'및 다른 주요 항목을 통해 다른 시간대의 작업에 대한 알고리즘을 훨씬 더 잘 정의 할 수 있습니다. 대답 할 질문의 코드 블록은 초기 질문의 방향으로 아무 것도하지 않지만 dbPOOL을 광범위하게 다시 읽습니다 ('.Select()'결과는 상관 없습니다) – user3666197
TimeLocal()
은 로컬 컴퓨터 (터미널 클라이언트)의 1970 년 1 월 1 일 자정 이후 경과 한 시간 (초)을 제공합니다.
TimeCurrent()
은 브로커의 컴퓨터 (서버)의 1970 년 1 월 1 일 자정 이후 경과 된 시간을 초 단위로 나타냅니다.
당신과 같이 문자열로이 중 하나를 변환 할 수 있습니다
이Print("Year:",TimeYear(TimeCurrent())," Month:",TimeMonth(TimeCurrent()));
MQL4 온라인 프로그래머 가이드가 될 수 있습니다 당신은 또한 그래서 같은 날짜 수의 개별 요소를 얻을 수 있습니다
string ct = TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS);
Print("Client Time: ", ct);
string st = TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
Print("Server Time: ", st);
발견 된 here.
희망이 도움이됩니다.
건배,
마크
찾고있는 부분이 있습니까 (예 : 시간대를 알려주는 논리, 거래를 시작하는 논리 등)? 아니면 그걸 모두 찾으십니까? – malonso
방법론을 찾고 있습니다. 추가 기준을 충족하는 경우 특정 시간에 거래를 열려고합니다. – PeanutPower