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 01-23-2008, 11:51 PM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
Best way to add MaxBarsToCount (History) to the limit?

Dear Admin, would be great if we didn't merge this thread and leave it separate -
question (problem) very common and specific thread much easier for Search
(plus this question allready in general thread, but no answer...)
--------------------------------------------------------------------


When we limit MaxBarsToCount (History) sometimes it require to add Correction, etc

is the best (safest, easiest, universal) way exist? (rule of tumb? dirty triks?)
----------------------

like here we have light fisher 4 stoch smothing:
----------

int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
int limit=Bars-counted_bars;
if(limit>maxbars)limit=maxbars;
if (limit>Bars-lenth-1)limit=Bars-lenth-1;
//----
for (int shift = limit; shift>=0;shift--)
{
AuxBuffer[shift]=(iStochastic(NULL,0,lenth,2,1,MODE_SMA,0,MODE_MAI N,shift)/100-0.5)
+0.5*AuxBuffer[shift+1];

FishBuffer[shift]= 0.25* MathLog((1+AuxBuffer[shift])/(1-AuxBuffer[shift]))+
0.5*FishBuffer[shift+1];
SignalBuffer[shift]=FishBuffer[shift+1];

}

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

for fisher limit f-la:

int limit;
int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(int i=limit; i>=0; i--)
{
....

for Stoch:


int start()
{
int i,k;
int counted_bars=IndicatorCounted();
double price;
//----
if(Bars<=draw_begin2) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=draw_begin1;i++) MainBuffer[Bars-i]=0;
for(i=1;i<=draw_begin2;i++) SignalBuffer[Bars-i]=0;
}
//---- minimums counting
i=Bars-KPeriod;
if(counted_bars>KPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double min=1000000;
k=i+KPeriod-1;
while(k>=i)
{
price=Low[k];
if(min>price) min=price;
k--;
}
LowesBuffer[i]=min;
i--;
}
....


p.s. in attached indicator, based on clean fisher transform and Stoch; MaxBars (tail) needs to be straighten-up a bit... (when MaxBars out - no problem)

pps. same thing with many others; try to add maxBars to regular (stoc) macd and look on the tail...
Attached Files
File Type: mq4 test_Trans_Stoch_smz_limitMaxBars_test.mq4 (2.8 KB, 13 views)

Last edited by fxbs; 01-23-2008 at 11:58 PM.
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 02-28-2008, 03:59 AM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
thank you everybody who helped!
here it is:

when we have no arrays - works basic formula:

limit = MathMin(limit, MaxBarsToCount);

but when we have 4ex. MAonArray - we need more bars (MA period) to count first MaonArray bar:
MaxBarsToCount + MA period

macd limit test3.gif

so, two ways possible- count more or draw less:

- draw MaxBarsToCount but count more
limit = MathMin(limit, MaxBarsToCount)+ MA period

- or count the same but draw less
SetIndexDrawBegin(i,Bars-MaxBarsToCount+MA period);

_____


in all cases SetIndexDrawBegin in "int start()" not at "init()" section

for (i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-MaxBarsToCount + MA period);
return(0);
}
Attached Files
File Type: mq4 MACD_limit_test1.mq4 (3.0 KB, 2 views)
File Type: mq4 MACD_limit_test2a.mq4 (2.6 KB, 2 views)
File Type: mq4 MACD_limit_test2b.mq4 (2.6 KB, 2 views)
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 02-28-2008, 04:00 AM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
________

whole thing 4 MAGD:
PHP Code:

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   
SetIndexStyle(0,DRAW_HISTOGRAM);
   
SetIndexStyle(1,DRAW_LINE);
   
SetIndexDrawBegin(1,SignalSMA);
   
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   
SetIndexBuffer(0,MacdBuffer);
   
SetIndexBuffer(1,SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   
SetIndexLabel(0,"MACD");
   
SetIndexLabel(1,"Signal");
   
   
//
   //
   //    two aproaches
   //     make an BarsToDraw that is going to be < MaxBarsToCount
   //
   //    or when setting limit add max (calculated here) to MaxBarsToCount
   //    calculate MaxBarsToCount+max and than 
   //   draw just MaxBarsToCount on chart
   //
   //
   
   
int max MathMax(FastEMA,SlowEMA);
       
max MathMax(SignalSMA,max);
       
BarsToDraw MaxBarsToCount-max;
//---- initialization done
   
return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;
   
limit MathMin(limitMaxBarsToCount);

//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
                   
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limiti++)
      
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);

   
//
   //
   //    don't draw everything
   //
   //

   
