Kod: Zaznacz cały
extern int profit = 2;
extern int lost = 5;
///////////////////////////////////////////
if (total(OP_BUY)>0)ZamknijBuy();
if (total(OP_SELL)>0)ZamknijSell();
//////////////////////////////////////////////////////////////
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);
} }
}
}
Próbuję tak :
Kod: Zaznacz cały
void ZamknijBuy()
{
double profit1 = ((Close[1]-Open[1])/2);
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()+profit1))||(Bid<=(OrderOpenPrice()-(lost*Point))))
{ OrderClose(OrderTicket(), OrderLots(), Bid,2, Aqua);
} }
}
}
void ZamknijSell()
{
double profit2 = ((Open[1]-Close[1])/2);
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()-profit2))||(Ask>=(OrderOpenPrice()+(lost*Point))))
{ OrderClose(OrderTicket(), OrderLots(), Ask,2, Magenta);
} }
}
}
Powidzcie mi : czy wogóle w funkcji "void" mogę wpisywać coś w rodzaju Close[1] czy Open[2] ?
Dodano po 26 minutach:
Już wiem. Po otwarciu zlecenia mija kilka świec i ta wartość jest już inna niż w momencia otwarcia. Bywa nawet, że Open - Close wychodzi ujemne i dlatego zamyka na minusie.
W takim razie zmieniam pytanie :
Jak zrobić, żeby wartość "profit" była zczytywana i zapamietywana w momencie skaładania zlecenia i z taka wartością zamykało zlecenie.