Atascado al crear un EA

 

Publi

Atascado al crear un EA

 

Publi

Resultados 1 al 1 de 1


  1. #1




    Reputación:
    Poder de reputación: 6

    Espana
    Mensajes: 18
    Créditos: 684

    Atascado al crear un EA


    Publi
    Hola a todos.


    Me he iniciado hace poco en este mundillo y, de momento, estoy aprendiendo en plan autodidacta de todo aquello que me parece útil. Una de las cosas que me parecen más interesantes es la posiblidad de crear un EA para trabajar con él en MT4. Como no tengo conocimientos de programación, estoy utiizando Forex Generator. De momento, hago cosas sencillas, para ir aprendiendo. Cojo un indicador, le doy orden de entrada y salida, y en una cuenta demo compruebo si responde bien a las órdenes... independientemente del balance económico. De momento no me interesa tanto el resultado económico como el aprender a crear un EA.


    El caso es que me he topado con un indicador que no sé por donde cogerlo. Es el 3LevelZZSemafor. Lo que intento es que abra una oeracion de compra cuando salga el 3 amarillo que indica un inicio de tendencia al alza y que la cierre cuando salga el 3 amarillo que indica un inicio de tendencia a la baja. Paralelamente, quiero que abra una operación de venta cuando salga el 3 amarillo que indica un inicio de tendencia a la baja y la cierre cuando salga el 3 amarillo que indica un inicio de tendencia al alza.


    Si no estoy equivocado, los buffers que me interesan son el 4 para abrir la compra y el 5 para abrir la venta. Inversamente, con el buffer 4 quiero cerrar la venta y con el 5 quiero cerrar la compra. He probado con muchos valores... y no lo consigo. La última prueba que he hecho es... buffer 4>1 para abrir compra y buffer 5<1 para abrir venta... pero nada. La compra no se abre y la venta se abre... pero no cuando debería.


    Alguien puede explicarme qué estoy haciendo mal? Estoy atascado y me gustaría averiguar dónde está el errror. Por si sirve de ayuda, pego el código y adjunto el indicador que estoy usando... no sea que el problema esté en ese archivo.
    Muchas gracias de antemano.


    -------------------------------
    //-------------------------------------------------------------
    // GNUSoft Ltda. Forex EA and Script Generator version 6.2 EA
    //-------------------------------------------------------------
    // Keywords: MT4, Forex EA builder, create EA, expert advisor developer


    #property copyright "Copyright © 2014-2017, GNUSoft. Forex EA Generator v6.2"
    #property link "http://www.generador-mql.com"


    #include <stdlib.mqh>
    #include <WinUser32.mqh>


    // exported variables
    extern double BuyLots21 = 0.5;
    extern int BuyStoploss21 = 0;
    extern int BuyTakeprofit21 = 0;
    extern double SellLots25 = 0.5;
    extern int SellStoploss25 = 0;
    extern int SellTakeprofit25 = 0;




    // local variables
    double PipValue=1; // this variable is here to support 5-digit brokers
    bool Terminated = false;
    string LF = "\n"; // use this in custom or utility blocks where you need line feeds
    int NDigits = 4; // used mostly for NormalizeDouble in Flex type blocks
    int ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique names
    int current = 0; // current bar index, used by Cross Up, Cross Down and many other blocks
    int varylots[101]; // used by Buy Order Varying, Sell Order Varying and similar


    datetime BarTime17 = 0;




    int init()
    {
    NDigits = Digits;

    if (true) ObjectsDeleteAll(); // clear the chart


    Comment(""); // clear the chart
    return (0);
    }


    // Expert start
    int start()
    {
    if (Bars < 10)
    {
    Comment("Not enough bars");
    return (0);
    }
    if (Terminated == true)
    {
    Comment("EA Terminated.");
    return (0);
    }

    OnEveryNewBar17();
    return (0);
    }


    void OnEveryNewBar17()
    {
    PipValue = 1;
    if (NDigits == 3 || NDigits == 5) PipValue = 10;
    if (BarTime17 < Time[0])
    {
    // we have a new bar opened
    BarTime17 = Time[0]; // keep the new bar open time
    IfOrderDoesNotExist20();
    IfOrderExists22();
    IfOrderDoesNotExist24();
    IfOrderExists18();

    }
    }


    void IfOrderDoesNotExist20()
    {
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
    {
    exists = true;
    }
    }
    else
    {
    Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }

    if (exists == false)
    {
    TechnicalAnalysis28();

    }
    }


    void TechnicalAnalysis28()
    {
    if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",4,current) > 1)
    {
    BuyOrder21();

    }
    }


    void BuyOrder21()
    {
    double SL = Ask - BuyStoploss21*PipValue*Point;
    if (BuyStoploss21 == 0) SL = 0;
    double TP = Ask + BuyTakeprofit21*PipValue*Point;
    if (BuyTakeprofit21 == 0) TP = 0;
    int ticket = -1;
    if (false)
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots21, Ask, 4, 0, 0, "My Expert", 1, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots21, Ask, 4, SL, TP, "My Expert", 1, 0, Blue);
    if (ticket > -1)
    {
    if (false)
    {
    bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
    bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
    if (ret == false)
    Print("OrderModify() error - ", ErrorDescription(GetLastError()));
    }

    }
    else
    {
    Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    }


    void IfOrderExists22()
    {
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
    {
    exists = true;
    }
    }
    else
    {
    Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }

    if (exists)
    {
    TechnicalAnalysis26();

    }
    }


    void TechnicalAnalysis26()
    {
    if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",5,current) < 1)
    {
    CloseOrder23();

    }
    }


    void CloseOrder23()
    {
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[90][2];
    for (int i = 0; i < orderstotal; i++)
    {
    bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
    {
    continue;
    }
    ordticket[orders][0] = OrderOpenTime();
    ordticket[orders][1] = OrderTicket();
    orders++;
    }
    if (orders > 1)
    {
    ArrayResize(ordticket,orders);
    ArraySort(ordticket);
    }
    for (i = 0; i < orders; i++)
    {
    if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
    {
    bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Blue);
    if (ret == false)
    Print("OrderClose() error - ", ErrorDescription(GetLastError()));
    }
    }

    }


    void IfOrderDoesNotExist24()
    {
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 2)
    {
    exists = true;
    }
    }
    else
    {
    Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }

    if (exists == false)
    {
    TechnicalAnalysis29();

    }
    }


    void TechnicalAnalysis29()
    {
    if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",5,current) < 1)
    {
    SellOrder25();

    }
    }


    void SellOrder25()
    {
    double SL = Bid + SellStoploss25*PipValue*Point;
    if (SellStoploss25 == 0) SL = 0;
    double TP = Bid - SellTakeprofit25*PipValue*Point;
    if (SellTakeprofit25 == 0) TP = 0;
    int ticket = -1;
    if (false)
    ticket = OrderSend(Symbol(), OP_SELL, SellLots25, Bid, 4, 0, 0, "My Expert", 2, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, SellLots25, Bid, 4, SL, TP, "My Expert", 2, 0, Red);
    if (ticket > -1)
    {
    if (false)
    {
    bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
    bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
    if (ret == false)
    Print("OrderModify() error - ", ErrorDescription(GetLastError()));
    }

    }
    else
    {
    Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    }


    void IfOrderExists18()
    {
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 2)
    {
    exists = true;
    }
    }
    else
    {
    Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }

    if (exists)
    {
    TechnicalAnalysis27();

    }
    }


    void TechnicalAnalysis27()
    {
    if (iCustom(NULL, PERIOD_CURRENT, "3_Level_ZZ_Semafor",4,current) > 1)
    {
    CloseOrder19();

    }
    }


    void CloseOrder19()
    {
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[90][2];
    for (int i = 0; i < orderstotal; i++)
    {
    bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 2)
    {
    continue;
    }
    ordticket[orders][0] = OrderOpenTime();
    ordticket[orders][1] = OrderTicket();
    orders++;
    }
    if (orders > 1)
    {
    ArrayResize(ordticket,orders);
    ArraySort(ordticket);
    }
    for (i = 0; i < orders; i++)
    {
    if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
    {
    bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
    if (ret == false)
    Print("OrderClose() error - ", ErrorDescription(GetLastError()));
    }
    }

    }






    int deinit()
    {
    if (true) ObjectsDeleteAll();


    return (0);
    }
    Foro de Forex Trading United
    Archivos adjuntados Archivos adjuntados

  2. Publi
    Publi


This website uses cookies
Utilizamos cookies propias y de terceros para elaborar información estadística y mostrarle publicidad personalizada a través del análisis de su navegación. Si continúa navegando acepta su uso. Más información y política de cookies.
     

 

Publi


Aviso Legal
Ley Orgánica 15/1999, de 13 de diciembre, de Protección de Datos de Carácter Personal