OrdersHistoryTotal

O jezykach programowania w platformach i nie tylko.
Awatar użytkownika
oswarek
Gaduła
Gaduła
Posty: 202
Rejestracja: 15 mar 2013, 11:09

OrdersHistoryTotal

Nieprzeczytany post autor: oswarek »

witam
chce żeby TP był okreslany na podstawie ilosci zamknietych pozycji oraz EA nie otwierał wiecej pozycji jesli przekroczy dany limit.. zrobiłem cos takiego:

Kod: Zaznacz cały

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = (Ask + TakeProfit * Point)         
          + (OrdersHistoryTotal() * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;

Kod: Zaznacz cały

if((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))) {
if (TimeHour(TimeCurrent())>=StartHourServerTime && TimeHour(TimeCurrent())<=EndHourServerTime
    && OrdersHistoryTotal() < maxiloscSL  )
wszystko działa ale tylko gdy nie ma innych pozycji w historii niz te które zawarł ten konkretny EA...jak zrobić żeby funkcja "OrdersHistoryTotal()" podawała do obliczen ilość zlecen tylko tego konkretnego EA na podstawie jego MagicNumber? Czy może musze użyć innej funkcji?

LowcaG
Pasjonat
Pasjonat
Posty: 1068
Rejestracja: 05 paź 2007, 15:39

Re: OrdersHistoryTotal

Nieprzeczytany post autor: LowcaG »

Musisz samemu policzyć.

Napisz do tego funkcje, która na wejście przyjmuje magiczne number

Awatar użytkownika
oswarek
Gaduła
Gaduła
Posty: 202
Rejestracja: 15 mar 2013, 11:09

Re: OrdersHistoryTotal

Nieprzeczytany post autor: oswarek »

to już niestety mnie przerasta :D myslałem że wystarczy gdzieś dorzucic tylko "magicNumber" albo jest inna gotowa funkcja która by szukała tylko pozycji z danym "magicNumber".... :(

-rookie-
Maniak
Maniak
Posty: 2307
Rejestracja: 13 kwie 2015, 19:00

Re: OrdersHistoryTotal

Nieprzeczytany post autor: -rookie- »

Nie chce mi sie włączać MT4 i grzebać w tym, ale nie da się tego zrobić w ten sposób ...? Robisz funkcje getLabel() żeby zrobić unikalne nazwy albo jako OrderLabel jeśli coś takiego jest i potem możesz wyszukiwać wg pierwszej litery albo pierwszych kliklu liczb w OrdersTotal()

//SendOrder(BLA BLA BLA, BLA, BLA, BLAH, margic number, BLA BLA BLA);
SendOrder(BLA BLA BLA, BLA, BLA, BLAH, getLabel(), BLA BLA BLA);

int counter = 0;
string getLabel() {
string label = "d" + counter;
counter ++;
}

for (OrderTotals() itd) {
if (OrderMagicNumber()[0] == "d") {
// otworzy pozycje gdzie w magic number pierwsza liczba bedzie stala albo bedzie jakas litera
// nastepnie sprawdz czy ta pierwsza liczba to jest to co ma być (unikalna)
// albo kilka pierwszych liczba
// następnie sparuj tylko pasujace elementy
}
}

Tak bym kombinowal ale nie chce mi sie teraz w tym grzebac. Czyli robisz unikalny lablel albo magic number dla tych pozycji EA i potem z order totals wyciagasz te ktore pasuja i w nazwie nadajesz jakas pierwsza unikalna litere albo w magin cumber pierwsze 3 cyfry unikalne i potem sprawdzasz w petli orderstotal() margic numbers albo label tych pozycji z historii albo otwartych z tym wzorem pierwszych liter albo cyfr.

Awatar użytkownika
Mustafa
Pasjonat
Pasjonat
Posty: 769
Rejestracja: 20 lip 2010, 10:54

Re: OrdersHistoryTotal

Nieprzeczytany post autor: Mustafa »

dla otwartych pozycji

Kod: Zaznacz cały

 int ilosc_open=0, ilosc_pending=0, ilosc_safe=0;
 int Magic_Number = 666;
 int Orders_Total = OrdersTotal();

   for(i=0 ; i < Orders_Total; i++)
   { 
      if(OrderSelect (i, SELECT_BY_POS) == true)
      {
         if(Symbol()==OrderSymbol() && OrderMagicNumber()==Magic_Number)
         {
            oType = OrderType();  
            if(oType > 1) ilosc_pending++;
            else ilosc_open++;
            if(oType==OP_SELL && OrderOpenPrice() > OrderStopLoss()) ilosc_safe++;
            if(oType==OP_BUY  && OrderOpenPrice() < OrderStopLoss()) ilosc_safe++;
         }
      }
   }
   
to if(Symbol()==OrderSymbol() wywalić jeżeli ma działać na różnych instrumentach jednocześnie

dla zamkniętych pozycji

Kod: Zaznacz cały

int i, history;
hTotal = OrdersHistoryTotal();
 for(i=0;i<hTotal;i++)
 {
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
  {
    if(Symbol()==OrderSymbol() && OrderMagicNumber()==Magic_Number)
    {
       history++;
     }
  }
}
https://www.mql5.com/en/docs/trading/orderselect

http://bossa.pl/index.jsp?layout=2&page ... at_id=1352
Nie chodzi o to czy masz rację czy nie, tylko o to, co robisz kiedy masz rację lub jak się zachowujesz jeżeli racji nie masz.

Awatar użytkownika
oswarek
Gaduła
Gaduła
Posty: 202
Rejestracja: 15 mar 2013, 11:09

Re: OrdersHistoryTotal

Nieprzeczytany post autor: oswarek »

dzięki wszystkim za pomoc :) po wielu probach udało sie :) ogolnie nie bardzo umiem pisac roboty i dlatego robie to troche "na ślepo"...
kod wyglada w tej chwili tak:

Kod: Zaznacz cały

int j, history; 
hTotal = OrdersTotal();
 for (j=0;j<hTotal;j++)
 {
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
  {
    if(Symbol()==OrderSymbol() && OrderMagicNumber()==oMagic)
    {
       history++;
     }
  }
kod na przesuwanie TP:

Kod: Zaznacz cały

         if (UseTakeProfit) TakeProfitLevel = (Ask + TakeProfit * Point)         
          + (hTotal * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;
kod na zatrzymanie EA po serii SL-i

Kod: Zaznacz cały

if((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))) {
if (TimeHour(TimeCurrent())>=StartHourServerTime && TimeHour(TimeCurrent())<=EndHourServerTime
    && hTotal < maxiloscSL  )

jednak nie działa w tej postaci a gdy zamiast OrdersTotal jest OrdersHistoryTotal to dalej liczy wszystkie pozycje..:(

-rookie-
Maniak
Maniak
Posty: 2307
Rejestracja: 13 kwie 2015, 19:00

Re: OrdersHistoryTotal

Nieprzeczytany post autor: -rookie- »

A w OrderSend() wpisałeś ten magic number, przy wysyłaniu zleceń przez EA. Bo jak nie nadałeś tego przy wysłaniu zleceniu to potem nie ma tego w obiekcie, czyli w informacji o pozycji i potem jak puścisz pętle żeby szukało tego magic number to nie znajdzie a masz warunek if(Symbol()==OrderSymbol() && OrderMagicNumber()==oMagic) co znaczy że masz mieć spełnione 2 warunki JEDNOCZEŚNIE żeby ten warunek zadziałał !!! Najpierw porównanie nazwy instrumentu z instrumentem w zleceniu a drugie masz właśnie ten magic number. Sprawdź co wyświetla najpierw sam warunek Print(Symbol()) oraz Print(OrderSymbol()) w tej pętli. Pokombinuj troche z tym bo bez pełnego kodu EA to po błądzenie po omacku, domyślanie się o co może chodzić... W ogóle co to jest oMagic, masz to zdefiniowane...?

Awatar użytkownika
oswarek
Gaduła
Gaduła
Posty: 202
Rejestracja: 15 mar 2013, 11:09

Re: OrdersHistoryTotal

Nieprzeczytany post autor: oswarek »

to co podesłał Mustafa wklejalem w różne miejsca i troche pozmieniałem zeby sie kompilowało.. w tej chwili jest w znaczniku "//funkcja liczenia zamknietych pozycji"

a tam gdzie miałem "OrderHistoryTotal()" to pozaminiałem na "hTotal" i dodałem linijke "int hTotal;" w 34 linijce bo inaczej mi nie kompilowało..

w tym EA nie ma "Magic_Number" tylko "MagicNumber" wiec użyłem tej wersji

kod wyglada teraz tak i kompiluje ale dalej uzywa wszystkich pozycji do policzenia TP


Kod: Zaznacz cały


#property copyright "EA"

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#define NL "\n"

extern int MagicNumber = 100;
extern bool EachTickMode = False;
extern string String4 = "--------MM Management---------";
extern string Min_Account_Balance_opis = "Minimalna ilość depozytu, jako ochrona przed wyzerowaniem konta PLN,EUR,USD";
extern int Min_Account_Balance = 5;
extern double STARTLots = 0.10;
extern double Lots = 0.10;
extern double LotsChangeAfterSL = 1;
extern int pozycjaSTART = 1;
extern double MaxLots = 1.0;
extern int Slippage = 2;
extern bool UseStopLoss = True;
extern int StopLoss = 100;
extern int maxiloscSL = 10;
extern bool UseTakeProfit = True;
extern int TakeProfit = 100;
extern int TakeProfit2 = 100;
extern int StartHourServerTime = 0;
extern int EndHourServerTime = 24;


int hTotal;



int BarCount;
int Current;
bool TickCheck = False;






//funkcja zwracania ticketu ostatniego zamknietego zlecenia

int last_closed_order_ticket(int oMagic) {

      //funkcja liczenia zamknietych pozycji

int j, history; 
hTotal = OrdersHistoryTotal();
 for (j=0;j<hTotal;j++)
 {
   if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true)
  {
    if(Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber)
    {
       history++;
     }
  }
}

int ostatniezlecenie = 0;
int last_closed_time = 0;

for(int k=OrdersHistoryTotal();k>=0;k--) // Check the last 10 closed orders in history

{

if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY)) {

if(OrderMagicNumber()==oMagic) {
      if(OrderSymbol()==Symbol()) {

if(OrderCloseTime()>last_closed_time)

{

last_closed_time=OrderCloseTime();

ostatniezlecenie=OrderTicket();

}
}
}
}

}
return(ostatniezlecenie);
}




//licznik zleceñ ze strony fxcraft.biz

int countOrders(int oMagic,int oType) {

   int count=0;

   for(int i=0;i<OrdersTotal();i++) {
    if(OrderSelect(i,SELECT_BY_POS)) {
     if(OrderMagicNumber()==oMagic) {
      if(OrderSymbol()==Symbol()) {
       if(OrderType()==oType || oType<0) {
        count++;
       }
      }
     }
    }
   }


   return(count);

}





//-----------

double last_order_profit() {
   double last_order_profit_value = 0;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
                                                    last_order_profit_value = OrderProfit();
                                                   }
   return(last_order_profit_value);
}

double last_order_volume() {
   double last_order_volume_value = 0;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
                                                    last_order_volume_value = OrderLots();
                                                   }
   return(last_order_volume_value);
}

int last_order_type() {
   int last_order_type_value = -1;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
                                                    last_order_type_value = OrderType();
                                                   }
   return(last_order_type_value);
}




//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
void OnInit() {
   BarCount = Bars;


   if (EachTickMode) Current = 0; else Current = 1;
   
   Comment(
           "OS EA OPIS" + NL +
           "MagicNumber = " + MagicNumber + NL +
           "Use EachTickMode = " + EachTickMode + NL +  
           "Lots = " + Lots + NL +
           "Start Lots = " + STARTLots + NL + 
           "MaxLots = " + MaxLots + NL + 
           "pozycja START = " + pozycjaSTART + "/// jesli 0 to SELL" + NL +
           "Lots po SL = " + LotsChangeAfterSL + NL + 
           "StopLossLevel = " + StopLoss/10 + " pips" + NL +
           "TakeProfitLevel = " + TakeProfit/10 + " pips" + NL +
           "TakeProfitLevel2 = " + TakeProfit2/10 + " pips" + NL +
           "max il. SL-i = " + maxiloscSL + NL +
           "Godz. pracy = " "od  " + StartHourServerTime +  "  do  " + EndHourServerTime + NL + 
           
           ".....................");
   return;
}



//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {


   return;
}


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+




 
void OnTick() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;
   double OrderVolume = STARTLots;
   

   




   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
  

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+



   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position

   

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
if((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))) {
if (TimeHour(TimeCurrent())>=StartHourServerTime && TimeHour(TimeCurrent())<=EndHourServerTime
    && hTotal < maxiloscSL  )
   
{

if(countOrders(MagicNumber,-1) < 1) {


if(last_order_type()==-1)
                        {
                           if (pozycjaSTART <= 0)  Order = SIGNAL_SELL;
                           if (pozycjaSTART > 0)  Order = SIGNAL_BUY;
                        }
                        
if(last_order_type()==0)
                        {
                           
                                                                                 
                           
                           
                                                   
                           if(last_order_profit()<0)
                                                      
                           {
                           OrderVolume = last_order_volume() * LotsChangeAfterSL;
                           Order = SIGNAL_SELL;
                           }
                           
                           
                         
                            
                        }
if(last_order_type()==1)
                        {
                          
                                                                                 
                                                      
                           
                           if(last_order_profit()<0)
                          
                           {
                           OrderVolume = last_order_volume() * LotsChangeAfterSL;
                           Order = SIGNAL_BUY;
                           }
                            
                         }
          
}

}
}


   

   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      
         //Check free margin
         
         if (AccountBalance() < Min_Account_Balance ) {
            Print("We have no money. Game over. Balance =", AccountBalance());
            return;
         }

         if(OrderVolume > MaxLots) OrderVolume = Lots;
         if(OrderVolume < Lots) OrderVolume=  Lots;
         
         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = (Ask + TakeProfit * Point)         
          + (hTotal * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, OrderVolume, Ask, Slippage, StopLossLevel, TakeProfitLevel,"Buy(#" + MagicNumber +")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
				Print("BUY order opened :", OrderOpenPrice());
			} else {
				Print("Error opening BUY order :", GetLastError());
			}
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         Print("Last order profit :", last_order_profit());
         Print("Last order volume :", last_order_volume());
         Print("Last order ticket :", last_closed_order_ticket(MagicNumber));
         return;
      
   }

   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
       
         //Check free margin
         if (AccountBalance() < Min_Account_Balance ) {
            Print("We have no money. Game over. Balance =", AccountBalance());
            return;
         }

         if(OrderVolume > MaxLots) OrderVolume = Lots;
         if(OrderVolume < Lots) OrderVolume=  Lots;
         
         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point
         - (hTotal * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, OrderVolume, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber +")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
				Print("SELL order opened :", OrderOpenPrice());
			} else {
				Print("Error opening SELL order : ", GetLastError());
			}
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         Print("Last order profit :", last_order_profit());
         Print("Last order volume :", last_order_volume());
         Print("Last order ticket :", last_closed_order_ticket(MagicNumber));
         return;
      
   }

   if (!EachTickMode) BarCount = Bars;

   return;
}
//+------------------------------------------------------------------+

-rookie-
Maniak
Maniak
Posty: 2307
Rejestracja: 13 kwie 2015, 19:00

Re: OrdersHistoryTotal

Nieprzeczytany post autor: -rookie- »

Sprawdziłem powierzchownie tylko, tam gdzie wstawiłeś tą pętle i chyba w ogóle nie wywołujesz w tym kodzie funkcji last_order_profit() oraz last_order_volume()
Zobacz sobie ten kod, zamiast EA dalem guziki BUY / SELL na wykresie i te otwieram pozycje 0.01 lota z tym magic number ustawionym w globalnych zmiennych i w ogóle tej funkcji nie ma wywołanej tam gdzie zdefiniowałeś

Kod: Zaznacz cały

#property copyright "EA"

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#define NL "\n"

extern int MagicNumber = 100;
extern bool EachTickMode = False;
extern string String4 = "--------MM Management---------";
extern string Min_Account_Balance_opis = "Minimalna ilość depozytu, jako ochrona przed wyzerowaniem konta PLN,EUR,USD";
extern int Min_Account_Balance = 5;
extern double STARTLots = 0.01;
extern double Lots = 0.01;
extern double LotsChangeAfterSL = 1;
extern int pozycjaSTART = 1;
extern double MaxLots = 1.0;
extern int Slippage = 2;
extern bool UseStopLoss = True;
extern int StopLoss = 100;
extern int maxiloscSL = 10;
extern bool UseTakeProfit = True;
extern int TakeProfit = 100;
extern int TakeProfit2 = 100;
extern int StartHourServerTime = 0;
extern int EndHourServerTime = 24;


int hTotal;



int BarCount;
int Current;
bool TickCheck = False;






//funkcja zwracania ticketu ostatniego zamknietego zlecenia

int last_closed_order_ticket(int oMagic) {

      //funkcja liczenia zamknietych pozycji
      
      Print( 123 );

int j, history;
hTotal = OrdersHistoryTotal();
 for (j=0;j<hTotal;j++)
 {
   if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true)
  {
  Print( 123 );
    if(Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber)
    {
       history++;
     }
  }
}

int ostatniezlecenie = 0;
int last_closed_time = 0;

for(int k=OrdersHistoryTotal();k>=0;k--) // Check the last 10 closed orders in history

{

if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY)) {

if(OrderMagicNumber()==oMagic) {
      if(OrderSymbol()==Symbol()) {

if(OrderCloseTime()>last_closed_time)

{

last_closed_time=OrderCloseTime();

ostatniezlecenie=OrderTicket();

}
}
}
}

}
return(ostatniezlecenie);
}




//licznik zleceñ ze strony fxcraft.biz

int countOrders(int oMagic,int oType) {

   int count=0;

   for(int i=0;i<OrdersTotal();i++) {
    if(OrderSelect(i,SELECT_BY_POS)) {
     if(OrderMagicNumber()==oMagic) {
      if(OrderSymbol()==Symbol()) {
       if(OrderType()==oType || oType<0) {
        count++;
       }
      }
     }
    }
   }


   return(count);

}





//-----------

double last_order_profit() {
   double last_order_profit_value = 0;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
                                                    last_order_profit_value = OrderProfit();
                                                   }
   return(last_order_profit_value);
}

double last_order_volume() {
   double last_order_volume_value = 0;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
                                                    last_order_volume_value = OrderLots();
                                                   }
   return(last_order_volume_value);
}

int last_order_type() {
   int last_order_type_value = -1;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
                                                    last_order_type_value = OrderType();
                                                   }
   return(last_order_type_value);
}




//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
void OnInit() {
   BarCount = Bars;


   //
   createBUYButton();
   createSELLButton();
   
   //

   if (EachTickMode) Current = 0; else Current = 1;
   
   Comment(
           "OS EA OPIS" + NL +
           "MagicNumber = " + MagicNumber + NL +
           "Use EachTickMode = " + EachTickMode + NL + 
           "Lots = " + Lots + NL +
           "Start Lots = " + STARTLots + NL +
           "MaxLots = " + MaxLots + NL +
           "pozycja START = " + pozycjaSTART + "/// jesli 0 to SELL" + NL +
           "Lots po SL = " + LotsChangeAfterSL + NL +
           "StopLossLevel = " + StopLoss/10 + " pips" + NL +
           "TakeProfitLevel = " + TakeProfit/10 + " pips" + NL +
           "TakeProfitLevel2 = " + TakeProfit2/10 + " pips" + NL +
           "max il. SL-i = " + maxiloscSL + NL +
           "Godz. pracy = " "od  " + StartHourServerTime +  "  do  " + EndHourServerTime + NL +
           
           ".....................");
   return;
}



