- Price range must exceed average price range.
- Price must break into an uncommon area.
- Price must open near one extreme and close near the other.
- Volume must exceed average volume.
- Price continues to advance in the direction of the breakout.
/** | |
v2.0 | |
This function checks to determine that a breakout candle has occurred. | |
A breakout candle contains the majority of it's body in the candle (no long tails). | |
*/ | |
bool isBO( double o, double h, double l, double c, double volt, bool isLong ) { | |
if ( MathAbs( o - c ) > volt ) { | |
if ( MathAbs( o - c ) / ( h - l ) > 0.8 ) { | |
if ( c > o && isLong ) { | |
return( true ); |
/* v1.0 | |
* this will loop through the last X bars to determine whether there has | |
* been a pin bar (it tests only the last bar = n-1, and folds the last two and three) | |
*/ | |
int getPinBar( int per, int lookBack, bool dir ) { | |
string sym = Symbol(); | |
int h, l; | |
if ( lookBack <= 1 ) { | |
lookBack = 1; | |
} |
/** v6.0 | |
* A pin bar is a hammer like formation where the body of the candle | |
* is at one extreme of the entire candle and the wick making up the | |
* remainder of the candle. The body of the candle should be no more | |
* than 1/3 of the entire candle, with the remaining wick taking up | |
* no more than 2/3 of the remainder of the body. | |
*/ | |
bool isPin( double o, double h, double l, double c, bool isLong ) { | |
double hx, lx, rng = h - l, pct = 1/3; | |
if ( isLong ) { |
//* //////////////////////////////////////////////////////////////////////////////// | |
// int _IsTradeAllowed( int MaxWaiting_sec = 30 ) | |
// | |
// the function checks the trade context status. Return codes: | |
// 1 - trade context is free, trade allowed | |
// 0 - trade context was busy, but became free. Trade is allowed only after | |
// the market info has been refreshed. | |
// -1 - trade context is busy, waiting interrupted by the user (expert was removed from | |
// the chart, terminal was shut down, the chart period and/or symbol was changed, etc.) | |
// -2 - trade context is busy, the waiting limit is reached (MaxWaiting_sec). |
//+------------------------------------------------------------------+ | |
string err_msg(int e) | |
//+------------------------------------------------------------------+ | |
// Returns error message text for a given MQL4 error number | |
// Usage: string s=err_msg(146) returns s="Error 0146: Trade context is busy." | |
{ | |
switch (e) { | |
case 0: return("Error 0000: No error returned."); | |
case 1: return("Error 0001: No error returned, but the result is unknown."); | |
case 2: return("Error 0002: Common error."); |
void removeOldOrders( string sym, string systemTag ) { | |
int tot = OrdersTotal(); | |
for( int i = 0; i < tot; i++ ) { | |
if ( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) { | |
if ( OrderSymbol() == sym ) { | |
if ( OrderType() != OP_BUY || OrderType() != OP_SELL ) { | |
if ( OrderComment() != systemTag ) { // don't forget your new order must contain the systemTag! | |
OrderDelete( OrderTicket() ); | |
} | |
} |
// This function provides a boilerplate type template for sending email alerts about your MetaTrader code. | |
// param subject (optional) => Usually a short description of what the email is alerting you about | |
// param body (optional) => As the email already contains many bits of information I just use the body for detailing a reason | |
// param systemTag (optional) => The name/tag of your expert advisor | |
// | |
// Example usage within my EA: | |
// alertMe( "CLOSE long order failed", "Reason: Closing a pending buystop order in function XYZ has failed", "My Sys (v1.0)" ); | |
void alertMe( string subject = "", string body = "", string systemTag = "" ) { | |
SendMail( subject + " " + Symbol() + " " + systemTag , |
// this function returns the spread of the currency in double form | |
double getSpread( string sym ) { | |
return( MarketInfo( sym, MODE_SPREAD ) * MarketInfo( sym, MODE_POINT ) ); | |
} |
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 ); | |
} | |
} | |
} |