Need help why calling indicator in expert not working properly

 

Hello,

I am using a custom indicator which works perfectly when added to a chart. It looks and operates normally. I am attempting to call it within my expert and it only returns the number 2147483647. I have included the code I use to call the indicator within the expert and the code of the indicator (I've also included the Indicator file). Any ideas why it only gives me the number 2147483647? I have tried changing the buffer mode and shift intigers but to no avail. Thanks much!

Pertinate code in EA

int start()
{
double Indicator;
int cnt, ticket, total, i;


// to simplify the coding and speed up access
// data are put into internal variables

Indicator = iCustom(NULL,0,"Sentinal Index_SMA",0,3);

Print("My indicators value=",Indicator);

Indicator Code:

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 RoyalBlue
#property indicator_color2 Goldenrod


extern int MODE = 0, // 0=Percent, 1=Pips, 2=USD per Lot
SMA_Period = 336;

extern double BIAS = 0, // starting value for the first bar
EUR = 1.0, // weights
JPY = 1.0,
GBP = 1.0,
CHF = 1.0,
CAD = 1.0,
AUD = 1.0,
NZD = 1.0;

//---- indicator buffers
double Index[],
SMA_Sentinal[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string name = "Sentinal Index";

//---- indicator line
IndicatorShortName(name);
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Index);
SetIndexLabel(0,name);

SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,SMA_Sentinal);

//----
return(0);
}

//+------------------------------------------------------------------+
//| Calculates the relative change of symbol between bar i and i+1 |
//+------------------------------------------------------------------+
double Sentinal(string symbol, int i = 0)
{
double a = iClose(symbol,0,i),
b = iClose(symbol,0,i+1),
move = a-b;

if(a==0||b==0)
{
if(i==0)
Print("Warning: No "+symbol+" data loaded.");
return(0);
}

double moveInPercent = 100*move/b;
double pointSize = MarketInfo(symbol,MODE_POINT),
tickValue = MarketInfo(symbol,MODE_TICKVALUE);
double moveInPips = move / pointSize,
moveInUSD = moveInPips * tickValue;

switch(MODE)
{
case 0: return(moveInPercent);
case 1: return(moveInPips);
case 2: return(moveInUSD);
}

return(0);
}

//+------------------------------------------------------------------+
int start()
{
int iMax = Bars - 1 - IndicatorCounted();
if(iMax==Bars-1)
{
iMax--;
Index[Bars-1] = BIAS;
}

//----
for(int i = iMax; i >= 0; i--)
{
double x = 0;

x += EUR * Sentinal("EURUSD",i);
x += -JPY * Sentinal("USDJPY",i);
x += GBP * Sentinal("GBPUSD",i);
x += -CHF * Sentinal("USDCHF",i);
x += -CAD * Sentinal("USDCAD",i);
x += AUD * Sentinal("AUDUSD",i);
x += NZD * Sentinal("NZDUSD",i);
x /= (EUR+JPY+GBP+CHF+CAD+AUD+NZD); // FIXME: incorrect if a pair is not available

// TODO: Calculate median instead of average?

// Index[i] = x;
Index[i] = Index[i+1]+x;
}

//Add SMA of Sentinal Indicator

for(i = iMax; i >= 0; i--)
{
SMA_Sentinal[i] = iMAOnArray(Index,0,SMA_Period,0,MODE_SMA,i);
}

//---
return(0);
}




 
Please use "MQL" button
 
Hello,

I have the same problem. I think is a bug or indicator must be written diferent.

Regards,
Tomaz

P.S.: MQL button? Can you explain that more specific.
 
Regarding the MQL button: In the text-editor on this site there is a button, when editing a reply/topic, that formats your MQL code to a highlighed piece of text, which makes it more readable. Here's yours:

int start()
  {
   double Indicator;
   int cnt, ticket, total, i;
 
 
// to simplify the coding and speed up access
// data are put into internal variables
 
Indicator = iCustom(NULL,0,"Sentinal Index_SMA",0,3);
 
Print("My indicators value=",Indicator);
 
Indicator Code:
 
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 RoyalBlue
#property indicator_color2 Goldenrod
 
 
extern int  MODE = 0, // 0=Percent, 1=Pips, 2=USD per Lot
               SMA_Period = 336;
 
extern double BIAS = 0, // starting value for the first bar
     EUR = 1.0, // weights
     JPY = 1.0,
     GBP = 1.0,
     CHF = 1.0,
     CAD = 1.0,
     AUD = 1.0,
     NZD = 1.0;
 
//---- indicator buffers
double Index[],
         SMA_Sentinal[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
 string name = "Sentinal Index";
 
//---- indicator line
 IndicatorShortName(name);
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Index);
   SetIndexLabel(0,name);
  
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,SMA_Sentinal);
 
//----
   return(0);
}
 
//+------------------------------------------------------------------+
//| Calculates the relative change of symbol between bar i and i+1 |
//+------------------------------------------------------------------+
double Sentinal(string symbol, int i = 0)
{
 double a = iClose(symbol,0,i),
    b = iClose(symbol,0,i+1),
    move = a-b;
 
 if(a==0||b==0)
 {
  if(i==0)
   Print("Warning: No "+symbol+" data loaded.");
  return(0);
 }
 
 double moveInPercent = 100*move/b;
 double pointSize = MarketInfo(symbol,MODE_POINT),
    tickValue = MarketInfo(symbol,MODE_TICKVALUE);
 double moveInPips = move / pointSize,
      moveInUSD  = moveInPips * tickValue;
 
 switch(MODE)
 {
  case 0: return(moveInPercent);
  case 1: return(moveInPips);
  case 2: return(moveInUSD);
 }
 
 return(0);
}
 
//+------------------------------------------------------------------+
int start()
{
 int iMax = Bars - 1 - IndicatorCounted();
 if(iMax==Bars-1)
 {
  iMax--;
  Index[Bars-1] = BIAS;
 }
 
//----
   for(int i = iMax; i >= 0; i--)
 {
  double x = 0;
 
  x +=  EUR * Sentinal("EURUSD",i);
  x += -JPY * Sentinal("USDJPY",i);
  x +=  GBP * Sentinal("GBPUSD",i);
  x += -CHF * Sentinal("USDCHF",i);
  x += -CAD * Sentinal("USDCAD",i);
  x +=  AUD * Sentinal("AUDUSD",i);
  x +=  NZD * Sentinal("NZDUSD",i);
  x /= (EUR+JPY+GBP+CHF+CAD+AUD+NZD); // FIXME: incorrect if a pair is not available
 
//  TODO: Calculate median instead of average?
 
//  Index[i] = x;
  Index[i] = Index[i+1]+x;
 }
 
//Add SMA of Sentinal Indicator 
 
   for(i = iMax; i >= 0; i--)
 {
    SMA_Sentinal[i] = iMAOnArray(Index,0,SMA_Period,0,MODE_SMA,i);
   }
 
//---
 return(0);
}
 
You read

 double pointSize = MarketInfo(symbol,MODE_POINT),
    tickValue = MarketInfo(symbol,MODE_TICKVALUE);

try this

if (pointSize==0) Print ("Ooops ... where is pointSize?");
if (tickValue ==0) Print ("Ooops ... where is tickValue ?");
 

Hello,

I tried Your code and I do not get any "error" : "Ooops ... where is pointSize?" or the other message.
Thanks for your help anyway.

Regards,
Tomaz



Rosh wrote:
You read

 double pointSize = MarketInfo(symbol,MODE_POINT),
    tickValue = MarketInfo(symbol,MODE_TICKVALUE);

try this

if (pointSize==0) Print ("Ooops ... where is pointSize?");
if (tickValue ==0) Print ("Ooops ... where is tickValue ?");


 
Hello,

I wrote code in that way and it is working now.

double pointSize = Point, //MarketInfo(symbol,MODE_POINT),

I must check now if is that right solution, but catch is here.

Regards,
Tomaž