• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 7:20pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 7:20pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

TMA+CG Mladen indicator problem - rewrite the indicator, please 130 replies

Help? Simple Question Regarding Arrows Indicator Coding 0 replies

Regarding Smoothed Heikin Ashi indicator 0 replies

Question regarding indicator for keltner channels 1 reply

Problem with my broker regarding the news trading! 79 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: Serious problem regarding EA and indicator
Cancel

Serious problem regarding EA and indicator

  • Post #1
  • Quote
  • First Post: Oct 11, 2009 6:26am Oct 11, 2009 6:26am
  •  aicccia
  • | Joined Jun 2006 | Status: Carpe Diem | 854 Posts
Hey, I got a serious problem and I need some help.

I've got an indicator, and and EA that runs off this indicator.

However I have noticed that while the indicator calculates and draws correctly, the indicator is sending different values to the EA.

For example using the Print function, I've discovered that at a specific point in time, the value of one the lines of the indicator is 1.4785, while the EA thinks the value of this line at that specific time is 1.4799.

All my variables are the same in the indicator and EA, the EA is running on the correct version of the indicator, and I've checked the buffers, my EA is referencing the correct indicator buffers.

Does anyone have any idea as to what could be causing this?

thanks in advance for any help or ideas
  • Post #2
  • Quote
  • Oct 11, 2009 10:29am Oct 11, 2009 10:29am
  •  skorcht
  • | Joined Jun 2006 | Status: Member | 173 Posts
print all of the buffers on the indicator and the buffer referenced by iCustom(), if you are using that.
you should be able to match it up
taking series 3 and 34
 
 
  • Post #3
  • Quote
  • Oct 12, 2009 6:44am Oct 12, 2009 6:44am
  •  aicccia
  • | Joined Jun 2006 | Status: Carpe Diem | 854 Posts
Quoting skorcht
Disliked
print all of the buffers on the indicator and the buffer referenced by iCustom(), if you are using that.
you should be able to match it up
Ignored
I did print them, that's the crazy part, sometimes they match and sometimes they're different. It's entirely random and its killing me.

I've got 4 buffers:

double UpperBufferA[];
double UpperBufferB[];
double LowerBufferA[];
double LowerBufferB[];

When plotting the indicator, according to the logic of the indicator, the lines are plotted correctly. However when I reference this indicator in an EA with icustom, the indicator sends different values for each buffer to the EA that differ from the correctly drawn indicator lines from 3 to 50 pips.

As I said before, all variables(including the timeframe) are the same in indicator and EA.
 
 
  • Post #4
  • Quote
  • Edited 7:41am Oct 12, 2009 7:23am | Edited 7:41am
  •  aicccia
  • | Joined Jun 2006 | Status: Carpe Diem | 854 Posts
I really don't like posting my stuff on here but I really need to figure this out. Here's the indicator and the section of the EA that references the indicator. Hopefully someone can spot something that I've missed.

Indicator:
Inserted Code
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Yellow
#property indicator_color4 Blue
#property indicator_color5 Yellow

//---- indicator parameters
extern int    EMA_Period=648;
extern double space=1.0;
extern double basebandmin=3.0;
extern double resume_trendrate_at=0.005;
extern double trendexpand_rate=0.0075;
extern double rangexpand_rate=0.0005;
extern double contract_rate=0.0005;
extern double till_breakeven_rate=0.0005;



//---- buffers
double MovingBuffer[];
double UpperBufferA[];
double UpperBufferB[];
double LowerBufferA[];
double LowerBufferB[];

int max,order;
double basebands,op,mo;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   max=EMA_Period;  
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MovingBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,UpperBufferA);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,UpperBufferB);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,LowerBufferA);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,LowerBufferB);
//----
   SetIndexDrawBegin(0,max);
   SetIndexDrawBegin(1,max);
   SetIndexDrawBegin(2,max);
   SetIndexDrawBegin(3,max);
   SetIndexDrawBegin(4,max);
//----
   return(0);
  }

