[Помогите написать советник, я новичок в MQL и плохо все понимаю. Буду очень признателен. Советник на основании RSI. ] Советник - страница 5

 
extern double TakeProfit=20;
extern double StopLoss = 300;
extern int    Periud   = 14;
 
PAVEL10:
r772ra Не работает у меня, на тесте работает а так нет, смайлик улыбается. А у вас работает?

А если так попробовать:

//+------------------------------------------------------------------+
//|                                                        e_RSI.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern int Magic = 2012;
extern double TakeProfit=200;
extern double StopLoss = 300;
extern int    Periud   = 11;
int total;                                                // Крличество открытых ордеров 
int gi_BUY, gi_SELL;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
      total = openPositions();                                 // Общее количество ордеров
    if (total == 2) return;                                  // Уже открыты оба ордера
//----
    double RSI_0 = iRSI (NULL, 0, Periud, PRICE_CLOSE, 0);
    double RSI_ 1= iRSI (NULL, 0, Periud, PRICE_CLOSE, 1);
  
    if (gi_BUY == 0)
    {
        if (RSI_0 > 30 && RSI_1 < 30)
        {OrderSend (Symbol(),OP_BUY,0.1, NormalizeDouble (Ask, Digits), 3, NormalizeDouble (Bid-StopLoss*Point, Digits),
         NormalizeDouble (Ask+TakeProfit*Point, Digits), "", Magic);}
    }
    else if (gi_SELL == 0)
    {
        if (RSI_0 < 70 && RSI_1 > 70)
        {OrderSend (Symbol(),OP_SELL,0.1,NormalizeDouble (Bid, Digits),3, NormalizeDouble (Ask+StopLoss*Point, Digits),
         NormalizeDouble (Bid-TakeProfit*Point, Digits), "", Magic);}
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+
int openPositions()
{
    int li_ord = 0;
    gi_BUY = 0;
    gi_SELL = 0;
    for (int i = OrdersTotal() - 1; i >= 0; i--)                                // scan all orders and positions...
    {
        if (!OrderSelect (i, SELECT_BY_POS, MODE_TRADES)) continue;
        if (OrderMagicNumber() != Magic) continue;
        if (OrderSymbol() != Symbol()) continue;
        if (OrderType() > 1) continue;
        if (OrderType() == OP_BUY) gi_BUY++;
        if (OrderType() == OP_SELL) gi_SELL++;
        li_ord++;
    } 
    return (li_ord);
}

Могу предположить, что на счёте Вы используете одновременно несколько советников.

 
Для пробы конечно, но другие работают...
 
extern int Magic = 2012;
extern double TakeProfit=200;
extern double StopLoss = 300;
extern int    Periud   = 11;
int total;                                                // Крличество открытых ордеров 
int gi_BUY, gi_SELL;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
      total = openPositions();                                 // Общее количество ордеров
    if (total == 2) return;                                  // Уже открыты оба ордера
//----
    double RSI_0 = iRSI (NULL, 0, Periud, PRICE_CLOSE, 0);
    double RSI_1 = iRSI (NULL, 0, Periud, PRICE_CLOSE, 1);
  
   
     if (gi_BUY == 0)
    {
        if (RSI_0 > 30 && RSI_1 < 30)
        {OrderSend (Symbol(),OP_BUY,0.1, NormalizeDouble (Ask, Digits), 3, NormalizeDouble (Bid-StopLoss*Point, Digits),
         NormalizeDouble (Ask+TakeProfit*Point, Digits), "", Magic);}
    else if (gi_SELL == 0)
    {
        if (RSI_0 < 70 && RSI_1 > 70)
        {OrderSend (Symbol(),OP_SELL,0.1,NormalizeDouble (Bid, Digits),3, NormalizeDouble (Ask+StopLoss*Point, Digits),
         NormalizeDouble (Bid-TakeProfit*Point, Digits), "", Magic);}
    }

   return(0);
  }
  //+------------------------------------------------------------------+
Ошибку выдает (62,1)
 
PAVEL10:
Ошибку выдает (62,1)

А где в Вашем коде функция:

int openPositions()

???

Держите код.

Файлы:
new.mq4  3 kb
 
Спасибо!
Причина обращения: