Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-12-2008, 12:19 PM
Junior Member
 
Join Date: Dec 2005
Posts: 11
graemenash is on a distinguished road
Buffer problem

Hi all,

I asked this question in another forum but it was moved, I think it was meant to be moved to this one but instead it got buried in another thread.

I know a little about MQL programming but not enough to solve this problem!

I'm trying to create an indicator with two buffers.

The values held in the first buffer is simply the O+H+L+C of the current bar divided by 4, no problems there.

The second buffer is where I'm having the problem. Basically the second buffer holds the value of buffer1 on the previous bar, added to the value of buffer2 on the previous bar, divided by 2.

That's not much of a problem either, except when you count back to the very first bar in the chart there is no previous bar to take data from. For that bar buffer2 needs a starting value, which is the open of that bar.

Basically I don't know how to set that up and would appreciate any help. Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 06-12-2008, 12:32 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
PHP Code:
if ( bar == Bars ) {
    
buffer2bar ] = Openbar ];
} else {
    
buffer2bar ] = ....

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 06-12-2008, 01:14 PM
Junior Member
 
Join Date: Dec 2005
Posts: 11
graemenash is on a distinguished road
Thanks Ralph I appreciate the help.

Just wondering if you could help me with where to place that bit of code. The basics I have so far are:

PHP Code:
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- check for possible errors
   
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;
//---- current bar OHLC counted in first buffer
   
for(int i=0i<limiti++)
      
ind_buffer1[i]=((Open[i]+High[i]+Low[i]+Close[i])/4);
//---- buffer1[1]+buffer2[1]/2 counted in second bar
   
for(i=0i<limiti++)
      
ind_buffer2[i]=((ind_buffer1[i+1]+ind_buffer2[i+1])/2);
//---- done
   
return(0);
  } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 06-12-2008, 01:15 PM
Administrator
 
Join Date: Sep 2005
Posts: 20,082
Blog Entries: 243
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Some related threads:

http://www.forex-tsd.com/metatrader-...-4-rsioma.html
Multiple Null Bar Re-Count in Some Indicators - MQL4 Articles
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 06-12-2008, 01:37 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
Firstly you need to range from higher index to lower, which corresponds to left to right. Otherwise the code will try to compute the right-hand (lower) index before the left-hand (higher) index, which it depends upon.

Thereafter you can wedge in my previous snippet into the last "for" clause.

Also, I think you should get rid of that counted_bars fiddling (which serves no purpose apart from adding confusion)
It'd be better to make the looping as:

PHP Code:
for ( int i Bars IndicatorCounted() - 1>= 0i-- ) {
    ... 
deal with indication for bar i

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 06-12-2008, 02:13 PM
Junior Member
 
Join Date: Dec 2005
Posts: 11
graemenash is on a distinguished road
Hi Ralph,

Thanks again for your help

I have just one more newbie question if you don't mind

This is the code I have now:

PHP Code:
int start()
  {
//---- current bar OHLC counted in first buffer
   
for(int i=Bars-IndicatorCounted()-1i>=0i--) 
      
ind_buffer1[i]=((Open[i]+High[i]+Low[i]+Close[i])/4);
//---- buffer1[1]+buffer2[1]/2 counted in second bar
   
for(i=Bars-IndicatorCounted()-1i>=0i--) 
      {
      if(
bar==Bars-1
         {
         
ind_buffer2[bar]=Open[bar];
         } 
      else 
      {
      
ind_buffer2[i]=((ind_buffer1[i+1]+ind_buffer2[i+1])/2);
      }  
      
Comment("buffer1=",ind_buffer1[i],"\nbuffer2=",ind_buffer2[i],"");
      }
//---- done
   
return(0);
  } 
When compiling, there is a problem because the variable "bar" is not defined. How should it be defined so that the program knows to look at the current bar number to check if it is the first bar?

Am I right in thinking that in the first code snippet you gave me, [bar] should be replaced with [i] ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 06-12-2008, 02:16 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
yes, that's right.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 06-12-2008, 02:22 PM
Junior Member
 
Join Date: Dec 2005
Posts: 11
graemenash is on a distinguished road
Thanks Ralph!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
who has extra buffer? or half? 4 Rsioma fxbs MetaTrader 31 04-15-2009 07:40 PM
The problem !!! MiniMe General Discussion 3 09-21-2007 07:44 AM
Help with buffer limits and flatlining indicator lines iboersma Indicators - Metatrader 4 0 03-22-2007 08:27 PM
Problem with .ex4................. EFX General Discussion 4 10-21-2006 08:23 AM


All times are GMT. The time now is 02:57 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.