ea based on willspread

 

i'd like to have a will_spread  indicator running in an expert

the willspread indicator has the sequent settings for SetIndexBuffer:

IndicatorBuffers(4);
   SetIndexBuffer(0, WillSpread);
   SetIndexBuffer(1, Spread);
   SetIndexBuffer(2, FastEMA);
   SetIndexBuffer(3, SlowEMA);

In my expert I use the iCustom instruction to extract the indicator value for the previous candle:

double previous_willspread = iCustom(NULL, 0, "Will-Spread_", 3, 15, "USAOIL", false,0,1);

but the results are value of the same order of the true value, but different

Can anyone help me?

 
Your request is incoherent. Please edit your post so that it can be understood.
 

well

My problem is the following:

 i'd like to introduce in an expert the results of this indicator:

//---- input parameters

extern int FastMAPeriod = 3;

extern int SlowMAPeriod = 15;

extern string SecondMarket = "GLD";

extern bool MarketsDirectCorrelation = true;

//---- buffers

double WillSpread[];

double Spread[];

double FastEMA[];

double SlowEMA[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

  {

   string Correlation = "Invert Correlation";

   if(MarketsDirectCorrelation == TRUE) 

       Correlation = "Direct Correlation";

   IndicatorShortName("Will-Spread(" + FastMAPeriod + "," + SlowMAPeriod + 

                      "," + SecondMarket + "," + Correlation + ")");

   IndicatorDigits(Digits + 2);

   IndicatorBuffers(4);

   SetIndexBuffer(0, WillSpread);

   SetIndexBuffer(1, Spread);

   SetIndexBuffer(2, FastEMA);

   SetIndexBuffer(3, SlowEMA);

   SetIndexStyle(0, DRAW_LINE);

   SetIndexLabel(0, "W-S");

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+

int deinit()

  {

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

  {

   int i, counted_bars = IndicatorCounted();

//---- check for possible errors

   if(counted_bars < 0) 

       return(-1);

//---- last counted bar will be recounted

   if(counted_bars > 0) 

       counted_bars--; 

   int limit = Bars - counted_bars;

   if(MarketsDirectCorrelation == TRUE)

     {

       for(i = 0; i < limit; i++)

           Spread[i] = iClose(SecondMarket, 0, i) / Close[i]*100;

  

     }

   else

     {

       for(i = 0; i < limit; i++)

           Spread[i] = Close[i] / iClose(SecondMarket, 0, i)*100;

     }

   for(i = limit - 1; i >= 0; i--)

     {

       FastEMA[i] = iMAOnArray(Spread, 0, FastMAPeriod, 0, MODE_EMA, i);

       SlowEMA[i] = iMAOnArray(Spread, 0, SlowMAPeriod, 0, MODE_EMA, i);

       WillSpread[i] = FastEMA[i] - SlowEMA[i];

     }

//----

   return(0);

  }

I'd like to use it comparing usdcad and usaoil, considering the inverse correlation between the instruments

to reach my goal I used a variable defined with iCustom command in this way:

double previous_willspread = iCustom(NULL, 0, "Will-Spread_", 3, 15, "USAOIL", false,0,1);

but the values extracted are not the right ones.