Jak dodać zamknięcie i odwrócić do istniejącego kodu, który działa?
Pokaż wyniki od 1 do 2 z 2

Wątek: Jak dodać zamknięcie i odwrócić do istniejącego kodu, który działa?

  1. #1
    To będzie długi post z dużą ilością linii kodu ...

    Mam istniejący kod, który działa zgodnie z zamierzeniami, który zajmuje wiele pozycji i zamyka się na ukrytych poziomach SL i TP.

    Chcę dodać do istniejących funkcji kodu, które pozwalają EA na zamykanie i cofanie, jeśli sygnały są generowane przed trafieniem SL lub TP.

    Oto istniejący kod, który działa dobrze:

    Wstawiony kod/---------------------------------------------- ----/PARAMETRY TRADINGOWE/---------------------------------------- ---------- RefreshRates (); {jeśli (NIESTANDARDOWY SYGNAŁ HANDLU ZA KUPNA) {if ((godzina () == 0) (minuta () == 0)) Sen (60000); {fBuy1 (); fBuy2 (); fBuy3 (); fBuy4 (); fBuy5 (); fBuy6 (); }} jeśli (CUSTOM TRADING SIGNAL OF SELL) {if ((Hour () == 0) (Minute () == 0)) Sleep (60000); {fSell1 (); fSell2 (); fSell3 (); fSell4 (); fSell5 (); fSell6 (); }}}}/-------------------------------------------- ------/KUP/--------------------------------------- ----------- void fBuy1 () {int result = OrderSend (ST1, OP_BUY, Partie, Ask, Slippage, 0,0, Open LONG Magic1, Magic1,0, Blue); OrderSelect (wynik, SELECT_BY_TICKET, MODE_TRADES); Drukuj (KUP ZAMÓWIENIE OTWARTE !, #, wynik, at, DoubleToStr (OrderOpenPrice (), cyfry), SL:, DoubleToStr (OrderStopLoss (), cyfry),, TP:, DoubleToStr (OrderTakeProfit (), cyfry),, OpenTrades :, OrdersTotal (),, Close # 91; 1 # 93 ;:, Zamknij # 91; 1 # 93;); jeśli (SignalMail) SendMail (OTWARTY ALERT!), ZAKUP ZAMÓWIENIA OTWARTE! ST1 , # wynik w DoubleToStr (OrderOpenPrice (), cyfry) , SL: DoubleToStr (OrderStopLoss (), cyfry) , TP : DoubleToStr (OrderTakeProfit (), cyfry)); if (result == -1) {int e = GetLastError (); Drukuj (e); }} void fBuy2 () {int result = OrderSend (ST1, OP_BUY, Lots, Ask, Slippage, 0,0, Open LONG Magic2, Magic2,0, Blue); OrderSelect (wynik, SELECT_BY_TICKET, MODE_TRADES); Drukuj (KUP ZAMÓWIENIE OTWARTE !, #, wynik, at, DoubleToStr (OrderOpenPrice (), cyfry), SL:, DoubleToStr (OrderStopLoss (), cyfry),, TP:, DoubleToStr (OrderTakeProfit (), cyfry),, OpenTrades :, OrdersTotal (),, Close # 91; 1 # 93 ;:, Zamknij # 91; 1 # 93;); jeśli (SignalMail) SendMail (OTWARTY ALERT!), ZAKUP ZAMÓWIENIA OTWARTE! ST1 , # wynik w DoubleToStr (OrderOpenPrice (), cyfry) , SL: DoubleToStr (OrderStopLoss (), cyfry) , TP : DoubleToStr (OrderTakeProfit (), cyfry)); if (result == -1) {int e = GetLastError (); Drukuj (e); }} ETC ... powtarzanie kodu trwa nadal przez VoidfBuy6/------------------------------------- -------------/SPRZEDAĆ/-------------------------------- ------------------ void fSell1 () {int result = OrderSend (ST1, OP_SELL, Lots, Bid, Slippage, 0,0, Open SHORT Magic1, Magic1,0, Czerwony); OrderSelect (wynik, SELECT_BY_TICKET, MODE_TRADES); Drukuj (SPRZEDAJ OTWARTE ZAMÓWIENIE !, #, wynik, at, DoubleToStr (OrderOpenPrice (), cyfry), SL:, DoubleToStr (OrderStopLoss (), cyfry),, TP:, DoubleToStr (OrderTakeProfit (), cyfry),, OpenTrades :, OrdersTotal (),, Close # 91; 1 # 93 ;:, Zamknij # 91; 1 # 93;); jeśli (SignalMail) SendMail (OTWARTY ALERT!), SPRZEDAJ ZAMÓWIENIE OTWARTE! ST1 , # wynik w DoubleToStr (OrderOpenPrice (), cyfry) , SL: DoubleToStr (OrderStopLoss (), cyfry) , TP : DoubleToStr (OrderTakeProfit (), cyfry)); if (result == -1) {int e = GetLastError (); Drukuj (e); }} void fSell2 () {int result = OrderSend (ST1, OP_SELL, Lots, Bid, Slippage, 0,0, Open SHORT Magic2, Magic2,0, Red); OrderSelect (wynik, SELECT_BY_TICKET,MODE_TRADES); Drukuj (SPRZEDAJ OTWARTE ZAMÓWIENIE !, #, wynik, at, DoubleToStr (OrderOpenPrice (), cyfry), SL:, DoubleToStr (OrderStopLoss (), cyfry),, TP:, DoubleToStr (OrderTakeProfit (), cyfry),, OpenTrades :, OrdersTotal (),, Close # 91; 1 # 93 ;:, Zamknij # 91; 1 # 93;); jeśli (SignalMail) SendMail (OTWARTY ALERT!), SPRZEDAJ ZAMÓWIENIE OTWARTE! ST1 , # wynik w DoubleToStr (OrderOpenPrice (), cyfry) , SL: DoubleToStr (OrderStopLoss (), cyfry) , TP : DoubleToStr (OrderTakeProfit (), cyfry)); if (result == -1) {int e = GetLastError (); Drukuj (e); }} void fSell3 () {int result = OrderSend (ST1, OP_SELL, Lots, Bid, Slippage, 0,0, Open SHORT Magic3, Magic3,0, Red); OrderSelect (wynik, SELECT_BY_TICKET, MODE_TRADES); Drukuj (SPRZEDAJ OTWARTE ZAMÓWIENIE !, #, wynik, at, DoubleToStr (OrderOpenPrice (), cyfry), SL:, DoubleToStr (OrderStopLoss (), cyfry),, TP:, DoubleToStr (OrderTakeProfit (), cyfry),, OpenTrades :, OrdersTotal (),, Close # 91; 1 # 93 ;:, Zamknij # 91; 1 # 93;); jeśli (SignalMail) SendMail (OTWARTY ALERT!), SPRZEDAJ ZAMÓWIENIE OTWARTE! ST1 , # wynik w DoubleToStr (OrderOpenPrice (), cyfry) , SL: DoubleToStr (OrderStopLoss (), cyfry) , TP : DoubleToStr (OrderTakeProfit (), cyfry)); if (result == -1) {int e = GetLastError (); Drukuj (e); }} ETC ... powtarzanie kodu trwa nadal przez VoidfSell6/------------------------------------- -------------/FUNKCJA HIDDEN SL TP/----------------------------- --------------------- void hidden_stop_loss () {int totalorders = OrdersTotal (); for (int i = totalorders-1; igt; = 0; i--) {OrderSelect (i, SELECT_BY_POS); bool result = false; {if (OrderMagicNumber () == Magic1) {if (OrderType () == OP_BUY iClose (Symbol (), 1,0) lt; NormalizeDouble (OrderOpenPrice () - ((OrderOpenPrice ()100) * StopLossLong1), 3 )) result = OrderClose (OrderTicket (), OrderLots (), Bid, 50, Red); if (OrderType () == OP_SELL iClose (Symbol (), 1,0) gt; NormalizeDouble (OrderOpenPrice () ((OrderOpenPrice ()100) * StopLossShort1), 3)) result = OrderClose (OrderTicket (), OrderLots (), Ask, 50, Red); } if (OrderMagicNumber () == Magic2) {if (OrderType () == OP_BUY iClose (Symbol (), 1,0) lt; NormalizeDouble (OrderOpenPrice () - ((OrderOpenPrice ()100) * StopLossLong2), 3 )) result = OrderClose (OrderTicket (), OrderLots (), Bid, 50, Red); if (OrderType () == OP_SELL iClose (Symbol (), 1,0) gt; NormalizeDouble (OrderOpenPrice () ((OrderOpenPrice ()100) * StopLossShort2), 3)) result = OrderClose (OrderTicket (), OrderLots (), Ask, 50, Red); } if (OrderMagicNumber () == Magic3) {if (OrderType () == OP_BUY iClose (Symbol (), 1,0) lt; NormalizeDouble (OrderOpenPrice () - ((OrderOpenPrice ()100) * StopLossLong3), 3 )) result = OrderClose (OrderTicket (), OrderLots (), Bid, 50, Red); if (OrderType () == OP_SELL iClose (Symbol (), 1,0) gt; NormalizeDouble (OrderOpenPrice () ((OrderOpenPrice ()100) * StopLossShort3), 3)) result = OrderClose (OrderTicket (), OrderLots (), Ask, 50, Red); } ETC ... powtórz kodkontynuuje poprzez Magic6}} return; } void hidden_take_profit () {int totalorders = OrdersTotal (); for (int i = totalorders-1; igt; = 0; i--) {OrderSelect (i, SELECT_BY_POS); bool result = false; {if (OrderMagicNumber () == Magic1) {if (OrderType () == OP_BUY iClose (Symbol (), 1,0) gt; NormalizeDouble (OrderOpenPrice () ((OrderOpenPrice ()100) * TakeProfitLong1), 3 )) result = OrderClose (OrderTicket (), OrderLots (), Bid, 50, Red); if (OrderType () == OP_SELL iClose (Symbol (), 1,0) lt; NormalizeDouble (OrderOpenPrice () - ((OrderOpenPrice ()100) * TakeProfitShort1), 3)) result = OrderClose (OrderTicket (), OrderLots (), Ask, 50, Red); } if (OrderMagicNumber () == Magic2) {if (OrderType () == OP_BUY iClose (Symbol (), 1,0) gt; NormalizeDouble (OrderOpenPrice () ((OrderOpenPrice ()100) * TakeProfitLong2), 3 )) result = OrderClose (OrderTicket (), OrderLots (), Bid, 50, Red); if (OrderType () == OP_SELL iClose (Symbol (), 1,0) lt; NormalizeDouble (OrderOpenPrice () - ((OrderOpenPrice ()100) * TakeProfitShort2), 3)) result = OrderClose (OrderTicket (), OrderLots (), Ask, 50, Red); } if (OrderMagicNumber () == Magic3) {if (OrderType () == OP_BUY iClose (Symbol (), 1,0) gt; NormalizeDouble (OrderOpenPrice () ((OrderOpenPrice ()100) * TakeProfitLong3), 3 )) result = OrderClose (OrderTicket (), OrderLots (), Bid, 50, Red); if (OrderType () == OP_SELL iClose (Symbol (), 1,0) lt; NormalizeDouble (OrderOpenPrice () - ((OrderOpenPrice ()100) * TakeProfitShort3), 3)) result = OrderClose (OrderTicket (), OrderLots (), Ask, 50, Red); } ETC ... powtarzanie kodu trwa przez Magic6}} return; }
    Powyższe działa świetnie, ale chciałem dodać zamknięcie, jeśli przeciwny sygnał i funkcja odwrotna ...
    Chociaż EA wchodzi z wieloma magicznymi liczbami i wychodzi z ukrytych SL i TP z wieloma magicznymi liczbami, chcę, aby opuścił wszystkie otwarte pozycje, jeśli przeciwny sygnał zostanie wygenerowany przed trafieniem SL lub TP, i chcę, żeby to się odwróciło i otworzyło nowa seria przeciwnych pozycji.

    Do tej pory próbowałem, ale nie działa zgodnie z oczekiwaniami ... żadnych innych pomysłów? Chciałbym wykorzystać istniejące ramy ... Co ja tu robię źle?

    Wstawiony kod {if (CUSTOM TRADING SIGNAL FOR BUY) {if ((Hour () == 0) (Minute () == 0)) Sleep (60000); {CloseSell (); lt; ----- Zostało dodane myśląc, że to będzie działać logicznie ... dodatkowa logika poniżej Sleep (10000); lt; ----- dodane, aby dać bufor do zamknięcia istniejących pozycji przed wykonaniem nowych, nie myśl, że wpływa na wyjście fBuy1 (); fBuy2 (); fBuy3 (); fBuy4 (); fBuy5 (); fBuy6 (); } etc .../------------------------------------------- -------/ZAMKNIJ ISTNIEJĄCĄ FUNKCJĘ PRZED PODSTAWIONEI PAKIETY/---------------------------------- ---------------- void CloseSell () {int totalorders = OrdersTotal (); for (int i = totalorders-1; igt; = 0; i--) {OrderSelect (i, SELECT_BY_POS); bool result = false; {if (OrderType () == OP_SELL) {result = OrderClose (OrderTicket (), OrderLots (), Ask, 50, Red); }}}} void CloseBuy () {int totalorders = OrdersTotal (); for (int i = totalorders-1; igt; = 0; i--) {OrderSelect (i, SELECT_BY_POS); bool result = false; {if (OrderType () == OP_BUY) {result = OrderClose (OrderTicket (), OrderLots (), Bid, 50, Red); } } }/ powrót; }
    Dodany kod nie działa tak jak myślałem. Jakieś inne obejścia?

  2. #2
    byłoby pomocne, gdybyś powiedział, co robi nowy kod lub w inny sposób ... także dlaczego nie spróbować wydrukować ostatniego błędu i numeru biletu i rodzaju zamówienia w zamkniętej pętli, abyś mógł zobaczyć, co się dzieje, w przeciwnym razie jest to po prostu zgadywanie

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.