Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information
I have a simple Custom Indicator with no externs called #TestIndicator that fills 8 buffers with the number 1.0 but when I bring back the buffers in my EA the buffer results are always 0 . Can you help me with this.
EA Code
Code:
double test4_up[];
double test4_down[];
double test3_up[];
double test3_down[];
double test2_up[];
double test2_down[];
double test1_up[];
double test1_down[];
int UniqueNum = 009;
..
..
...
......
..
int i=0;
int limit=Bars-counted_bars;
ArrayResize(test4_up, limit);
ArrayResize(test4_down, limit);
for(i=0;i<limit;i++)
{
test4_up[i] = iCustom(NULL, 0, "#TestIndicator",0,i);
test4_down[i] = iCustom(NULL, 0, "#TestIndicator",1,i);
}
for(i=0;i<30;i++)
{
Print("Test 4 UP ", test4_up[i]," Bar ",i );
Print("Test 4 DOWN ", test4_down[i]," Bar ",i );
//Print("This is a test");
}
//----
return(0);
}
//+---------
Depending how your going to access your data you donot have to refill the array on each tick just like you dont have to recalculate indicators. see
bool ArraySetAsSeries(double&array[], bool set)Sets indexing direction of the array. If the set parameter has the TRUE value, the array will be indexed in a reversed order, i.e., the last element has a zero index. The FALSE value sets a standard indexing order. The function returns the previous status.
You are trying to use features that are meant to be used exclusively from an indicator.
IndicatorCounted() has no meaning at all when called from an EA. It always returns -1 when called within EA code. Try using a constant instead (like in your second loop) or Bars (if you want the whole history).
Also, arrays used within EA should be sized, initialized and the whole work that normally metatrader does when it comes to indicators and buffers within indicators. EA does not have an equivalent of SetIndexBuffer() that is used in indicators. You are having uninitialized arrays in your Ea and only metatrader prevented your EA from crashing the platform (it always returns 0 in those cases, since the element value you are trying to read does not exist, and in fact, those arrays do not exist (they are just declared, not allocated, initialized,...))
regards
mladen
Quote:
Originally Posted by Xaun
I have a simple Custom Indicator with no externs called #TestIndicator that fills 8 buffers with the number 1.0 but when I bring back the buffers in my EA the buffer results are always 0 . Can you help me with this.
#TestIndicator
Code:
#property indicator_chart_window
#property indicator_buffers 8
double buf4_up[];
double buf4_down[];
double buf3_up[];
double buf3_down[];
double buf2_up[];
double buf2_down[];
double buf1_up[];
double buf1_down[];
int UniqueNum = 0070;
string shortname = "";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
shortname = "#TFX";
IndicatorBuffers(8);
IndicatorShortName(shortname);
//---- indicators
SetIndexBuffer(0,buf4_up);
SetIndexBuffer(1,buf4_down);
SetIndexBuffer(2,buf3_up);
SetIndexBuffer(3,buf3_down);
SetIndexBuffer(4,buf2_up);
SetIndexBuffer(5,buf2_down);
SetIndexBuffer(6,buf1_up);
SetIndexBuffer(7,buf1_down);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
//---- the last calculated bar will be recalculated
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars - 1;
//---- the main cycle
for(int i = limit; i >= 0; i--)
{
//----
buf4_up[i]=1.0;
buf4_down[i]=1.0;
buf3_up[i]=1.0;
buf3_down[i]=1.0;
buf2_up[i]=1.0;
buf2_down[i]=1.0;
buf1_up[i]=1.0;
buf1_down[i]=1.0;
}
//----
//----
//----
return(0);
}
//+------------------
EA Code
Code:
double test4_up[];
double test4_down[];
double test3_up[];
double test3_down[];
double test2_up[];
double test2_down[];
double test1_up[];
double test1_down[];
int UniqueNum = 009;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
Print("Inside init");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
Print("Inside deinit");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
Print("Inside start");
int counted_bars=IndicatorCounted();
int y5m=0, y1h=0, y30m=0, y15m=0, yy=0;
int i=0;
int limit=Bars-counted_bars;
for(i=0;i<limit;i++)
{
test4_up[i] = iCustom(NULL, 0, "#TestIndicator",0,i);
test4_down[i] = iCustom(NULL, 0, "#TestIndicator",1,i);
}
for(i=0;i<30;i++)
{
Print("Test 4 UP ", test4_up[i]," Bar ",i );
Print("Test 4 DOWN ", test4_down[i]," Bar ",i );
//Print("This is a test");
}
//----
return(0);
}
//+---------
I have an indicator that I am very fond of and have demo'd it for a couple of weeks and been pretty successful. Is there a way where I can automate buy/sell orders based on the indicator? Short summary is it's a small arrow pointing either up or down on the chart when the indicators I like line up. Is there a way that when the arrow pops up it will place an order for me?
I have an indicator that I am very fond of and have demo'd it for a couple of weeks and been pretty successful. Is there a way where I can automate buy/sell orders based on the indicator? Short summary is it's a small arrow pointing either up or down on the chart when the indicators I like line up. Is there a way that when the arrow pops up it will place an order for me?
Codersguru has a whole tutorial on how to write an EA. Read it, you will learn a lot.
You can use the iCustom function to incorporate your external indicator but you'll have to write the other logic (buy/sell etc.) yourself. It's pretty straightforeward.
Anyone can help me here? I am trying to do an object create of a uptrend or downtrend using iCustom and a indicator that displays Histogram bars above 0 and below 0.
How do i make use of the iCustom function to call on it that when its above 0, it a uptrend and when its below 0 its a downtrend?
Codesguru, can help me? I am trying to do an object create of a uptrend or downtrend using iCustom and a histogram indicator that displays Histogram bars above 0 and below 0.
How do i make use of the iCustom function to call on it that when its above 0, it an Uptrend and when its below 0 its a Downtrend? Also, how do i set a popup alert to alert 1 time only?