Pregunta

¿alguien tiene cualquier código de ejemplo para la forma de generar un momento de señal de entrada basada en Metatrader 4 días? p.ej. a una hora particular y minutos de cada día

¿Fue útil?

Solución

He estado trabajando en la función simplemente como una. Tiene que personalizar mucho-estoy trabajando en hacer una versión más general de que; va a ser tan grande y tedioso que necesitará su propio archivo include. Pero valdrá la pena para poder pegarla en diferentes gráficos sin cambiar el código. Básicamente será una declaración de gran caso con lo que he aquí ya medida para cada período de tiempo individual.

¿Qué has estado trabajando? Gracias por su interés en el tiempo y la divisa!

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);
}

Otros consejos

TimeLocal() le da el número de segundos transcurridos desde la medianoche 1 ª Ene 1970 su equipo local (el cliente de terminal).

TimeCurrent() le da el número de segundos transcurridos desde la medianoche 1 ª Ene 1970 el ordenador de su Broker (Servidor).

Se puede convertir cualquiera de éstos en una cadena de este modo:

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

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

También puede obtener los elementos individuales del número de fecha, así:

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

La guía MQL4 programadores en línea se puede encontrar aquí .

Espero que esto ayude.

Saludos,

Marcar

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top