EA dla RSI

O jezykach programowania w platformach i nie tylko.
grzechu0071
Uczestnik
Uczestnik
Posty: 1
Rejestracja: 20 lip 2011, 20:17

EA dla RSI

Nieprzeczytany post autor: grzechu0071 »

Witam wszystkich,

mam problem z EA dla RSI.

Warunkiem otwarcia pozycji jest przecięcie poziomu Rsi 50, w górę pozycja kup, a w dół pozycja sprzedaj. EA ma zamykać też pozycję w odwrotnych warunkach.
Zmodyfikowałem EA przykładowe dla Moving Average tak żeby działało pod Rsi, problem pojawia się w testerze strategii. A dokładnie to otwiera tylko pozycję Buy, nie otwiera Sell, no i nie zamyka też automatycznie pozycji przy spełnionych warunkach.
Dodam też, że EA ma działać tylko w określonych godzinach, teraz jest wpisane od 8 rano do 18.

Pomóżcie co jest nie tak w tym kodzie.

Poniżej kod:

Kod: Zaznacz cały

//+------------------------------------------------------------------+
#define MAGICMA  20050610


extern double TakeProfit = 41;
extern double Lots = 0.01;
extern double StopLoss = 11;
extern int RSIPeriod = 14;

//+------------------------------------------------------------------+
//| 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                                       |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
if(Hour()>7&&Hour()<18)
  {
   double ma;
   double RsiPrevious, RsiCurrent; 
   int cnt, ticket, total, limit;
   int    res;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
        for(int n = 0; n < limit; n++)
        RsiPrevious = iRSI(NULL, 0, RSIPeriod, PRICE_OPEN, n + 1);
        RsiCurrent = iRSI(NULL, 0, RSIPeriod, PRICE_OPEN, n);
//---- sell conditions
   if(RsiPrevious > 50 && RsiCurrent < 50)  
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Blue);
      return;
     }
//---- buy conditions
   if(RsiPrevious < 50 && RsiCurrent > 50)  
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Red);
      return;
     }     
//----
  }
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
   double RsiPrevious, RsiCurrent; 
   int cnt, ticket, total, limit;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
        for(int n = 0; n < limit; n++)
        RsiPrevious = iRSI(NULL, 0, RSIPeriod, PRICE_OPEN, n + 1);
        RsiCurrent = iRSI(NULL, 0, RSIPeriod, PRICE_OPEN, n);
//----
   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(RsiPrevious > 50 && RsiCurrent < 50) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(RsiPrevious < 50 && RsiCurrent > 50) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         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())==0) CheckForOpen();
   else                                    CheckForClose();
//----
  }
//+------------------------------------------------------------------+[
Pozdrawiam

ODPOWIEDZ