Skip to content

Instantly share code, notes, and snippets.

@currencysecrets
Last active December 16, 2015 04:29
Show Gist options
  • Save currencysecrets/5377395 to your computer and use it in GitHub Desktop.
Save currencysecrets/5377395 to your computer and use it in GitHub Desktop.
This function returns the bar number according to the currency and datetime being passed in. This function is good for trailing stop methods that need to know when the entry of the bar occurred.
int getOpenBar( string sym, datetime openTime ) {
// each bar has the opening time at the start of the bar
// eg if openTime is 12:01PM we will know at 4:00PM (when the
// bar is greater than the opening time of trade)
for ( int i = 0; i < Bars; i++ ) {
if ( openTime >= Time[i] ) {
return( i );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment