MetaTrader4 中的 MT4 基于时间的入场信号

发布于 2024-08-18 09:55:01 字数 65 浏览 12 评论 0原文

有谁有关于如何在 Metatrader 4 中生成基于一天中时间的入场信号的示例代码吗?例如,在每天的特定小时和分钟

Does anyone have any example code for how to generate a time of day based entry signal in Metatrader 4? e.g. at a particular hour and minute of each day

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脱离于你 2024-08-25 09:55:01

我一直在研究这样的功能。它必须进行大量定制——我正在努力制作一个更通用的版本,它会变得又大又乏味,需要它自己的 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);
}

I've been working on just such a function. It has to be customized a lot—I'm working on making a more general version that;s going to be so big and tedious it'll need its own include file. But it'll be worth it to be able to stick it on different charts without changing the code. It will basically be one big case statement with what I have here customized already to each individual timeframe.

What have you been working on? Thanks for your interest in time and forex!

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);
}
堇色安年 2024-08-25 09:55:01

TimeLocal() 为您提供本地计算机(终端客户端)自 1970 年 1 月 1 日午夜以来的秒数。

TimeCurrent() 为您提供自 1970 年 1 月 1 日午夜以来您的经纪商计算机(服务器)的秒数。

您可以将其中任何一个转换为字符串,如下所示:

string ct = TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS);
Print("Client Time: ", ct);

string st = TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
Print("Server Time: ", st);

您还可以获取日期数字的各个元素,如下所示:

Print("Year:",TimeYear(TimeCurrent())," Month:",TimeMonth(TimeCurrent()));

MQL4 在线程序员指南可以在 这里

希望这有帮助。

干杯,

马克

TimeLocal() gives you the number of seconds since midnight Jan 1st 1970 of your local computer (Terminal Client).

TimeCurrent() gives you the number of seconds since midnight Jan 1st 1970 of your Broker's computer (Server).

You can convert either of these into a string like so:

string ct = TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS);
Print("Client Time: ", ct);

string st = TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
Print("Server Time: ", st);

You can also get individual elements of the date number like so:

Print("Year:",TimeYear(TimeCurrent())," Month:",TimeMonth(TimeCurrent()));

The MQL4 online programmers guide can be found here.

Hope this helps.

Cheers,

Mark

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文