//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {

   ObjectDelete("btnBUY");
   ObjectDelete("btnSELL");
   return;
}


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+




 
void OnTick() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;
   double OrderVolume = STARTLots;
   

   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
 

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+



   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position

   

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
if((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))) {
if (TimeHour(TimeCurrent())>=StartHourServerTime && TimeHour(TimeCurrent())<=EndHourServerTime
    && hTotal < maxiloscSL  )
   
{

if(countOrders(MagicNumber,-1) < 1) {


if(last_order_type()==-1)
                        {
                           if (pozycjaSTART <= 0)  Order = SIGNAL_SELL;
                           if (pozycjaSTART > 0)  Order = SIGNAL_BUY;
                        }
                       
if(last_order_type()==0)
                        {
                           
                                                                                 
                           
                           
                                                   
                           if(last_order_profit()<0)
                                                     
                           {
                           OrderVolume = last_order_volume() * LotsChangeAfterSL;
                           Order = SIGNAL_SELL;
                           }
                           
                           
                         
                           
                        }
if(last_order_type()==1)
                        {
                         
                                                                                 
                                                     
                           
                           if(last_order_profit()<0)
                         
                           {
                           OrderVolume = last_order_volume() * LotsChangeAfterSL;
                           Order = SIGNAL_BUY;
                           }
                           
                         }
         
}

}
}


   
   /*
   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
     
         //Check free margin
         
         if (AccountBalance() < Min_Account_Balance ) {
            Print("We have no money. Game over. Balance =", AccountBalance());
            return;
         }

         if(OrderVolume > MaxLots) OrderVolume = Lots;
         if(OrderVolume < Lots) OrderVolume=  Lots;
         
         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = (Ask + TakeProfit * Point)         
          + (hTotal * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, OrderVolume, Ask, Slippage, StopLossLevel, TakeProfitLevel,"Buy(#" + MagicNumber +")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
            Print("BUY order opened :", OrderOpenPrice());
         } else {
            Print("Error opening BUY order :", GetLastError());
         }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         Print("Last order profit :", last_order_profit());
         Print("Last order volume :", last_order_volume());
         Print("Last order ticket :", last_closed_order_ticket(MagicNumber));
         return;
     
   }

   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
       
         //Check free margin
         if (AccountBalance() < Min_Account_Balance ) {
            Print("We have no money. Game over. Balance =", AccountBalance());
            return;
         }

         if(OrderVolume > MaxLots) OrderVolume = Lots;
         if(OrderVolume < Lots) OrderVolume=  Lots;
         
         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point
         - (hTotal * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, OrderVolume, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber +")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
            Print("SELL order opened :", OrderOpenPrice());
         } else {
            Print("Error opening SELL order : ", GetLastError());
         }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         Print("Last order profit :", last_order_profit());
         Print("Last order volume :", last_order_volume());
         Print("Last order ticket :", last_closed_order_ticket(MagicNumber));
         return;
     
   }
   */

   if (!EachTickMode) BarCount = Bars;

   return;
}
//+------------------------------------------------------------------+



//////
/////
////
///
//
//

void createBUYButton() {
   ObjectCreate(ChartID(), "btnBUY", OBJ_BUTTON, 0 ,0, 0);
   ObjectSetInteger(ChartID(), "btnBUY",OBJPROP_XDISTANCE,100);
   ObjectSetInteger(ChartID(), "btnBUY",OBJPROP_YDISTANCE,100);
   ObjectSetString(ChartID(), "btnBUY",OBJPROP_TEXT,"buy");
}

void createSELLButton() {
   ObjectCreate(ChartID(), "btnSELL", OBJ_BUTTON, 0 ,0, 0);
   ObjectSetInteger(ChartID(), "btnSELL",OBJPROP_XDISTANCE,200);
   ObjectSetInteger(ChartID(), "btnSELL",OBJPROP_YDISTANCE,100);
   ObjectSetString(ChartID(), "btnSELL",OBJPROP_TEXT,"sell");
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
      if(id == CHARTEVENT_OBJECT_CLICK) {
         string clickedChartObject = sparam;
         //--- If you click on the object with the name buttonID
            if(clickedChartObject == "btnBUY") {
               sendBuyOrder();
               Print( 1 );
            } else {
               Print( "error" );
            }
            if(clickedChartObject == "btnSELL") {
               //
            } else {
               Print( "error" );
            }
      }
  }
//+------------------------------------------------------------------+

void sendBuyOrder() {
   OrderSend(Symbol(), OP_BUY, 0.01, Ask, Slippage, 0, 0,"Buy(#" + MagicNumber +")", MagicNumber, 0, clrGreen);
   //OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen);
}
Moze jakis blad zrobilem... nie wiem... tak na szybko to sprawdzilem. Jak klikniesz BUY to otworzy 0.01 lota a potem EA dolozy 0.02, 0.04 itd bedzie piramidowac. ALE TEJ FUNKCJI NIE WYWOLUJE PRZEZ CO PETLA SIE NIE REALIZUJE. Nie dochodzi do sprawdzenia warunkow gdzie to wstawiles dlatego nie wywoluje tej petli chyba.

-- Dodano: 15 sie 2018, 02:06 --

heh, miałem właczone jeszcze jakies EA na innym wykresie ktore robilem dlatego mi otwierale te pozycje 0.01 potem 0.02. To nie twoje EA. Zamotałem się przez to. Sprawdze jeszcze raz to twoje EA potem.

-- Dodano: 15 sie 2018, 03:51 --

F..c. Nie ogarniam o co w ogóle chodzi w tym EA :roll:
Może Mustafa na to rzuci okiem jeszcze.
Zrobiłem takie coś...
Ten kod który napisałeś wstawiłem jako osobną funkcje

Kod: Zaznacz cały

int countHistoricalOrder() {
   int j;
   int history;
   hTotal = OrdersHistoryTotal();
   for (j=0;j<hTotal;j++) {
      if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true) {
         if(Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber) {
            history++;
         }
      }
   }
   return history;
}
I to zwraca tylko te pozycje z tym magic number. Następnie zamiast hTotal wywołałem w tej linijce countHistoricalOrder()

Kod: Zaznacz cały

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = (Ask + TakeProfit * Point)         
          + (countHistoricalOrder() * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;
Dodalem guziki BUY SELL oraz CLOSE które działają na testerze historycznym. Żeby ich nie było po prostu można ich nie wywoływac w onInit() - czyli skasować te 3 linijki kodu, albo dać w komentarz

Kod: Zaznacz cały

void OnInit() {
   BarCount = Bars;

   //.
   createBUYButton();
   createSELLButton();
   createCLOSEButton();

- CAŁY KOD - z moimi modyfikacjami.

Kod: Zaznacz cały

#property copyright "EA"

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#define NL "\n"

extern int MagicNumber = 100;
extern bool EachTickMode = False;
extern string String4 = "--------MM Management---------";
extern string Min_Account_Balance_opis = "Minimalna ilość depozytu, jako ochrona przed wyzerowaniem konta PLN,EUR,USD";
extern int Min_Account_Balance = 5;
extern double STARTLots = 0.01;
extern double Lots = 0.01;
extern double LotsChangeAfterSL = 1;
extern int pozycjaSTART = 1;
extern double MaxLots = 1.0;
extern int Slippage = 2;
extern bool UseStopLoss = True;
extern int StopLoss = 100;
extern int maxiloscSL = 10;
extern bool UseTakeProfit = True;
extern int TakeProfit = 100;
extern int TakeProfit2 = 100;
extern int StartHourServerTime = 0;
extern int EndHourServerTime = 24;

int hTotal;

int BarCount;
int Current;
bool TickCheck = False;



//funkcja zwracania ticketu ostatniego zamknietego zlecenia
int last_closed_order_ticket(int oMagic) {
   //funkcja liczenia zamknietych pozycji
   //int j, history;
   /*
   int j;
   int history;
   hTotal = OrdersHistoryTotal();
   for (j=0;j<hTotal;j++) {
      if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true) {
         if(Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber) {
            history++;
            Print( " 111231241241 4 sss ---> " + history);
         }
      }
   }
   */
   
   Print( countHistoricalOrder() );
   
   
   int ostatniezlecenie = 0;
   int last_closed_time = 0;
   
   for(int k=OrdersHistoryTotal();k>=0;k--) { // Check the last 10 closed orders in history
      if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY)) {
         if(OrderMagicNumber()==oMagic) {
            if(OrderSymbol()==Symbol()){
               if(OrderCloseTime()>last_closed_time){
                  last_closed_time=OrderCloseTime();
                  ostatniezlecenie=OrderTicket();
               }
            }
         }
      }
   }
   return(ostatniezlecenie);
}

int countHistoricalOrder() {
   int j;
   int history;
   hTotal = OrdersHistoryTotal();
   for (j=0;j<hTotal;j++) {
      if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true) {
         if(Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber) {
            history++;
         }
      }
   }
   return history;
}


//licznik zleceñ ze strony fxcraft.biz
int countOrders(int oMagic,int oType) {
   int count=0;
   for(int i=0;i<OrdersTotal();i++) {
      if(OrderSelect(i,SELECT_BY_POS)) {
         if(OrderMagicNumber()==oMagic) {
            if(OrderSymbol()==Symbol()) {
               if(OrderType()==oType || oType<0) {
                  count++;
               }
            }
         }
      }
   }
   return(count);

}

//-----------

