Отправлено 10 January 2012 - 14:49
Добрый день! Помогите пожалуйста добавить функцию для открытия OP_SELLLIMIT и OP_BUYLIMIT .Хотел сам .но уже неделю борюсь и ни каких результатов!
Заранее огромная БЛАГОДАРНОСТЬ!
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
void start()
{
if (!IsTradeAllowed()) return;
static int Trade=0;
static double LastPrice=0.0;
if (Trade==1 && LastPrice<=Ask-nextpos*pnt)
{
LastPrice=Ask;
NewOrder(OP_BUYSTOP,lot,LastPrice+nextpos*pnt,LastPrice*pnt,LastPrice+(nextpos+takeprofit)*pnt);
return;
}
if (Trade==2 && LastPrice>=Bid+nextpos*pnt)
{
LastPrice=Bid;
NewOrder(OP_SELLSTOP,lot,LastPrice-nextpos*pnt,LastPrice+stoploss*pnt,LastPrice-(nextpos+takeprofit)*pnt);
return;
}
for (int i=OrdersTotal()-1; i>=0; i--)
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if (OrderType()==OP_BUY)
{
if (NormalizeDouble(LastPrice-stoploss*pnt,Digits)>NormalizeDouble(OrderStopLoss(),Digits)
&& Bid>=LastPrice) SetStop(LastPrice-stoploss*pnt);
return;
}
if (OrderType()==OP_SELL)
{
if (NormalizeDouble(LastPrice+stoploss*pnt,Digits)<NormalizeDouble(OrderStopLoss(),Digits)
&& Ask<=LastPrice) SetStop(LastPrice+stoploss*pnt);
return;
}
}
static datetime FixTime=0;
if (Time[0]==FixTime) return;
FixTime=Time[0];
for (i=OrdersTotal()-1; i>=0; i--)
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic
&& (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)) DelOrder();
Trade=0;
double iRegr=iCustom(NULL,0,"i-Regr",degree,ksdt,bars,shift,2,1);
if (High[1]>iRegr+kick*pnt && Low[1]<iRegr-kick*pnt)
{
LastPrice=Ask;
NewOrder(OP_BUY,lot,LastPrice,LastPrice-stoploss*pnt,LastPrice+takeprofit*pnt);
NewOrder(OP_BUYSTOP,lot,LastPrice+nextpos*pnt,LastPrice-stoploss*pnt,LastPrice+(nextpos+takeprofit)*pnt);
NewOrder(OP_BUYLIMIT,lot,LastPrice-nextpos*pnt,LastPrice-stoploss*pnt,LastPrice-(nextpos-takeprofit)*pnt);
Trade=1;
return;
}
iRegr=iCustom(NULL,0,"i-Regr",degree,ksdt,bars,shift,1,1);
if (High[1]>iRegr+kick*pnt && Low[1]<iRegr-kick*pnt)
{
LastPrice=Bid;
NewOrder(OP_SELL,lot,LastPrice,LastPrice+stoploss*pnt,LastPrice-takeprofit*pnt);
NewOrder(OP_SELLSTOP,lot,LastPrice-nextpos*pnt,LastPrice+stoploss*pnt,LastPrice-(nextpos+takeprofit)*pnt);
NewOrder(OP_SELLLIMIT,lot,LastPrice+nextpos*pnt,LastPrice+stoploss*pnt,LastPrice+(nextpos-takeprofit)*pnt);
Trade=2;
return;
}
}
//+------------------------------------------------------------------+