TRIX 값 읽어오기

  • SEAN
  • 3,041

TRIX를 이용해서 EA를 만들려고 하고 있습니다.

Trix 인디케이터에서 Trix값을 읽어오는 방법을 그대로 EA에 적용시켰는데.
값이 나오질 않습니다.

 

============== 인디케이터=========================

//---- indicator parameters
extern int  TRIX_Period     = 4;
extern int  Signal_Period = 8;
extern bool Signals      = true;
extern int  CountBars    = 1500;


//---- indicator buffers
double      ind_buffer1[];
double      ind_buffer2[];
double      ind_buffer3[];
double      ind_buffer4[];
double      ind_buffer5[];
double      ind_buffer6[];
double      ind_buffer7[];

//---- indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);
   SetIndexBuffer(3,ind_buffer4);
   SetIndexBuffer(4,ind_buffer5);
   SetIndexBuffer(5,ind_buffer6);
   SetIndexBuffer(6,ind_buffer7);

   int i, limit=CountBars;
   if (limit>Bars) limit=Bars-1;
//---- trix
   for(i=0; i    for(i=0; i    for(i=0; i   
   for(i=0; i    for(i=0; i    for(i=0; i
   Alert("Trix: ", ind_buffer1[0]*10000," | ", ind_buffer1[1]*10000," | ", ind_buffer1[2]*10000," | ", ind_buffer1[3]*10000," : ", TimeToStr(CurTime(),TIME_SECONDS));

 

============== EA =========================
//---- indicator buffers
double ind_buffer1[10];
double ind_buffer2[10];
double ind_buffer3[10];
double ind_buffer4[10];
double ind_buffer5[10];
double ind_buffer6[10];
double ind_buffer7[10];


int i, limit=4;

for(i=0; i for(i=0; i for(i=0; i
for(i=0; i for(i=0; i for(i=0; i

Alert("EA: ", ind_buffer1[0]*10000," | ", ind_buffer1[1]*10000," | ", ind_buffer1[2]*10000," | ", ind_buffer1[3]*10000," : ", TimeToStr(CurTime(),TIME_SECONDS));
 
=====================================================
 
두개를 돌려보면 Alert가 인디케이터에서는 제데로 나오는데, EA에서는 -400으로 나오네요.
 
뭐가 잘못된것일까요?
배열 선언을 잘못한것일까요?
 
혹시 아시는분, 도움 부탁 드립니다.
 

 

Comment (2)

블루아이

인디케이터가 있다면 iCustom으로 바로 TRIX인디값을 가져오는게 좋을거 같습니다.


SEAN

답변 감사 합니다.

iCustom 으로 불러봤는데, 잘 안되네요.

혹시 제 소스좀 봐주실수 있을까요?

============ 인디 케이터 ======================

//+------------------------------------------------------------------+
//|                                                         TRIX.mq4 |
//|                                                          by Raff |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, raff1410@o2.pl"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1 Red
#property  indicator_color2 DeepSkyBlue
#property  indicator_color3 Yellow
#property  indicator_color4 Aqua
#property  indicator_color5 DarkGray
#property  indicator_color6 DarkGray
#property  indicator_width1 2
#property  indicator_width2 2
#property  indicator_width3 0
#property  indicator_width4 0
#property  indicator_width5 1
#property  indicator_width6 1
#property  indicator_style1 STYLE_SOLID
#property  indicator_style2 STYLE_DOT
#property  indicator_style3 STYLE_SOLID
#property  indicator_style4 STYLE_SOLID
#property  indicator_style5 STYLE_SOLID
#property  indicator_style6 STYLE_SOLID

#property  indicator_level1 0
//---- indicator parameters
extern int  TRIX_Period     = 4;
extern int  Signal_Period = 8;
extern bool Signals      = true;
extern int  CountBars    = 750;
//---- indicator buffers
double      ind_buffer1[];
double      ind_buffer2[];
double      ind_buffer3[];
double      ind_buffer4[];
double      ind_buffer5[];
double      ind_buffer6[];
double      ind_buffer7[];
//---- variables
static bool TurnedUp = false;
static bool TurnedDown = false; 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorBuffers(7);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,233);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,234);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_HISTOGRAM);
//---- indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);
   SetIndexBuffer(3,ind_buffer4);
   SetIndexBuffer(4,ind_buffer5);
   SetIndexBuffer(5,ind_buffer6);
   SetIndexBuffer(6,ind_buffer7);
  
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("TRIX index | Period: "+TRIX_Period+", Signal Period: "+Signal_Period+" | ");
   SetIndexLabel(0,"TRIX");
   SetIndexLabel(1,"Signal");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| TRIX                                                             |
//+------------------------------------------------------------------+
int start()
  {
   if (TRIX_Period==Signal_Period) return(0);
  
   int i, limit=CountBars;
   if (limit>Bars) limit=Bars-1;
//---- trix
   for(i=0; i    for(i=0; i    for(i=0; i   
   for(i=0; i    for(i=0; i    for(i=0; i
   Alert("Trix: ", ind_buffer1[0]*10000," | ", ind_buffer1[1]*10000," | ", ind_buffer1[2]*10000," | ", ind_buffer1[3]*10000," : ", TimeToStr(CurTime(),TIME_SECONDS));
//---- signals
/*
   i=limit-1;
   while(i>=0)
   {
     if (Signals==true)
     {
     if (ind_buffer2[i]=ind_buffer1[i+1]) ind_buffer3[i]=ind_buffer2[i]-0.0001;
     if (ind_buffer2[i]>ind_buffer1[i] && ind_buffer2[i+1]<=ind_buffer1[i+1]) ind_buffer4[i]=ind_buffer2[i]+0.0001;
    
     if (ind_buffer3[0]==ind_buffer2[0]-0.0001 && TurnedUp==false)
        { 
              Alert("Trix Buy:  ",Symbol()," - ",Period(),"  at  ", Close[0],"  -  ", TimeToStr(CurTime(),TIME_SECONDS));
              TurnedDown = false;
              TurnedUp = true;
        }
     if (ind_buffer4[0]==ind_buffer2[0]+0.0001 && TurnedDown==false)
        { 
              Alert("Trix SELL:  ",Symbol()," - ",Period(),"  at  ", Close[0],"  -  ", TimeToStr(CurTime(),TIME_SECONDS));
              TurnedUp = false;
              TurnedDown = true;
        }
     }
   i--;
   }
   */
//---- done
   return(0);
  }
 
 
====================== EA ======================
//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+
#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#property copyright "Expert Advisor Builder"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"
extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = True;
extern double Lots = 1.0;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 30;
extern bool UseTakeProfit = True;
extern int TakeProfit = 60;
extern bool UseTrailingStop = True;
extern int TrailingStop = 30;
//---- sub indicator parameters
extern int  TimeFrame      = 0;
extern int  TRIX_Period     = 4;
extern int  Signal_Period = 8;
extern bool Signals      = true;
extern int  CountBars    = 750;
//---- indicator buffers
double      ind_buffer1[];
double      ind_buffer2[];
double      ind_buffer3[];
double      ind_buffer4[];
double      ind_buffer5[];
double      ind_buffer6[];
double      ind_buffer7[];
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;
   if (EachTickMode) Current = 0; else Current = 1;
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;
 
   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;
   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+

   datetime TimeArray[];
   int   i, y=0;
//   int   counted_bars=IndicatorCounted();
   
// Plot defined timeframe on to current timeframe  
//   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
  
   for(i=0,y=0;i<750;i++)
   {
   y++; 
  
   ind_buffer1[i]=iCustom(NULL,TimeFrame,"myTrix",TRIX_Period,Signal_Period,Signals,CountBars,0,y);
   ind_buffer2[i]=iCustom(NULL,TimeFrame,"myTrix",TRIX_Period,Signal_Period,Signals,CountBars,1,y);
   ind_buffer3[i]=iCustom(NULL,TimeFrame,"myTrix",TRIX_Period,Signal_Period,Signals,CountBars,2,y);
   ind_buffer4[i]=iCustom(NULL,TimeFrame,"myTrix",TRIX_Period,Signal_Period,Signals,CountBars,3,y);
   ind_buffer5[i]=iCustom(NULL,TimeFrame,"myTrix",TRIX_Period,Signal_Period,Signals,CountBars,4,y);
   ind_buffer6[i]=iCustom(NULL,TimeFrame,"myTrix",TRIX_Period,Signal_Period,Signals,CountBars,5,y);
   ind_buffer7[i]=iCustom(NULL,TimeFrame,"myTrix",TRIX_Period,Signal_Period,Signals,CountBars,6,y);
   }
//---- trix
   Alert("EA : ", ind_buffer1[0]*10000," | ", ind_buffer1[1]*10000," | ", ind_buffer1[2]*10000," | ", ind_buffer1[3]*10000," : ", TimeToStr(CurTime(),TIME_SECONDS));
//   Alert("EA : ", ind_buffer2[0]*10000," | ", ind_buffer2[1]*10000," | ", ind_buffer2[2]*10000," | ", ind_buffer2[3]*10000," : ", TimeToStr(CurTime(),TIME_SECONDS));
//   Alert("EA: ", ind_buffer3[0]*10000," | ", ind_buffer3[1]*10000," | ", ind_buffer3[2]*10000," | ", ind_buffer3[3]*10000," : ", TimeToStr(CurTime(),TIME_SECONDS));
//---- signals
/*
  
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+
   //Check position
   bool IsTrade = False;
   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close
            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+
                     if (CloseBuy1_1 == CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+
            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close
            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+
                     if (CloseSell1_1 == CloseSell1_2) Order = SIGNAL_CLOSESELL;

            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+
            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }
   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
   if (Buy1_1 == Buy1_2) Order = SIGNAL_BUY;
   if (Sell1_1 == Sell1_2) Order = SIGNAL_SELL;

   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+
   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }
         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
   } else {
    Print("Error opening BUY order : ", GetLastError());
   }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }
   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }
         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
   } else {
    Print("Error opening SELL order : ", GetLastError());
   }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }
   if (!EachTickMode) BarCount = Bars;
*/
   return(0);
}
//+------------------------------------------------------------------+