double last_order_profit() {
   double last_order_profit_value = 0;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
      last_order_profit_value = OrderProfit();
   }
   return(last_order_profit_value);
}

double last_order_volume() {
   double last_order_volume_value = 0;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
      last_order_volume_value = OrderLots();
   }
   return(last_order_volume_value);
}

int last_order_type() {
   int last_order_type_value = -1;
   int q = last_closed_order_ticket(MagicNumber);
   if(OrderSelect(q, SELECT_BY_TICKET, MODE_HISTORY)) {
      last_order_type_value = OrderType();
   }
   return(last_order_type_value);
}

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
void OnInit() {
   BarCount = Bars;

   //.
   createBUYButton();
   createSELLButton();
   createCLOSEButton();
   

   if (EachTickMode) Current = 0; else Current = 1;
   
   Comment(
           "OS EA OPIS" + NL +
           "MagicNumber = " + MagicNumber + NL +
           "Use EachTickMode = " + EachTickMode + NL + 
           "Lots = " + Lots + NL +
           "Start Lots = " + STARTLots + NL +
           "MaxLots = " + MaxLots + NL +
           "pozycja START = " + pozycjaSTART + "/// jesli 0 to SELL" + NL +
           "Lots po SL = " + LotsChangeAfterSL + NL +
           "StopLossLevel = " + StopLoss/10 + " pips" + NL +
           "TakeProfitLevel = " + TakeProfit/10 + " pips" + NL +
           "TakeProfitLevel2 = " + TakeProfit2/10 + " pips" + NL +
           "max il. SL-i = " + maxiloscSL + NL +
           "Godz. pracy = " "od  " + StartHourServerTime +  "  do  " + EndHourServerTime + NL +
           
           ".....................");
   return;
}



//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
   ObjectDelete("btnBUY");
   ObjectDelete("btnSELL");
   ObjectDelete("btnCLOSE");
   return;
}


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
 
void OnTick() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;
   double OrderVolume = STARTLots;
   
   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
 
   //Print( Bars );
   int j, history;
   hTotal = OrdersHistoryTotal();
   for (j=0;j<hTotal;j++) {
      if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true) {
         if(Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber) {
            //Print( " >>>>>>>>> " + j + " " + OrderMagicNumber() + " " + OrderSymbol() );
         } else {
            //Print( " none " );
         }
      }
   }

   // OnChartEvent doesn't work in the tester
   if (IsTesting()) {
      if(ObjectGetInteger(ChartID(),"btnBUY",OBJPROP_STATE)==true) {
         sendBuyOrder();
         ObjectSetInteger(ChartID(),"btnBUY",OBJPROP_STATE,false);
      }
      if(ObjectGetInteger(ChartID(),"btnSELL",OBJPROP_STATE)==true) {
         sendSellOrder();
         ObjectSetInteger(ChartID(),"btnSELL",OBJPROP_STATE,false);
      }
      if(ObjectGetInteger(ChartID(),"btnCLOSE",OBJPROP_STATE)==true) {
         manuallyCloseOrder();
         ObjectSetInteger(ChartID(),"btnCLOSE",OBJPROP_STATE,false);
      }
   }

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+



   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position

   

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
if((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))) {
   if (TimeHour(TimeCurrent())>=StartHourServerTime && TimeHour(TimeCurrent())<=EndHourServerTime && hTotal < maxiloscSL) { 
      if(countOrders(MagicNumber,-1) < 1) {

      if(last_order_type()==-1) {
         if (pozycjaSTART <= 0)  Order = SIGNAL_SELL;
         if (pozycjaSTART > 0)  Order = SIGNAL_BUY;
      }
                             
      if(last_order_type()==0) {                    
         if(last_order_profit()<0) {
            OrderVolume = last_order_volume() * LotsChangeAfterSL;
            Order = SIGNAL_SELL;
         }
      }
      
      if(last_order_type()==1){
         if(last_order_profit()<0) {
            OrderVolume = last_order_volume() * LotsChangeAfterSL;
            Order = SIGNAL_BUY;
         }
      }
               
      }
   }
}

   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+
   
   
   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
     
         //Check free margin
         
         if (AccountBalance() < Min_Account_Balance ) {
            Print("We have no money. Game over. Balance =", AccountBalance());
            return;
         }

         if(OrderVolume > MaxLots) OrderVolume = Lots;
         if(OrderVolume < Lots) OrderVolume=  Lots;
         
         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = (Ask + TakeProfit * Point)         
          + (countHistoricalOrder() * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, OrderVolume, Ask, Slippage, StopLossLevel, TakeProfitLevel,"Buy(#" + MagicNumber +")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
            Print("BUY order opened :", OrderOpenPrice());
         } else {
            Print("Error opening BUY order :", GetLastError());
         }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         Print("Last order profit :", last_order_profit());
         Print("Last order volume :", last_order_volume());
         Print("Last order ticket :", last_closed_order_ticket(MagicNumber));
         return;
     
   }

   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
       
         //Check free margin
         if (AccountBalance() < Min_Account_Balance ) {
            Print("We have no money. Game over. Balance =", AccountBalance());
            return;
         }

         if(OrderVolume > MaxLots) OrderVolume = Lots;
         if(OrderVolume < Lots) OrderVolume=  Lots;
         
         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point
         - (countHistoricalOrder() * (TakeProfit2 * Point)); else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, OrderVolume, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber +")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
            Print("SELL order opened :", OrderOpenPrice());
         } else {
            Print("Error opening SELL order : ", GetLastError());
         }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         Print("Last order profit :", last_order_profit());
         Print("Last order volume :", last_order_volume());
         Print("Last order ticket :", last_closed_order_ticket(MagicNumber));
         return;
     
   }
   

   if (!EachTickMode) BarCount = Bars;

   return;
}
//+------------------------------------------------------------------+

//////
/////
////
///
//
//

void createBUYButton() {
   ObjectCreate(ChartID(), "btnBUY", OBJ_BUTTON, 0 ,0, 0);
   ObjectSetInteger(ChartID(), "btnBUY",OBJPROP_XDISTANCE,100);
   ObjectSetInteger(ChartID(), "btnBUY",OBJPROP_YDISTANCE,100);
   ObjectSetString(ChartID(), "btnBUY",OBJPROP_TEXT,"buy");
}

void createSELLButton() {
   ObjectCreate(ChartID(), "btnSELL", OBJ_BUTTON, 0 ,0, 0);
   ObjectSetInteger(ChartID(), "btnSELL",OBJPROP_XDISTANCE,200);
   ObjectSetInteger(ChartID(), "btnSELL",OBJPROP_YDISTANCE,100);
   ObjectSetString(ChartID(), "btnSELL",OBJPROP_TEXT,"sell");
}

void createCLOSEButton() {
   ObjectCreate(ChartID(), "btnCLOSE", OBJ_BUTTON, 0 ,0, 0);
   ObjectSetInteger(ChartID(), "btnCLOSE",OBJPROP_XDISTANCE,150);
   ObjectSetInteger(ChartID(), "btnCLOSE",OBJPROP_YDISTANCE,200);
   ObjectSetString(ChartID(), "btnCLOSE",OBJPROP_TEXT,"CLOSE");
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
      if(id == CHARTEVENT_OBJECT_CLICK) {
         string clickedChartObject = sparam;
         //--- If you click on the object with the name buttonID
            if(clickedChartObject == "btnBUY") {
               sendBuyOrder();
               Print( 1 );
            } else {
               Print( "error" );
            }
            if(clickedChartObject == "btnSELL") {
               //
            } else {
               Print( "error" );
            }
      }
  }
//+------------------------------------------------------------------+

void sendBuyOrder() {
   OrderSend(Symbol(), OP_BUY, 0.01, Ask, Slippage, 0, 0,"Buy(#" + MagicNumber +")", MagicNumber, 0, clrGreen);
}

void sendSellOrder() {
   OrderSend(Symbol(), OP_SELL, 0.01, Bid, Slippage, 0, 0,"Sell(#" + MagicNumber +")", MagicNumber, 0, clrRed);
}

void manuallyCloseOrder() {
   for(int i=OrdersTotal(); i>=0; i--) {
      if(OrderSelect(i, SELECT_BY_POS)==true) {
         if (OrderType() == 0) {
            OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0, clrNONE);
         } else if (OrderType() == 1) {
            OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0, clrNONE);
         }
      }
   }
}
Mustafa :568:
Ty lepiej ogarniasz MT4

-- Dodano: 15 sie 2018, 04:04 --

Oswarek przypisał do globalnej zmiennej hTotal = OrdersHistoryTotal();
Nie przefiltrowane, dopiero to history było przefiltrowanym wynikiem
Według mnie tutaj był błąd, dlatego dałem to jako osobna funkcja która liczy tylko te pozycje z tym magic number
i potem własnie tej linijce co oswarek pisal ze dal hTotal wywołałem countHistoricalOrder()
czyli przefiltrowane a nie OrdersHistoryTotal() jak miało to zdefiniowane oswarek
Może połapiesz się dalej co z tym zrobić.

Awatar użytkownika
oswarek
Gaduła
Gaduła
Posty: 202
Rejestracja: 15 mar 2013, 11:09

Re: OrdersHistoryTotal

Nieprzeczytany post autor: oswarek »

jeszcze raz dzieki za pomoc :)
EA juz działa tak jak chciałem czyli uzywa tylko swoich(według magicumber) pozycji z historii
"countHistoricalOrder()" - przywoluje ilosc zamknietych pozycji do obliczen a jego funckaja jest zapisana w ten sposob:

Kod: Zaznacz cały

int countHistoricalOrder() {
   int j;
   int history;
   hTotal = OrdersHistoryTotal();
   for (j=0;j<hTotal;j++) {
      if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true) {
         if(Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber) {
            history++;
         }
      }
   }
   return history;
}

ODPOWIEDZ