|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
barssince(), vauewhen()
metastock-like functions:
since it costed me quite some time to figure out a self-made metastock-like function, I think it might be valuble for some people to have the function code. Therefore I decide to post the code here. barssince() function: //by suffic369 int barsSince() { bool cond; int bars=Bars; static datetime prevtime=0; if( prevtime == Time[0]) return(0); prevtime = Time[0]; for (int i=0;i<=bars;i++) { if ( cond ) { int barPos=i; break; } } if (barPos<bars) return(barPos); else return(-1); } valuewhen(): if you know the bar position,it is easy to know the value of whatever you want. suffic369 www.wsforex.com Last edited by suffic369 : 09-30-2006 at 08:14 PM. |
|
|||
|
Hi suffic369...thanks for converting such a great function.
But after i pasted the function in my EA, i am having problem in calling the barsSince() . Can you show an example how to call it inorder to know the bar position? Many Thanks for your effort. |
|
|||
|
the prevtime variable must be staitc
example: to find the bar position of the latest C cross up the ma int barsSince() { int bars=Bars; static datetime prevtime=0; if( prevtime == Time[0]) return(0); prevtime = Time[0]; for (i=0,i<bars,i++) { ci=Close[i]; c1i=Close[1+i]; mai=iMA(....,i); ma1i=iMA(....,1+i); bool cXmaUp=ci>mai && c1i<ma1i; if (cXmaUp) { int barPos=i; break; } } if (barPos<bars) return(barPos); else return(-1); } to call this function you will get the latest bar position of c cross up ma. suffic369 www.wsforex.com Last edited by suffic369 : 09-30-2006 at 08:14 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|