...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()));
}
}
}
}