пожалйста помогите

 

Здравствуйте!

Я начинающий в программировании и пытаюсь сделать советник при определённых условиях открывающий 2 противоположных ордера. С помощью какой функции можно это сделать?

Может быть я кого то рассмешу но всё таки рискну. красным Выделенный текст - моя попытка это сделать:


#define MAGICMA 0


extern double sl = 2;
extern double StopLoss = 20;
extern double TakeProfit = 200;
extern double Lots = 0.1;
extern double MaximumRisk = 0.02;
extern double MovingPeriod = 21;
extern double MovingShift = 1;
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double LotsOptimized()
{
double lot=Lots;
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//---- return lot size
if(lot<0.1) lot=0.1;
return(lot);
}
//+------------------------------------------------------------------+
//| Check for open sell conditions |
//+------------------------------------------------------------------+
bool Open_S()
{
if(OrderType()==0)
return (true);
if(OrderType()==1)
return (false);
}

//+------------------------------------------------------------------+
//| Check for open buy conditions |
//+------------------------------------------------------------------+
bool Open_B()
{
if(OrderType()==1)
return (true);
if(OrderType()==0)
return (false);
}

//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double ma;
int res;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
if(Bid<ma && (Open_S()==true))
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
return;
}
//---- buy conditions
if(Ask>ma && (Open_B()==true))
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
return;
}
//----
}
//+------------------------------------------------------------------+
//| Check for Modify order conditions |
//+------------------------------------------------------------------+
void CheckForModify()
{
double ma;
double SL;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if((Ask-OrderOpenPrice())>StopLoss*Point)
{
OrderModify(OrderTicket(),0,ma+sl*Point,OrderTakeProfit(),0,0);
break;
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Bid)>StopLoss*Point)
{
OrderModify(OrderTicket(),0,ma-sl*Point,OrderTakeProfit(),0,0);
break;
}
}
}
//----
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())<=1) CheckForOpen(); Первоначально было ==0
else CheckForModify();
//----
}
//+------------------------------------------------------------------+