Mała pomoc z kodem EA
Pokaż wyniki od 1 do 4 z 4

Wątek: Mała pomoc z kodem EA

  1. #1
    Poniżej znajduje się EA, którego używam jako szablonu do zbudowania EA dla systemu, którego używam. Nie jestem doświadczonym programistą i mam nadzieję, że ten projekt pozwoli mi zdobyć wiedzę na temat mql4. Poniższy kod działa dobrze, jednak utknąłem na jednej małej części. Ten EA będzie obecnie miał tylko jedną transakcję otwartą na raz. Chciałbym, aby możliwe było równoczesne zawieranie transakcji. Czy ktoś mógłby rzucić okiem na kod i dać mi znać, która część to ogranicza. Uważam, że może to być sekcja pozycji czeku. Wielkie dzięki.


    Cytat Zamieszczone przez ;
    #define SIGNAL_NONE 0
    #define SIGNAL_BUY 1
    #define SIGNAL_SELL 2
    #define SIGNAL_CLOSEBUY 3
    #define SIGNAL_CLOSESELL 4
    extern int MagicNumber = 0;
    extern bool SignalMail = Fałsz;
    extern bool EveryTickMode = Fałsz;
    extern double Lots = 1.0;
    extern int Slippage = 3;
    extern bool UseStopLoss = Fałsz;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = Fałsz;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = Fałsz;
    extern int TrailingStop = 30;
    int BarCount;
    int Current;
    bool TickCheck = Fałsz;
    // ----------------------------------------------- -------------------
    //| funkcja inicjalizacji eksperta |
    // ----------------------------------------------- -------------------
    int init () {
    BarCount = Bars;
    jeśli (EveryTickMode) Current = 0; else Current = 1;
    return (0);
    }
    // ----------------------------------------------- -------------------
    //| funkcja dezinicjalizacji eksperta |
    // ----------------------------------------------- -------------------
    int deinit () {
    return (0);
    }
    // ----------------------------------------------- -------------------
    //| funkcja startu eksperta |
    // ----------------------------------------------- -------------------
    int start () {
    int Order = SIGNAL_NONE;
    int Suma, bilet;
    double StopLossLevel, TakeProfitLevel;

    if (EveryTickMode Bars! = BarCount) TickCheck = Fałsz;
    Łącznie = OrdersTotal ();
    Order = SIGNAL_NONE;
    // ----------------------------------------------- -------------------
    //| Zmienna Rozpocznij |
    // ----------------------------------------------- -------------------

    double Buy1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double Buy1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);
    double Sell1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double Sell1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);
    double CloseBuy1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double CloseBuy1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);
    double CloseSell1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double CloseSell1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);

    // ----------------------------------------------- -------------------
    //| Zmienny koniec |
    // ----------------------------------------------- -------------------
    //Sprawdź pozycję
    bool IsTrade = Fałsz;
    for (int i = 0; i lt; Total; i ) {
    OrderSelect (i, SELECT_BY_POS, MODE_TRADES);
    if (OrderType () lt; = OP_SELL OrderSymbol () == Symbol ()) {
    IsTrade = True;
    if (OrderType () == OP_BUY) {
    //Blisko
    // ----------------------------------------------- -------------------
    //| Rozpoczęcie sygnału (wyjście z zakupu)
    // ----------------------------------------------- -------------------
    if (CloseBuy1_1 lt; CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

    // ----------------------------------------------- -------------------
    //| Koniec sygnału (wyjście z zakupu)
    // ----------------------------------------------- -------------------
    if (Order == SIGNAL_CLOSEBUY ((EveryTickMode! TickCheck) || (! EveryTickMode (Bars! = BarCount)))) {
    OrderClose (OrderTicket (), OrderLots (), Bid, Slippage, MediumSeaGreen);
    jeśli (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Bid, Cyfry) Zamknij Kup);
    if (! EachTickMode) BarCount = Bary;
    IsTrade = Fałsz;
    dalej;
    }
    //Trailing stop
    if (UseTrailingStop TrailingStop gt; 0) {
    if (Bid - OrderOpenPrice () gt; Point * TrailingStop) {
    if (OrderStopLoss () lt; Bid - Point * TrailingStop) {
    OrderModify (OrderTicket (), OrderOpenPrice (), Bid - Point * TrailingStop, OrderTakeProfit (), 0, MediumSeaGreen);
    if (! EachTickMode) BarCount = Bary;
    dalej;
    }
    }
    }
    } else {
    //Blisko
    // ----------------------------------------------- -------------------
    //| Signal Begin (Wyjdź Sprzedaj) |
    // ----------------------------------------------- -------------------
    if (CloseSell1_1 gt; CloseSell1_2) Order = SIGNAL_CLOSESELL;

    // ----------------------------------------------- -------------------
    //| Koniec sygnału (wyjście z trybu sprzedaży) |
    // ----------------------------------------------- -------------------
    if (Order == SIGNAL_CLOSESELL ((EveryTickMode! TickCheck) || (! EachTickMode (Bars! = BarCount)))) {
    OrderClose (OrderTicket (), OrderLots (), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Pytaj, Cyfry) Zamknij Sprzedaj);
    if (! EachTickMode) BarCount = Bary;
    IsTrade = Fałsz;
    dalej;
    }
    //Trailing stop
    if (UseTrailingStop TrailingStop gt; 0) {
    if ((OrderOpenPrice () - Ask) gt; (Point * TrailingStop)) {
    if ((OrderStopLoss () gt; (Ask Point * TrailingStop)) || (OrderStopLoss () == 0)) {
    OrderModify (OrderTicket (), OrderOpenPrice (), Ask Point * TrailingStop, OrderTakeProfit (), 0, DarkOrange);
    if (! EachTickMode) BarCount = Bary;
    dalej;
    }
    }
    }
    }
    }
    }
    // ----------------------------------------------- -------------------
    //| Rozpoczęcie sygnału (wpis)
    // ----------------------------------------------- -------------------
    if (Buy1_1 gt; Buy1_2) Order = SIGNAL_BUY;
    if (Sell1_1 lt; Sell1_2) Order = SIGNAL_SELL;

    // ----------------------------------------------- -------------------
    //| Koniec sygnału |
    // ----------------------------------------------- -------------------
    //Kupować
    if (Order == SIGNAL_BUY ((EveryTickMode! TickCheck) || (! EveryTickMode (Bars! = BarCount)))) {
    if (! IsTrade) {
    //Sprawdź wolny margines
    if (AccountFreeMargin () lt; (1000 * Lots)) {
    Drukuj (Nie mamy pieniędzy, Free Margin =, AccountFreeMargin ());
    return (0);
    }
    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0,0;
    if (UseTakeProfit) TakeProfitLevel = Ask TakeProfit * Point; else TakeProfitLevel = 0,0;
    Ticket = OrderSend (Symbol (), OP_BUY, Partie, Ask, Slippage, StopLossLevel, TakeProfitLevel, Buy (# MagicNumber ), MagicNumber, 0, DodgerBlue);
    if (Ticket gt; 0) {
    if (OrderSelect (bilet, SELECT_BY_TICKET, MODE_TRADES)) {
    Drukuj (zamówienie BUY zostało otwarte:, OrderOpenPrice ());
    if (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Pytaj, Cyfry) Otwórz Kup);
    } else {
    Drukuj (Błąd podczas otwierania zamówienia KUP:, GetLastError ());
    }
    }
    if (EveryTickMode) TickCheck = True;
    if (! EachTickMode) BarCount = Bary;
    return (0);
    }
    }
    //Sprzedać
    if (Order == SIGNAL_SELL ((EveryTickMode! TickCheck) || (! EachTickMode (Bars! = BarCount)))) {
    if (! IsTrade) {
    //Sprawdź wolny margines
    if (AccountFreeMargin () lt; (1000 * Lots)) {
    Drukuj (Nie mamy pieniędzy, Free Margin =, AccountFreeMargin ());
    return (0);
    }
    if (UseStopLoss) StopLossLevel = Bid ​​ StopLoss * Point; else StopLossLevel = 0,0;
    if (UseTakeProfit) TakeProfitLevel = Bid ​​- TakeProfit * Point; else TakeProfitLevel = 0,0;
    Ticket = OrderSend (Symbol (), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, Sell (# MagicNumber ), MagicNumber, 0, DeepPink);
    if (Ticket gt; 0) {
    if (OrderSelect (bilet, SELECT_BY_TICKET, MODE_TRADES)) {
    Drukuj (polecenie SELL otwarte:, OrderOpenPrice ());
    jeśli (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Bid, Cyfry) Otwórz Sprzedaj);
    } else {
    Drukuj (Błąd podczas otwierania polecenia SELL:, GetLastError ());
    }
    }
    if (EveryTickMode) TickCheck = True;
    if (! EachTickMode) BarCount = Bary;
    return (0);
    }
    }
    if (! EachTickMode) BarCount = Bary;
    return (0);
    }
    // ----------------------------------------------- -------------------
    Cytat Zamieszczone przez ;
    #define SIGNAL_NONE 0
    #define SIGNAL_BUY 1
    #define SIGNAL_SELL 2
    #define SIGNAL_CLOSEBUY 3
    #define SIGNAL_CLOSESELL 4
    extern int MagicNumber = 0;
    extern bool SignalMail = Fałsz;
    extern bool EveryTickMode = Fałsz;
    extern double Lots = 1.0;
    extern int Slippage = 3;
    extern bool UseStopLoss = Fałsz;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = Fałsz;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = Fałsz;
    extern int TrailingStop = 30;
    int BarCount;
    int Current;
    bool TickCheck = Fałsz;
    // ----------------------------------------------- -------------------
    //| funkcja inicjalizacji eksperta |
    // ----------------------------------------------- -------------------
    int init () {
    BarCount = Bars;
    jeśli (EveryTickMode) Current = 0; else Current = 1;
    return (0);
    }
    // ----------------------------------------------- -------------------
    //| funkcja dezinicjalizacji eksperta |
    // ----------------------------------------------- -------------------
    int deinit () {
    return (0);
    }
    // ----------------------------------------------- -------------------
    //| funkcja startu eksperta |
    // ----------------------------------------------- -------------------
    int start () {
    int Order = SIGNAL_NONE;
    int Suma, bilet;
    double StopLossLevel, TakeProfitLevel;

    if (EveryTickMode Bars! = BarCount) TickCheck = Fałsz;
    Łącznie = OrdersTotal ();
    Order = SIGNAL_NONE;
    // ----------------------------------------------- -------------------
    //| Zmienna Rozpocznij |
    // ----------------------------------------------- -------------------

    double Buy1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double Buy1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);
    double Sell1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double Sell1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);
    double CloseBuy1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double CloseBuy1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);
    double CloseSell1_1 = iOpen (NULL, PERIOD_H4, Current 0);
    double CloseSell1_2 = iCustom (NULL, PERIOD_H4, AndrewFX HiLo, 0, prąd 0);

    // ----------------------------------------------- -------------------
    //| Zmienny koniec |
    // ----------------------------------------------- -------------------
    //Sprawdź pozycję
    bool IsTrade = Fałsz;
    for (int i = 0; i lt; Total; i ) {
    OrderSelect (i, SELECT_BY_POS, MODE_TRADES);
    if (OrderType () lt; = OP_SELL OrderSymbol () == Symbol ()) {
    IsTrade = True;
    if (OrderType () == OP_BUY) {
    //Blisko
    // ----------------------------------------------- -------------------
    //| Rozpoczęcie sygnału (wyjście z zakupu)
    // ----------------------------------------------- -------------------
    if (CloseBuy1_1 lt; CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

    // ----------------------------------------------- -------------------
    //| Koniec sygnału (wyjście z zakupu)
    // ----------------------------------------------- -------------------
    if (Order == SIGNAL_CLOSEBUY ((EveryTickMode! TickCheck) || (! EveryTickMode (Bars! = BarCount)))) {
    OrderClose (OrderTicket (), OrderLots (), Bid, Slippage, MediumSeaGreen);
    jeśli (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Bid, Cyfry) Zamknij Kup);
    if (! EachTickMode) BarCount = Bary;
    IsTrade = Fałsz;
    dalej;
    }
    //Trailing stop
    if (UseTrailingStop TrailingStop gt; 0) {
    if (Bid - OrderOpenPrice () gt; Point * TrailingStop) {
    if (OrderStopLoss () lt; Bid - Point * TrailingStop) {
    OrderModify (OrderTicket (), OrderOpenPrice (), Bid - Point * TrailingStop, OrderTakeProfit (), 0, MediumSeaGreen);
    if (! EachTickMode) BarCount = Bary;
    dalej;
    }
    }
    }
    } else {
    //Blisko
    // ----------------------------------------------- -------------------
    //| Signal Begin (Wyjdź Sprzedaj) |
    // ----------------------------------------------- -------------------
    if (CloseSell1_1 gt; CloseSell1_2) Order = SIGNAL_CLOSESELL;

    // ----------------------------------------------- -------------------
    //| Koniec sygnału (wyjście z trybu sprzedaży) |
    // ----------------------------------------------- -------------------
    if (Order == SIGNAL_CLOSESELL ((EveryTickMode! TickCheck) || (! EachTickMode (Bars! = BarCount)))) {
    OrderClose (OrderTicket (), OrderLots (), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Pytaj, Cyfry) Zamknij Sprzedaj);
    if (! EachTickMode) BarCount = Bary;
    IsTrade = Fałsz;
    dalej;
    }
    //Trailing stop
    if (UseTrailingStop TrailingStop gt; 0) {
    if ((OrderOpenPrice () - Ask) gt; (Point * TrailingStop)) {
    if ((OrderStopLoss () gt; (Ask Point * TrailingStop)) || (OrderStopLoss () == 0)) {
    OrderModify (OrderTicket (), OrderOpenPrice (), Ask Point * TrailingStop, OrderTakeProfit (), 0, DarkOrange);
    if (! EachTickMode) BarCount = Bary;
    dalej;
    }
    }
    }
    }
    }
    }
    // ----------------------------------------------- -------------------
    //| Rozpoczęcie sygnału (wpis)
    // ----------------------------------------------- -------------------
    if (Buy1_1 gt; Buy1_2) Order = SIGNAL_BUY;
    if (Sell1_1 lt; Sell1_2) Order = SIGNAL_SELL;

    // ----------------------------------------------- -------------------
    //| Koniec sygnału |
    // ----------------------------------------------- -------------------
    //Kupować
    if (Order == SIGNAL_BUY ((EveryTickMode! TickCheck) || (! EveryTickMode (Bars! = BarCount)))) {
    if (! IsTrade) {
    //Sprawdź wolny margines
    if (AccountFreeMargin () lt; (1000 * Lots)) {
    Drukuj (Nie mamy pieniędzy, Free Margin =, AccountFreeMargin ());
    return (0);
    }
    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0,0;
    if (UseTakeProfit) TakeProfitLevel = Ask TakeProfit * Point; else TakeProfitLevel = 0,0;
    Ticket = OrderSend (Symbol (), OP_BUY, Partie, Ask, Slippage, StopLossLevel, TakeProfitLevel, Buy (# MagicNumber ), MagicNumber, 0, DodgerBlue);
    if (Ticket gt; 0) {
    if (OrderSelect (bilet, SELECT_BY_TICKET, MODE_TRADES)) {
    Drukuj (zamówienie BUY zostało otwarte:, OrderOpenPrice ());
    if (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Pytaj, Cyfry) Otwórz Kup);
    } else {
    Drukuj (Błąd podczas otwierania zamówienia KUP:, GetLastError ());
    }
    }
    if (EveryTickMode) TickCheck = True;
    if (! EachTickMode) BarCount = Bary;
    return (0);
    }
    }
    //Sprzedać
    if (Order == SIGNAL_SELL ((EveryTickMode! TickCheck) || (! EachTickMode (Bars! = BarCount)))) {
    if (! IsTrade) {
    //Sprawdź wolny margines
    if (AccountFreeMargin () lt; (1000 * Lots)) {
    Drukuj (Nie mamy pieniędzy, Free Margin =, AccountFreeMargin ());
    return (0);
    }
    if (UseStopLoss) StopLossLevel = Bid ​​ StopLoss * Point; else StopLossLevel = 0,0;
    if (UseTakeProfit) TakeProfitLevel = Bid ​​- TakeProfit * Point; else TakeProfitLevel = 0,0;
    Ticket = OrderSend (Symbol (), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, Sell (# MagicNumber ), MagicNumber, 0, DeepPink);
    if (Ticket gt; 0) {
    if (OrderSelect (bilet, SELECT_BY_TICKET, MODE_TRADES)) {
    Drukuj (polecenie SELL otwarte:, OrderOpenPrice ());
    jeśli (SignalMail) SendMail ([Alert Sygnału], [ Symbol () ] DoubleToStr (Bid, Cyfry) Otwórz Sprzedaj);
    } else {
    Drukuj (Błąd podczas otwierania polecenia SELL:, GetLastError ());
    }
    }
    if (EveryTickMode) TickCheck = True;
    if (! EachTickMode) BarCount = Bary;
    return (0);
    }
    }
    if (! EachTickMode) BarCount = Bary;
    return (0);
    }
    // ----------------------------------------------- -------------------

  2. #2
    Twój kod jest zbyt trudny do odczytania! spróbuj wciskać odpowiednie części i ewentualnie umieszczać części w funkcjach, aby nie trzeba było czytać wielu linii, aby ustalić, co się dzieje. Na pierwszy rzut oka może to być tak, że ustawiasz Istrade = True; i dlatego nie dopuszcza kolejnej transakcji, ponieważ już handel jest prawdziwym HTH

  3. #3
    Tak, to jest kod budowniczego EA ... Sugeruję, abyś używał innego szablonu do budowania EA, ale jeśli nalegasz na używanie tego, musisz zadzierać ze zmienną IsTrade. Zasadniczo, zmień ją na podwójną zmienną, a każdy OrderSend doda 1 do liczby transakcji. Tak więc przed złożeniem zamówienia upewnij się, że liczba transakcji jest mniejsza niż pewna zmienna MaxTrades. Coś w tym stylu.

  4. #4
    1 Załącznik (-i) Hi jcalow, Dodałem 2 nowe zmienne. extern bool UseIsTrade = false; extern int Maxtrades = 5; UseIsTrade: Kiedy ta wartość jest ustawiona na false, zignoruje całą deklarację zmiennej IsTrade i wszelkie zmiany jej wartości. Naprzeciwko dzieje się, gdy jest ustawione na true. Maxtrades: Jest to zmienna sprawdzająca licznik. Zasadniczo policzy ona liczbę otwartych transakcji otwartych przez twój EA, niezależnie od tego, czy jest to KUPNA, czy SPRZEDAJ. Odbywa się to za pomocą numeru magicznego ustawionego przez EA. Sprawdza również, czy transakcje są otwierane przez ich odpowiednią parę walutową. Jeśli liczba otwartych transakcji jest większa lub równa liczbie maksymalnej. transakcji, które nie są dozwolone, nie pozwoli EA otworzyć więcej nowych transakcji. W skrócie Jeśli ustawię Maxtrades na wartość 5 i jeśli mam już 5 otwartych transakcji, EA przestanie otwierać nowe.
    https://www.forex-instant.com/attach...3665102391.mq4

Uprawnienia umieszczania postów

  • Nie możesz zakładać nowych tematów
  • Nie możesz pisać wiadomości
  • Nie możesz dodawać załączników
  • Nie możesz edytować swoich postów
  •  
Używamy cookies
Używamy cookies, aby jak najlepiej dostosować witrynę do Twoich potrzeb. Kontynuowanie przeglądania tej strony, oznacza zgodę na używanie plików cookies. Aby uzyskać więcej informacji zapoznaj się z naszą Polityką Prywatności.