for (i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-BarsToDraw);   
   return(
0);
  }
//+------------------------------------------ 

Last edited by fxbs; 03-01-2008 at 06:22 PM.
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 02-29-2008, 10:41 PM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
another way - but that's - dirty trick:
simple macd;

only "-SignalSMA" added - that's it

//---- signal line counted in the 2-nd buffer
for(i=0; i<limit-SignalSMA; i++)

before:
PHP Code:
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;
   
limit MathMin(limitMaxBarsToCount);

//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limiti++)
      
SignalBuffer[i]=iMAOnArray(MacdBuffer,0,SignalSMA,0,MODE_SMA,i);
//---- done
   
return(0);
  }
//+------------------------------------------------------------------+ 
after

PHP Code:
//+------------------------------------------------------------------+
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;
   
limit MathMin(limitMaxBarsToCount);

//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limit-SignalSMAi++)
      
SignalBuffer[i]=iMAOnArray(MacdBuffer,0,SignalSMA,0,MODE_SMA,i);
//---- done
   
return(0);
  }
//+------------------------------------------------------------------+ 
macd limit test3 3lim.gif

not cleanest solution, but ....
(as been mentioned- dirty trick; and TRO can use it for his book...) : - )))))))))
____________

P.S.

whoops - people say this slaking approach no good: limit-SignalSMA can be negative - not refreshing, etc, etc...

whoopsy daisy ... what to do?
____________

gets trickier and trickier...

MaxBarsToCount instead of limit - should take care of it?

for(i=0; i<MaxBarsToCount -SignalSMA; i++)
instead of
for(i=0; i<limit-SignalSMA; i++)

-sure, but we sacrificing our beloved limit....

well, gets even more trickier:

PHP Code:
   limit=Bars-counted_bars;
   
limit MathMin(limitMaxBarsToCount);
//---- macd counted in the 1-st buffer
   
for(int i=0i<limit+SignalSMAi++)
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
//   for(i=0; i<limit-SignalSMA; i++)
     
for(i=0i<limiti++)
      
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done 

so: for(int i=0; i<limit+SignalSMA; i++)
they wouldn't call it "dirty trick" for nothing...
to do it right - everybody can; - try to do it ... different.... : ))))

new update: now - even more less dirtier (setting limit4 each buffer):
PHP Code:
   limit=Bars-counted_bars;
   
limit MathMin(limitMaxBarsToCount);

//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
        
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   
limit MathMin(limitMaxBarsToCount-SignalSMA); 
   for(
i=0i<limiti++)
  
      
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
   
return(0); 
1. limit = MathMin(limit, MaxBarsToCount);
...
2. limit = MathMin(limit, MaxBarsToCount-SignalSMA);

!nobody messes with our Limit!! : ((((

Last edited by fxbs; 03-01-2008 at 09:14 PM.
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 03-01-2008, 12:49 AM
Senior Member
 
Join Date: Feb 2006
Posts: 587
Michel is on a distinguished road
Quote:
Originally Posted by fxbs View Post
another way - but that's - dirty trick:
...
There is no ONE best solution.
It depends of what you want to do: for example, some indics must run at every tick of bar 0, but some other needs to run only once at the open of the bar, it's stupid to let them run at each tick; some cannot run the last "x" bars of the history because they need the datas, some run from the past to the present and some others no, and so on.
The best solution is the one YOU understand !
I must admit that sometime it's very tricky...
I such cases, in order to test how it works, I suggest you to add a command inside the "for" loop to print or comment the bar number, for example :

for(int i = limitblablabla...)
{
Print(i + " " + Bars + " " + IndicatorCounted());

In a generic case, if you only want to add a MaxBars count at a working indic , the easiest way is to add at the first line of the "for" loop this line :

for(int i = limitblablabla...) //original command , no need to understand it
{
if(i > MaxBars) continue;

....
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 03-01-2008, 01:05 AM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
perky's trick - eft sto smz (post1) tale cut-off
Attached Images
File Type: gif sto eft smz maxbars.gif (15.0 KB, 138 views)
Attached Files
File Type: mq4 test_Trans_Stoch_smz_limitMaxBars_test2.mq4 (2.9 KB, 6 views)
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 03-01-2008, 06:39 AM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
Quote:
Originally Posted by Michel View Post
There is no ONE best solution.
It depends of what you want to do: for example, some indics must run at every tick of bar 0, but some other needs to run only once at the open of the bar, it's stupid to let them run at each tick; some cannot run the last "x" bars of the history because they need the datas, some run from the past to the present and some others no, and so on.
The best solution is the one YOU understand !
I must admit that sometime it's very tricky...
I such cases, in order to test how it works, I suggest you to add a command inside the "for" loop to print or comment the bar number, for example :

for(int i = limitblablabla...)
{
Print(i + " " + Bars + " " + IndicatorCounted());

In a generic case, if you only want to add a MaxBars count at a working indic , the easiest way is to add at the first line of the "for" loop this line :

for(int i = limitblablabla...) //original command , no need to understand it
{
if(i > MaxBars) continue;

....
Thanks a lot, Michel!
- that's how we learn, day by day
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 03-01-2008, 07:53 AM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
Hey, Michel!
how to use this line:
if(i > MaxBars) continue;
i tryed - no go...

but if put like this:
if(i < MaxBarsToCount)
- works (MACD):

PHP Code:
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;

//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
   if(
MaxBarsToCount)
   
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limiti++)
      if(
MaxBarsToCount-SignalSMA

      
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- 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
  #9 (permalink)  
Old 03-01-2008, 08:38 AM
Senior Member
 
Join Date: Feb 2006
Posts: 587
Michel is on a distinguished road
Quote:
Originally Posted by fxbs View Post
Hey, Michel!
how to use this line:
if(i > MaxBars) continue;
i tryed - no go...

but if put like this:
if(i < MaxBarsToCount)
- works (MACD):

PHP Code:
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;

//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
   if(
MaxBarsToCount)
   
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limiti++)
      if(
MaxBarsToCount-SignalSMA

      
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
   
return(0); 
both should do the same, but the problem here is that you don't use the brackets for the for loop because there is only one command.
"if(i < MaxBarsToCount) MacdBuffer[i]=iMA(NULL,0,FastEMA... ;" is only one command ( there is only one ";" ) so the for loop doesn't need any brackets.
Now, the use "if(i >MaxBarsToCount) continue;" means one more command in the for loop, so you have to use brackets to group them together.
so :
for(int i=0; i<limit; i++)
if(i > MaxBarsToCount) continue;
does'nt work because there is only one command, the if test line, which does nothing.
but
for(int i=0; i<limit; i++)
{
if(i > MaxBarsToCount) continue;
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE blabla ;
blahblahblah...;
}
works.

I a general case, the for loop use brackets, thus "if(i > MaxBarsToCount) continue;" is ready to use (you do not need to add other brakets or modify the code)

Last edited by Michel; 03-01-2008 at 08:42 AM.
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
  #10 (permalink)  
Old 03-01-2008, 10:35 AM
Senior Member
 
Join Date: Jan 2007
Location: not so remote
Posts: 3,272
fxbs is on a distinguished road
Thank you, Michel!
well, i did as you sayed -
PHP Code:
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limiti++)
   {
    if(
MaxBarsToCount) continue; 
SignalBuffer[i]=iMAOnArray(NULL,0,FastEMA,0,MODE blabla ;
blahblahblah...;
     }
//---- done 

works good but when onArray - old story - steping on tail
(maybe should have use more braskets: )

macd maxbars limit.gif

well, 4 onArray buffer :
if(i > MaxBarsToCount - SignalSMA) continue;
and that's it! : ))))))))
PHP Code:
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;
//  limit = MathMin(limit, MaxBarsToCount);
//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
  {
if(
MaxBarsToCount) continue;   
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
   }
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limiti++)
   {
if(
MaxBarsToCount SignalSMA) continue; 
      
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
    }
//---- done
   
return(0);
  } 
thaks, Michel, - we still have our limit (no counted bars recount) -
clean solution too

Last edited by fxbs; 03-02-2008 at 02:33 AM.
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
Order Limit clippertm Questions 1 07-16-2007 04:04 PM
how to get total each of buy/sellstop/limit? tytian Metatrader 4 11 03-30-2007 01:26 AM
Limit/Stop Orders Expiry dates don perry Metatrader 4 1 06-14-2006 04:54 AM
ANy limit to number of trades an EA can do? shazan Expert Advisors - Metatrader 4 2 04-15-2006 05:34 PM
How to enter Limit Orders ? billm General Discussion 3 01-02-2006 07:04 PM


All times are GMT. The time now is 01:17 PM.



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