double bed,tal;
int start()
  {
   int    i,k,counted_bars=IndicatorCounted();
   double deviation,buffer,sum,oldval,newres,BandsDeviation,distance,average,atr,step1,expandingx,contractingx;
   
   if(Bars<=max) { return(0); }
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=max;i++)
        {
         MovingBuffer[Bars-i]=EMPTY_VALUE;
         UpperBufferA[Bars-i]=EMPTY_VALUE;
         UpperBufferB[Bars-i]=EMPTY_VALUE;
         LowerBufferA[Bars-i]=EMPTY_VALUE;
         LowerBufferB[Bars-i]=EMPTY_VALUE;
        }

   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(i=0; i<limit; i++)
      MovingBuffer[i]=iMA(NULL,PERIOD_M5,EMA_Period,0,MODE_EMA,PRICE_CLOSE,i);

   i=Bars-max+1;
   if(counted_bars>max-1) i=Bars-counted_bars-1;
   while(i>=0)
     {
      average=iMA(NULL,PERIOD_M5,3,0,MODE_EMA,PRICE_CLOSE,i);
      oldval=MovingBuffer[i]; 
      atr=iATR(NULL,PERIOD_M5,EMA_Period-1,i);
      step1=atr*basebands; 
      buffer=0.0006*space; 
    
      if(((order==1) || (order==4)) && (MathAbs((oldval+step1)-op)<resume_trendrate_at)) { expandingx=rangexpand_rate; } else expandingx=trendexpand_rate;
      if((order==1) && ((oldval+step1-buffer)<op)) { expandingx=till_breakeven_rate; }
      if((order==4) && ((oldval-step1+buffer)>op)) { expandingx=till_breakeven_rate; }
      if((order==2) && ((oldval+step1)>mo)) { contractingx=till_breakeven_rate; } else contractingx=contract_rate;
      if((order==3) && ((oldval-step1)<mo)) { contractingx=till_breakeven_rate; } else contractingx=contract_rate;
     
      if(order==1) { // Outside Buy
         if((average>(oldval+step1)) && (MathAbs(average-(oldval+step1))>expandingx))   { 
            if((MathAbs((average-expandingx)-oldval)/atr)>basebands)   { basebands=(MathAbs((average-expandingx)-oldval)/atr);  }}}
      if(order==2) { // Inside Sell
         if((average<(oldval+step1-buffer)) && (MathAbs(average-(oldval+step1-buffer))>contractingx)) { 
            if((MathAbs((average+contractingx)-(oldval-buffer))/atr)<basebands) { basebands=(MathAbs((average+contractingx)-(oldval-buffer))/atr); }}
         if(basebands<basebandmin) { basebands=basebandmin; }}
      if(order==3) { // Inside Buy
         if((average>(oldval-step1+buffer)) && (MathAbs(average-(oldval-step1+buffer))>contractingx)) { 
            if((MathAbs((average-contractingx)-(oldval+buffer))/atr)<basebands) { basebands=(MathAbs((average-contractingx)-(oldval+buffer))/atr); }}
          if(basebands<basebandmin) { basebands=basebandmin; }}
      if(order==4) { // Outside Sell
         if((average<(oldval-step1)) && (MathAbs(average-(oldval-step1))>expandingx))   { 
            if((MathAbs((average+expandingx)-oldval)/atr)>basebands)    { basebands=(MathAbs((average+expandingx)-oldval)/atr); }}} 
         
      deviation=atr*basebands;
    
      UpperBufferA[i]=oldval+deviation; 
      UpperBufferB[i]=oldval+deviation-buffer;
      LowerBufferA[i]=oldval-deviation;
      LowerBufferB[i]=oldval-deviation+buffer;
  
      if(average>UpperBufferA[i]) { order=1; if(op==0) { op=average; mo=0; }}
      if((order==1) && (average<UpperBufferB[i])) { order=2; if(mo==0) { mo=average; op=0; }}
      if((order==4) && (average>LowerBufferB[i])) { order=3; if(mo==0) { mo=average; op=0; }} 
      if(average<LowerBufferA[i]) { order=4; if(op==0) { op=average; mo=0; }}
      
      i--; }
 
   return(0);
  }

Section of EA that references indicator:
Data() is of course called every tick, but as you can see from the code, the arrays are only loaded with new values every new bar(which in this case is the 5 minute bar)
Inserted Code
 void Data()   { 
    ArraySetAsSeries(Base,true); ArraySetAsSeries(AverageFX,true); int e; 
    if(BB!=iTime(NULL,TimeFrame1,1)) {
      for(e=0;e<=1;e++) { 
         AverageFX[e]=iMA(NULL,TimeFrame1,average,0,MODE_EMA,PRICE_CLOSE,e);
         Base[e]=iMA(NULL,TimeFrame1,EMA_Period,0,MODE_EMA,PRICE_CLOSE,e);
         atr[e]=iATR(NULL,TimeFrame1,EMA_Period-1.0,e); 
         TopOuter=iCustom(NULL,TimeFrame1,"mystery",EMA_Period,space,basebandmin,resume_trendrate_at,trendexpand_rate,rangexpand_rate,contract_rate,till_breakeven_rate,1,e);
         TopInner=iCustom(NULL,TimeFrame1,"mystery",EMA_Period,space,basebandmin,resume_trendrate_at,trendexpand_rate,rangexpand_rate,contract_rate,till_breakeven_rate,2,e);
         BottomOuter=iCustom(NULL,TimeFrame1,"mystery",EMA_Period,space,basebandmin,resume_trendrate_at,trendexpand_rate,rangexpand_rate,contract_rate,till_breakeven_rate,3,e);
         BottomInner=iCustom(NULL,TimeFrame1,"mystery",EMA_Period,space,basebandmin,resume_trendrate_at,trendexpand_rate,rangexpand_rate,contract_rate,till_breakeven_rate,4,e);
         }
      BB=iTime(NULL,TimeFrame1,1); }}

It's like there are little gremlins in my computer, messing up my code. God damn gremlins are the reason I keep losing money in forex!!
 
 
  • Post #5
  • Quote
  • Last Post: Oct 21, 2009 12:20pm Oct 21, 2009 12:20pm
  •  hoichoi
  • | Joined Feb 2009 | Status: Member | 344 Posts
hi acicca
why have u stopped posting in the system thread u created we are all waiting for the final version of your system. if you can help that would be good
 
 
  • Platform Tech
  • /
  • Serious problem regarding EA and indicator
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023