EA oparty na niestandardowym wskaźniku

O jezykach programowania w platformach i nie tylko.
Awatar użytkownika
personov
Pasjonat
Pasjonat
Posty: 1525
Rejestracja: 09 sie 2009, 21:27

Nieprzeczytany post autor: personov »

(...)edit
...kosz

Dodano po 22 godzinach 45 minutach:

Sprawdź to zamykanie, bo nie testowałem. Trochę bałagan w kodzie, bo tylko przekleiłem fragment z innego EA. Pamiętaj, żeby ten lost nie był mniejszy lub równy od spreadu, bo otworzy pozycję i odrazu ją zamknie.

Kod: Zaznacz cały

#include <stdlib.mqh> 
int MagicNumber    = 888634; 
extern double lot          = 1; 
extern int    lost           = 3;
extern int    intensity    = 18; 
extern int    periods      = 800; 
extern bool   TrailingStop = true; 
extern int    ActivateTS   = 1; 
extern int    StepTS       = 10;
 
int    profit       = 3000;
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void init() 
{} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void deinit() 
{} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void start() 
{ 
   double it1 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,0); 
   double it2 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,1); 
   //trailing stop 
   if (total(OP_BUY )>0 && TrailingStop==true) ts(OP_BUY ); 
   if (total(OP_SELL)>0 && TrailingStop==true) ts(OP_SELL); 
   if(total(OP_BUY)==0&&it1>0&&it2<=0)send(OP_BUY); 
   if(total(OP_SELL)==0&&it1<0&&it2>=0)send(OP_SELL);

   if (total(OP_BUY)>0)ZamknijBuy();
   if (total(OP_SELL)>0)ZamknijSell();
} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
int total(int cmd) 
{ 
   int sum=0; 
   for ( int i=0;i<=OrdersTotal();i++) 
   { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES); 
      if (OrderSymbol()==Symbol() && cmd ==OrderType() && MagicNumber==OrderMagicNumber()) sum++; 
   } 
   return(sum); 
} 
/////////////////////////////////////////////////////// 
void send(int cmd) 
{ 
   double Point_ = Point; 
   if (Digits==3 || Digits==5) Point_=Point*10; 
   double tp; 
   double sl; 
   double pr; 
   color cl; 
   if (cmd==OP_BUY) 
   { 
      pr = Ask; 
      tp = 0; 
      sl = 0; 
      cl = Blue; 
   } 
   if (cmd==OP_SELL) 
   { 
      pr = Bid; 
      tp = 0; 
      sl = 0; 
      cl = Red; 
   } 
   int ticket = OrderSend(Symbol(),cmd,lot,pr,0,sl,tp,"",MagicNumber,0,cl); 
   if (ticket<=0) Print(ErrorDescription(GetLastError())); 
} 
///////////////////////////////////////////////////////////////////////// 
void ZamknijBuy() 
{      
   int i; 
    
   for (i = 0; i < OrdersTotal(); i++) 
   { 
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); 
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) 
      { 
         if (OrderType() == OP_BUY) 
          if((Bid>=(OrderOpenPrice()+(profit*Point)))||(Bid<=(OrderOpenPrice()-(lost*Point)))) 
           { OrderClose(OrderTicket(), OrderLots(), Bid,2, Aqua); 
         } }
      } 
   }  

void ZamknijSell() 
{      
   int i; 
    
   for (i = 0; i < OrdersTotal(); i++) 
   { 
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); 
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) 
      { 
         if (OrderType() == OP_SELL) 
         if((Ask<=(OrderOpenPrice()-(profit*Point)))||(Ask>=(OrderOpenPrice()+(lost*Point)))) 
         { OrderClose(OrderTicket(), OrderLots(), Ask,2, Magenta); 
         } }
      } 
   }

void ts(int cmd) 
{ 
   double Point_ = Point; 
   if (Digits==3 || Digits==5) Point_=Point*10; 
   for (int i=0;i<=OrdersTotal();i++) 
   { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES); 
      if (Symbol()==OrderSymbol() && MagicNumber==OrderMagicNumber() && cmd==OrderType() && OrderStopLoss()!=0) 
      { 
         double sl = 0; 
         color  cl; 
         if (OrderType()==OP_BUY) 
         { 
            if (Bid>=OrderOpenPrice()+ActivateTS*Point_) 
            { 
               if (Bid-OrderStopLoss()>=(StepTS)*Point_) 
               { 
                  sl = Bid-StepTS*Point_; 
               } 
            } 
            cl = Blue; 
         } 
         if (OrderType()==OP_SELL ) 
         { 
            if (Ask<=OrderOpenPrice()-ActivateTS*Point_) 
            { 
               if (OrderStopLoss()-Ask>=(StepTS)*Point_) 
               { 
                  sl = Ask+StepTS*Point_; 
               } 
            } 
            cl = Red; 
         } 
         if (sl!=0) 
         { 
            int ticket = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,cl); 
            if (ticket<=0) Print(ErrorDescription(GetLastError())); 
         } 
      } 
   } 
}
Solą życia jest kasa.

ebate
Stały bywalec
Stały bywalec
Posty: 24
Rejestracja: 18 mar 2012, 21:06

Nieprzeczytany post autor: ebate »

Zamykanie działa poprawnie, prawie jak SL. Co zauważyłem, to przy lost=3 raz zamknęło transakcje po 5. Był to szybki spadek ceny, ale jak wcześniej wspomniałeś to normalne, gdyz działa to jak "zamykanie z reki".
Problemem jest Trailing Stop. Nie działa w ogóle.

Awatar użytkownika
personov
Pasjonat
Pasjonat
Posty: 1525
Rejestracja: 09 sie 2009, 21:27

Nieprzeczytany post autor: personov »

Teraz powinien działać TS.
TS działa na zwykłym StopLoss, skoro go wykasowalem to TS nie działał.
Teraz przywróciłem SL i ustaw go sobie zapobiegawczo gdzieś dalej.

Kod: Zaznacz cały

#include <stdlib.mqh> 
int MagicNumber    = 888634; 
extern double lot          = 1; 
extern int    lost           = 3;
extern int    SL            = 20; 
extern int    intensity    = 18; 
extern int    periods      = 800; 
extern bool   TrailingStop = true; 
extern int    ActivateTS   = 1; 
extern int    StepTS       = 10; 
  
int    profit       = 3000; 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void init() 
{} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void deinit() 
{} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void start() 
{ 
   double it1 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,0); 
   double it2 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,1); 
   //trailing stop 
   if (total(OP_BUY )>0 && TrailingStop==true) ts(OP_BUY ); 
   if (total(OP_SELL)>0 && TrailingStop==true) ts(OP_SELL); 
   if(total(OP_BUY)==0&&it1>0&&it2<=0)send(OP_BUY); 
   if(total(OP_SELL)==0&&it1<0&&it2>=0)send(OP_SELL); 

   if (total(OP_BUY)>0)ZamknijBuy(); 
   if (total(OP_SELL)>0)ZamknijSell(); 
} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
int total(int cmd) 
{ 
   int sum=0; 
   for ( int i=0;i<=OrdersTotal();i++) 
   { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES); 
      if (OrderSymbol()==Symbol() && cmd ==OrderType() && MagicNumber==OrderMagicNumber()) sum++; 
   } 
   return(sum); 
} 
/////////////////////////////////////////////////////// 
void send(int cmd) 
{ 
   double Point_ = Point; 
   if (Digits==3 || Digits==5) Point_=Point*10; 
   double tp; 
   double sl; 
   double pr; 
   color cl; 
   if (cmd==OP_BUY) 
   { 
      pr = Ask; 
      tp = 0; 
      sl = Ask-SL*Point_; 
      cl = Blue; 
   } 
   if (cmd==OP_SELL) 
   { 
      pr = Bid; 
      tp = 0; 
      sl = Bid+SL*Point_; 
      cl = Red; 
   } 
   int ticket = OrderSend(Symbol(),cmd,lot,pr,0,sl,tp,"",MagicNumber,0,cl); 
   if (ticket<=0) Print(ErrorDescription(GetLastError())); 
} 
///////////////////////////////////////////////////////////////////////// 
void ZamknijBuy() 
{      
   int i; 
    
   for (i = 0; i < OrdersTotal(); i++) 
   { 
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); 
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) 
      { 
         if (OrderType() == OP_BUY) 
          if((Bid>=(OrderOpenPrice()+(profit*Point)))||(Bid<=(OrderOpenPrice()-(lost*Point)))) 
           { OrderClose(OrderTicket(), OrderLots(), Bid,2, Aqua); 
         } } 
      } 
   }  

void ZamknijSell() 
{      
   int i; 
    
   for (i = 0; i < OrdersTotal(); i++) 
   { 
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); 
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) 
      { 
         if (OrderType() == OP_SELL) 
         if((Ask<=(OrderOpenPrice()-(profit*Point)))||(Ask>=(OrderOpenPrice()+(lost*Point)))) 
         { OrderClose(OrderTicket(), OrderLots(), Ask,2, Magenta); 
         } } 
      } 
   } 

void ts(int cmd) 
{ 
   double Point_ = Point; 
   if (Digits==3 || Digits==5) Point_=Point*10; 
   for (int i=0;i<=OrdersTotal();i++) 
   { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES); 
      if (Symbol()==OrderSymbol() && MagicNumber==OrderMagicNumber() && cmd==OrderType() && OrderStopLoss()!=0) 
      { 
         double sl = 0; 
         color  cl; 
         if (OrderType()==OP_BUY) 
         { 
            if (Bid>=OrderOpenPrice()+ActivateTS*Point_) 
            { 
               if (Bid-OrderStopLoss()>=(StepTS)*Point_) 
               { 
                  sl = Bid-StepTS*Point_; 
               } 
            } 
            cl = Blue; 
         } 
         if (OrderType()==OP_SELL ) 
         { 
            if (Ask<=OrderOpenPrice()-ActivateTS*Point_) 
            { 
               if (OrderStopLoss()-Ask>=(StepTS)*Point_) 
               { 
                  sl = Ask+StepTS*Point_; 
               } 
            } 
            cl = Red; 
         } 
         if (sl!=0) 
         { 
            int ticket = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,cl); 
            if (ticket<=0) Print(ErrorDescription(GetLastError())); 
         } 
      } 
   } 
}
Solą życia jest kasa.

ebate
Stały bywalec
Stały bywalec
Posty: 24
Rejestracja: 18 mar 2012, 21:06

Nieprzeczytany post autor: ebate »

Dzięki za pomoc. Po testach dam znać co i jak.

Dodano po 19 godzinach 59 minutach:

Przez repaint wskaźnika całe testy manualne idą na marne. Nie wiedziałem że ten wskaźnik repaintuje aż tak. Przez to jest dwa razy więcej stratnych transakcji, albo więcej.
Zastanawiam się jak temu zaradzić. Mam na to 2 pomysły. Jeden jest całkiem prosty i dość obiecujący, lecz nie na tyle prosty bym sam mógł go wprowadzić.
Oto fragment kodu, założenia:

Kod: Zaznacz cały

void start()
{
   double it1 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,0);
   double it2 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,1);
   //trailing stop
   if (total(OP_BUY )>0 && TrailingStop==true) ts(OP_BUY );
   if (total(OP_SELL)>0 && TrailingStop==true) ts(OP_SELL);
   if(total(OP_BUY)==0&&it1>0&&it2<=0)send(OP_BUY);
   if(total(OP_SELL)==0&&it1<0&&it2>=0)send(OP_SELL);

   if (total(OP_BUY)>0)ZamknijBuy();
   if (total(OP_SELL)>0)ZamknijSell();
} 
Jak zmienić założenia, żeby np.:
EA otwierał pozycję BUY wtedy, kiedy wysokość żółtego słupka osiągnęłaby określoną wartość np. 0.05. Otwarta pozycja byłaby zamykana jak wcześniej to było, przez TS i SL. Pozycje SELL analogicznie jak BUY. Można to wprowadzić?
Domyślam się, że chodzi o ten kawałek kodu

Kod: Zaznacz cały

   if(total(OP_BUY)==0&&it1>0&&it2<=0)send(OP_BUY);
   if(total(OP_SELL)==0&&it1<0&&it2>=0)send(OP_SELL);
Tylko nie do końca wiem, które zera zmienić na wartość 0.05.
Z góry dziekuje za pomoc.

Awatar użytkownika
personov
Pasjonat
Pasjonat
Posty: 1525
Rejestracja: 09 sie 2009, 21:27

Nieprzeczytany post autor: personov »

Nie mam tego wskaźnika i nie wiem jak on wygląda, ale wydaje mi się, że w tym kawałku kodu zamień wszystkie cztery zera na liczbę jaką chcesz. Np. 0.05

Dodano po 31 minutach:

Dla Sell musisz wpisać -0.05
Solą życia jest kasa.

ebate
Stały bywalec
Stały bywalec
Posty: 24
Rejestracja: 18 mar 2012, 21:06

Nieprzeczytany post autor: ebate »

A jest możliwość, żeby wprowadzić limit otwieranych transakcji na jednej świecy np. max jedna transakcja na jedną świece?

Awatar użytkownika
personov
Pasjonat
Pasjonat
Posty: 1525
Rejestracja: 09 sie 2009, 21:27

Nieprzeczytany post autor: personov »

Blokada jednej pozycji na świecę. Po otwaciu nowej świecy blokada sie odblokowuje.

Kod: Zaznacz cały

#include <stdlib.mqh> 
int MagicNumber    = 888634; 
extern double lot          = 1; 
extern int    lost           = 3; 
extern int    SL            = 20; 
extern int    intensity    = 18; 
extern int    periods      = 800; 
extern bool   TrailingStop = true; 
extern int    ActivateTS   = 1; 
extern int    StepTS       = 10; 
int blokada=0; 
int    profit       = 3000; 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void init() 
{} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void deinit() 
{} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
void start() 
{ 
   double it1 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,0); 
   double it2 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,1); 
   //trailing stop 
   if (total(OP_BUY )>0 && TrailingStop==true) ts(OP_BUY ); 
   if (total(OP_SELL)>0 && TrailingStop==true) ts(OP_SELL);
   if(blokada==1&&isNewBar())blokada=0; 
   if(blokada==0&&total(OP_BUY)==0&&it1>0&&it2<=0){send(OP_BUY);blokada=1;} 
   if(blokada==0&&total(OP_SELL)==0&&it1<0&&it2>=0){send(OP_SELL);blokada=1;} 

   if (total(OP_BUY)>0)ZamknijBuy(); 
   if (total(OP_SELL)>0)ZamknijSell(); 
} 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
int total(int cmd) 
{ 
   int sum=0; 
   for ( int i=0;i<=OrdersTotal();i++) 
   { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES); 
      if (OrderSymbol()==Symbol() && cmd ==OrderType() && MagicNumber==OrderMagicNumber()) sum++; 
   } 
   return(sum); 
} 
/////////////////////////////////////////////////////// 
void send(int cmd) 
{ 
   double Point_ = Point; 
   if (Digits==3 || Digits==5) Point_=Point*10; 
   double tp; 
   double sl; 
   double pr; 
   color cl; 
   if (cmd==OP_BUY) 
   { 
      pr = Ask; 
      tp = 0; 
      sl = Ask-SL*Point_; 
      cl = Blue; 
   } 
   if (cmd==OP_SELL) 
   { 
      pr = Bid; 
      tp = 0; 
      sl = Bid+SL*Point_; 
      cl = Red; 
   } 
   int ticket = OrderSend(Symbol(),cmd,lot,pr,0,sl,tp,"",MagicNumber,0,cl); 
   if (ticket<=0) Print(ErrorDescription(GetLastError())); 
} 
///////////////////////////////////////////////////////////////////////// 
void ZamknijBuy() 
{      
   int i; 
    
   for (i = 0; i < OrdersTotal(); i++) 
   { 
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); 
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) 
      { 
         if (OrderType() == OP_BUY) 
          if((Bid>=(OrderOpenPrice()+(profit*Point)))||(Bid<=(OrderOpenPrice()-(lost*Point)))) 
           { OrderClose(OrderTicket(), OrderLots(), Bid,2, Aqua); 
         } } 
      } 
   }  

void ZamknijSell() 
{      
   int i; 
    
   for (i = 0; i < OrdersTotal(); i++) 
   { 
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); 
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) 
      { 
         if (OrderType() == OP_SELL) 
         if((Ask<=(OrderOpenPrice()-(profit*Point)))||(Ask>=(OrderOpenPrice()+(lost*Point)))) 
         { OrderClose(OrderTicket(), OrderLots(), Ask,2, Magenta); 
         } } 
      } 
   } 

void ts(int cmd) 
{ 
   double Point_ = Point; 
   if (Digits==3 || Digits==5) Point_=Point*10; 
   for (int i=0;i<=OrdersTotal();i++) 
   { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES); 
      if (Symbol()==OrderSymbol() && MagicNumber==OrderMagicNumber() && cmd==OrderType() && OrderStopLoss()!=0) 
      { 
         double sl = 0; 
         color  cl; 
         if (OrderType()==OP_BUY) 
         { 
            if (Bid>=OrderOpenPrice()+ActivateTS*Point_) 
            { 
               if (Bid-OrderStopLoss()>=(StepTS)*Point_) 
               { 
                  sl = Bid-StepTS*Point_; 
               } 
            } 
            cl = Blue; 
         } 
         if (OrderType()==OP_SELL ) 
         { 
            if (Ask<=OrderOpenPrice()-ActivateTS*Point_) 
            { 
               if (OrderStopLoss()-Ask>=(StepTS)*Point_) 
               { 
                  sl = Ask+StepTS*Point_; 
               } 
            } 
            cl = Red; 
         } 
         if (sl!=0) 
         { 
            int ticket = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,cl); 
            if (ticket<=0) Print(ErrorDescription(GetLastError())); 
         } 
      } 
   } 
}
///////////////////////////////////////////////////////////////////////// 
bool isNewBar() { 
 static int prevTime; 
 bool newBar=false; 
 if(Time[0]!=prevTime){ 
 newBar=true; 
 prevTime=Time[0];} 
 return(newBar);}
Solą życia jest kasa.

ebate
Stały bywalec
Stały bywalec
Posty: 24
Rejestracja: 18 mar 2012, 21:06

Nieprzeczytany post autor: ebate »

Mam pewien problem z kodem. Coś jest nie tak z TS. EA otwiera transakcje BUY. TS jest ok. Dalej otwiera SELL, lecz wcześniejsza nie osiągnęła jeszcze poziomu TS. Buy zamyka TS, zaś TS w pierwszej transakcji zmienia wartość tak, jakby była SELL, i bez potrzeby zamyka transakcje. Dodatkowo otwarta transakcja BUY blokuje otwarcie kolejne BUY. Oto kod, którego używam:

Kod: Zaznacz cały

#include <stdlib.mqh>
int MagicNumber    = 888634;
extern double lot          = 1;
extern int    lost           = 200;
extern int    SL            = 200;
extern int    intensity    = 20;
extern int    periods      = 800;
extern bool   TrailingStop = true;
extern int    ActivateTS   = 1;
extern int    StepTS       = 150;
extern string time1Begin    = "12:30";
extern string time1End      = "14:00";   
 
int    profit       = 3000;
///////////////////////////////////////////////////////////////////////////////////////////////////
void init()
{}
///////////////////////////////////////////////////////////////////////////////////////////////////
void deinit()
{}
///////////////////////////////////////////////////////////////////////////////////////////////////
void start()
{
   double it1 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,0);
   double it2 = iCustom(Symbol(),Period(),"freescalpingindicator",intensity,periods,0,1);
   //trailing stop
   if (total(OP_BUY )>0 && TrailingStop==true) ts(OP_BUY );
   if (total(OP_SELL)>0 && TrailingStop==true) ts(OP_SELL);
   if (isTradingTime()==true&&total(OP_BUY)==0&&it1>0&&it2<=0)send(OP_BUY);
   if (isTradingTime()==true&&total(OP_SELL)==0&&it1<0&&it2>=0)send(OP_SELL);

   if (total(OP_BUY)>0)ZamknijBuy();
   if (total(OP_SELL)>0)ZamknijSell();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
int total(int cmd)
{
   int sum=0;
   for ( int i=0;i<=OrdersTotal();i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol()==Symbol() && cmd ==OrderType() && MagicNumber==OrderMagicNumber()) sum++;
   }
   return(sum);
}
///////////////////////////////////////////////////////
void send(int cmd)
{
   double Point_ = Point;
   if (Digits==3 || Digits==5) Point_=Point*10;
   double tp;
   double sl;
   double pr;
   color cl;
   if (cmd==OP_BUY)
   {
      pr = Ask;
      tp = 0;
      sl = Ask-SL*Point_;
      cl = Blue;
   }
   if (cmd==OP_SELL)
   {
      pr = Bid;
      tp = 0;
      sl = Bid+SL*Point_;
      cl = Red;
   }
   int ticket = OrderSend(Symbol(),cmd,lot,pr,0,sl,tp,"",MagicNumber,0,cl);
   if (ticket<=0) Print(ErrorDescription(GetLastError()));
}
/////////////////////////////////////////////////////////////////////////
void ZamknijBuy()
{     
   int i;
   
   for (i = 0; i < OrdersTotal(); i++)
   {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
      {
         if (OrderType() == OP_BUY)
          if((Bid>=(OrderOpenPrice()+(profit*Point)))||(Bid<=(OrderOpenPrice()-(lost*Point))))
           { OrderClose(OrderTicket(), OrderLots(), Bid,2, Aqua);
         } }
      }
   } 

void ZamknijSell()
{     
   int i;
   
   for (i = 0; i < OrdersTotal(); i++)
   {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
      {
         if (OrderType() == OP_SELL)
         if((Ask<=(OrderOpenPrice()-(profit*Point)))||(Ask>=(OrderOpenPrice()+(lost*Point))))
         { OrderClose(OrderTicket(), OrderLots(), Ask,2, Magenta);
         } }
      }
   }

void ts(int cmd)
{
   double Point_ = Point;
   if (Digits==3 || Digits==5) Point_=Point*10;
   for (int i=0;i<=OrdersTotal();i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if (Symbol()==OrderSymbol() && MagicNumber==OrderMagicNumber() && cmd==OrderType() && OrderStopLoss()!=0)
      {
         double sl = 0;
         color  cl;
         if (OrderType()==OP_BUY)
         {
            if (Bid>=OrderOpenPrice()+ActivateTS*Point_)
            {
               if (Bid-OrderStopLoss()>=(StepTS)*Point_)
               {
                  sl = Bid-StepTS*Point_;
               }
            }
            cl = Blue;
         }
         if (OrderType()==OP_SELL )
         {
            if (Ask<=OrderOpenPrice()-ActivateTS*Point_)
            {
               if (OrderStopLoss()-Ask>=(StepTS)*Point_)
               {
                  sl = Ask+StepTS*Point_;
               }
            }
            cl = Red;
         }
         if (sl!=0)
         {
            int ticket = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,cl);
            if (ticket<=0) Print(ErrorDescription(GetLastError()));
         }
      }
   }
}
///////////////////////////////////////////////////////////////////////
bool isTradingTime() {
    if(TimeCurrent()>StrToTime(time1Begin) && TimeCurrent()<StrToTime(time1End)) {
        return(true);}
       return(false);}
Zgodnie z kodem transakcje będą zawierane między 12:30 a 14:00. I tu EA działa poprawnie. Zgodnie z założeniami, posiłkując się zdjęciem, EA powinien zawrzeć 4 transakcje. Pierwsza buy jest zawarta, sell również, lecz chyba przez niezamkniętą buy następna buy nie jest otwarta. Dlaczego? Drugą nieprawidłowością jest TS. Mam go ustawionego na 150. Coś TS szaleje, jest to pokazane na drugim zdjęciu. Poza tym TS przyjmuje wartość 200, jak SL a nie 150 jak wpisałem.
Proszę o pomoc.
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.

Awatar użytkownika
personov
Pasjonat
Pasjonat
Posty: 1525
Rejestracja: 09 sie 2009, 21:27

Nieprzeczytany post autor: personov »

TS to StopLost, ktory kroczy za aktualną ceną , a nie za ceną otwarcia.
Jeśli profit przkroczył 1 ustawiony pips to przeskakuje na 150 pipsów za ceną i idzie dalej.
Jeśli jest otwarte zlecenie BUY to nie otworzy kolejnego dopóki tego nie zamknie.
Jest warunek : jeśli waunek dla buy jest spełniony i jeśli nie ma już otwartej pozycji buy - wtedy otwieraj BUY.
Jeśli zabierzemy zapis "jeśli nie ma już otwartej pozycji buy " to będzie otwierane BUY na każdej świecy . Bo warunek będzie spełniony.
Jeśli chciałbyś otwierać pozycję na każdym sygnale nizależnie od tego, czy będzie to już drugie buy, czy trzecie - to trzeba użyć innych sztuczek.
Solą życia jest kasa.

ODPOWIEDZ