TRIX 값 읽어오기
- SEAN
- 3,038
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[];
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;
for(i=0; i
for(i=0; i
============== 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
코멘트 (2)
인디케이터가 있다면 iCustom으로 바로 TRIX인디값을 가져오는게 좋을거 같습니다.
답변 감사 합니다.
iCustom 으로 불러봤는데, 잘 안되네요.
혹시 제 소스좀 봐주실수 있을까요?
============ 인디 케이터 ======================
//+------------------------------------------------------------------+
//| TRIX.mq4 |
//| by Raff |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, raff1410@o2.pl"
#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
extern int TRIX_Period = 4;
extern int Signal_Period = 8;
extern bool Signals = true;
extern int CountBars = 750;
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double ind_buffer5[];
double ind_buffer6[];
double ind_buffer7[];
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);
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");
return(0);
}
//+------------------------------------------------------------------+
//| TRIX |
//+------------------------------------------------------------------+
int start()
{
if (TRIX_Period==Signal_Period) return(0);
int i, limit=CountBars;
if (limit>Bars) limit=Bars-1;
for(i=0; i
for(i=0; i
//---- signals
/*
i=limit-1;
while(i>=0)
{
if (Signals==true)
{
if (ind_buffer2[i]
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);
}
//| 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_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"
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;
extern int TimeFrame = 0;
extern int TRIX_Period = 4;
extern int Signal_Period = 8;
extern bool Signals = true;
extern int CountBars = 750;
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double ind_buffer5[];
double ind_buffer6[];
double ind_buffer7[];
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start() {
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
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);
}
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 |
//+------------------------------------------------------------------+
bool IsTrade = False;
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+
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) |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+
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) |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+
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 (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
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);
}
}
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 (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
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);
}
}
*/
return(0);
}
//+------------------------------------------------------------------+