Подскажите пожалуйста, где ошибка в коде
//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| _http://www.metaquotes.net MetaTrader 5 Trading Platform / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//---- input parameters
extern double TakeProfit=10.0;
extern double StopLoss=20.0;
extern double DecreaseFactor =3;
extern double Lots =0.1;
extern double MovingShift =1;
extern double MaximumRisk =0.02;
extern int MovingPeriod1=11;
extern int MovingPeriod2=21;
double SL,TP;
double ma1,ma2,ma3,ma4;
int res;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//| Функция расчета оптимального размера лота |
//+------------------------------------------------------------------+
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//---- calculate number of losses orders without a break
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{ Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
}
//---- return lot size
if(lot<0.1) lot=0.1;
return(lot);
//жжжжжжжжжжжж Функция открытия позиций жжжжжжжжжжжжжжжжжжжжжжжжжжжжж+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double ma1,ma2,ma3,ma4;int res;
//---- get Moving Average
ma1==iMA(NULL,0,MovingPeriod1,MovingShift,MODE_SMA,PRICE_CLOSE,0);
ma2==iMA(NULL,0,MovingPeriod1,MovingShift,MODE_SMA,PRICE_CLOSE,1);
ma3==iMA(NULL,0,MovingPeriod2,MovingShift,MODE_SMA,PRICE_CLOSE,0);
ma4==iMA(NULL,0,MovingPeriod2,MovingShift,MODE_SMA,PRICE_CLOSE,1);
//---- go trading only for first tiks of new bar
if(Volume[0]>1), return(0);
{
//---- sell conditions
if(ma2>ma3&&ma1==ma3)
{
SL=0;TP=0;
if(StopLoss>0) SL=Bid+Point*StopLoss;
if(TakeProfit>0) TP=Bid-Point*TakeProfit;
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(), Bid,3,SL,TP,"Moving Average",0,0,Red);
if(res<0)
{
Print("Ошибка открытия ордера SELL #",GetLastError());
Sleep(10000); return(0);
}
}
//---- buy conditions
if( ma4<ma1&& ma3==ma1)
{
SL=0;TP=0;
if(StopLoss>0) SL=Ask-Point*StopLoss;
if(TakeProfit>0) TP=Ask+Point*TakeProfit;
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,SL,TP,"Moving Average",0,0,Blue);
if(res<0)
{
Print("Ошибка открытия ордера BUY #",GetLastError());
Sleep(10000); return(0);
}
}
}
//----
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
void start()
{
//(если на графике есть более 100 баров и торговый поток свободен)
if(Bars<100 || IsTradeAllowed()==false) return;
CheckForOpen();
}