Skip to content

Instantly share code, notes, and snippets.

View currencysecrets's full-sized avatar

Ryan currencysecrets

View GitHub Profile
@currencysecrets
currencysecrets / MetaTraderBrokerQuestions.md
Created September 30, 2013 11:14
Things to TEST and ask your MetaTrader broker about when designing and implementing your MetaTrader system.

Important questions you will need to know the answers to BEFORE operating a LIVE MetaTrader account with your broker.

Price/History

  1. Are ticks mantained throughout the weekend?
  2. Are changes to Daylight Savings made? Which country is followed as the baseline?
  3. What time zone is stamped on price?
@currencysecrets
currencysecrets / getATRTrailingStop.mq4
Last active September 11, 2022 02:51
ATR Trailing Stop method - these are the ATR trailing stop functions I use to calculate my automatic stops. Aspects within this code that need to be added are the checking of the Trading Content being free and (optional) better error reporting.
//+------------------------------------------------------------------+
//| calculate-atr-trailing-stop.mq4
//| Copyright 2013, Currency Secrets
//| http://www.currencysecrets.com
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Currency Secrets"
#property link "http://www.currencysecrets.com"
//--- input parameters
extern int extLookBack = 50; // bars to look back for the ATR indicator
@currencysecrets
currencysecrets / HTMLalertMe.mq4
Created September 17, 2013 12:47
HTML version of alertMe - for those who have the ability to send HTML emails from within MetaTrader, more here:
void alertMe( string subject = "", string body = "", string sym = "" ) {
if ( sym == "" ) { sym = Symbol(); }
string systemTag = WindowExpertName() + " (v" + sysVersion + ")";
SendMail( subject + " " + sym + " " + systemTag ,
"<!DOCTYPE html><html lang='en-AU'><head>" +
"<body style='width:600px'>" +
body +
"<br /><br /><br /><br />" +
"<table border=0 cellpadding=5><tr><td colspan='2'>SYSTEM DETAILS:</td></tr>" +
"<tr><td>System:</td><td>" + systemTag + "</td></tr>" +
@currencysecrets
currencysecrets / swapValueReport.mq4
Created September 17, 2013 12:21
SWAP Value Report - save as script in your MetaTrader 4 platform and double click to run.
//+------------------------------------------------------------------+
//| Swap Values.mq4 |
//| Copyright 2013, Currency Secrets |
//| http://www.currencysecrets.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Currency Secrets."
#property link "http://www.currencysecrets.com"
string fx[32];
@currencysecrets
currencysecrets / swapValues.mq4
Last active December 23, 2015 06:19
Finding out the SWAP values for a currency pair. Run this code in a SCRIPT file NOT an expert advisor file.
//+------------------------------------------------------------------+
//| Swap Values.mq4 |
//| Copyright 2013, Currency Secrets |
//| http://www.currencysecrets.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Currency Secrets (as is)."
#property link "http://www.currencysecrets.com"
//+------------------------------------------------------------------+
//| script program start function |
@currencysecrets
currencysecrets / checkPortfolioRisk.mq4
Created September 13, 2013 13:17
This simple script determines whether a new trade is viable according to the current level of portfolio risk. It does NOT take into account any strong positive or negative correlations that exist with the existing trades and only uses the AccountBalance() and NOT any draw down amount in equity.
extern int maxPortfolioRisk = 30; // maximum amount at risk (0 = nothing; 100 = all)
// this function returns the profit/loss if the stop is hit
double profitAtStop( double open, double stop, double lots, bool isLong, string sym = "" ) {
if ( sym == "" ) { sym = Symbol(); }
double result = lots * MarketInfo( sym, MODE_TICKVALUE ) / MarketInfo( sym, MODE_TICKSIZE );
if ( isLong ) {
return( N( ( stop - open ) * result, 2 ) );
} else {
return( N( ( open - stop ) * result, 2 ) );
@currencysecrets
currencysecrets / autoTradingFramework.mq4
Last active June 25, 2017 13:22
Automated Trading - Framework. I'm finding through continued automated MetaTrader 4 system programming that my expert advisors are taking the same form and shape.
INIT
----
|
|_ remove pending orders
| |
| |_ error alert
|
|_ reset charts
|_ reset global variables
@currencysecrets
currencysecrets / reportOpenPositions.mq4
Last active December 22, 2015 08:58
Report on Open Positions - this function obtains the currently held open positions and returns a string.
int extBarsBack = 60;
// this function returns the profit/loss if the stop is hit
double profitAtStop( double open, double stop, double lots, bool isLong, string sym = "" ) {
if ( sym == "" ) { sym = Symbol(); }
double result = lots * MarketInfo( sym, MODE_TICKVALUE ) / MarketInfo( sym, MODE_TICKSIZE );
if ( isLong ) {
return( N( ( stop - open ) * result, 2 ) );
} else {
@currencysecrets
currencysecrets / alertMe.mq4
Last active April 3, 2018 12:40
alertMe is a template function that is used to send emails regarding any errors that occur during automation of trade and position processing. User simply calls the function by entering a string for the header/subject line of the email and then the opening area of the body of the message. The remainder of the function adds additional details abo…
/**
* This function sends an email according to the Tools > Options > Send Email settings
* @string subject line of the email (default = empty string)
* @string opening body of the message (default = empty string)
* @string optional currency symbol (default = empty string == symbol of the active chart)
*/
void alertMe( string subject = "", string body = "", string sym = "" ) {
string systemTag;
if ( sym == "" ) { sym = Symbol(); }
systemTag = WindowExpertName() + " (v" + version + ")";
@currencysecrets
currencysecrets / coreUtility.mq4
Created August 9, 2013 12:51
Simple MQL4 Utility Functions. Converting datetime to string. Converting double to a specific number of decimal places. Converting price to string.
/**
* @double price to convert to string
* @int number of decimal places to show (default = Digits of active currency)
*/
string D( double price, int num = -1 ) {
if ( num == -1 ) { num = Digits; }
return( DoubleToStr( price, num ) );
}
/**