Skip to content

Instantly share code, notes, and snippets.

View currencysecrets's full-sized avatar

Ryan currencysecrets

View GitHub Profile
@currencysecrets
currencysecrets / myMoneyManagement.mq4
Created July 9, 2012 08:33
MQL4: My Money Management
//+------------------------------------------------------------------+
//| My Money Management.mq4 |
//| Ryan Sheehy, CurrencySecrets.com |
//| http://www.currencysecrets.com |
//+------------------------------------------------------------------+
#property copyright "Ryan Sheehy, CurrencySecrets.com"
#property link "http://www.currencysecrets.com"
//--- input parameters
extern double xRiskPerTrade=1; // $ amount of risked per trade
@currencysecrets
currencysecrets / drawdownLimits.mq4
Last active August 29, 2023 07:00
How to set your drawdown limits to prevent excessive loss of capital in your MetaTrader script
//+------------------------------------------------------------------+
//| My Automated Trading EA.mq4
//| Copyright 2013, Ryan Sheehy
//| http://www.currencysecrets.com
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Ryan Sheehy"
#property link "http://www.currencysecrets.com"
//--- input parameters
string VERSION = "TL BO 1.0";
// external global variables
extern int EXT_SWINGS = 2; // swing level, 0 is lowest, 2 is most common
extern int EXT_NO_SWING_LMT = 12; // don't consider the latest X bars as swing points to draw trend lines
extern int EXT_ATR = 300; // ATR(x)
extern double EXT_ATR_MAX_SLOPE = 0.05; // multiple of ATR that would be considered maximum slope
extern double EXT_ATR_BUFFER = 0.05; // multiple of ATR to add to low/high for it to be considered a "touch"
extern int EXT_NULL_CLOSES = 0; // number of closes beyond trend line to nullify it as a valid trend line
extern int EXT_NUM_TOUCHES = 3; // (inclusive) number of touches needed to be considered a valid trend line
@currencysecrets
currencysecrets / automatedTrendLines.mq4
Created July 9, 2012 09:07
MQL4: Automated Trend Lines
//+------------------------------------------------------------------+
//| Automated Trend Lines.mq4 |
//| Ryan Sheehy, CurrencySecrets.com |
//| http://www.currencysecrets.com |
//+------------------------------------------------------------------+
#property copyright "Ryan Sheehy, CurrencySecrets.com"
#property link "http://www.currencysecrets.com"
/*
* This script automates the generation and plotting of sloping trend
@currencysecrets
currencysecrets / auto-trendlines.afl
Last active December 14, 2022 13:38
Amibroker version of automated trend lines.
/*
* Name: Automatic Trend Lines
* This Amibroker script is designed to automate the process of drawing:
* 1. Trend lines (sloping)
* 2. Support & resistance lines (horizontal)
* 3. Channel lines (parallel lines to trend lines & horizontal lines)
* This script is not a recommendation to buy or sell anything. It's to be
* used as is without any guarantees or warranties on its reliability.
* Author: Ryan Sheehy
* Version: v2.0.2 (20160816)
@currencysecrets
currencysecrets / WinFile.mqh
Created April 27, 2014 19:25
The famous WinFile.mqh file from MTIntelligence.com
//+------------------------------------------------------------------+
//| Copyright © 2009 MTIntelligence.com |
//| http://www.mtintelligence.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009 MTIntelligence.com"
#property link "http://www.mtintelligence.com"
// *************************************************************************************
//
@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 / calcPL.mq4
Created October 3, 2012 08:41
MQL4: Calculate Profit or Loss on Trade
/**
* This method calculates the profit or loss of a position in the home currency of the account
* @param string sym
* @param int type 0 = buy, 1 = sell
* @param double entry
* @param double exit
* @param double lots
* @result double profit/loss in home currency
*/
double calcPL(string sym, int type, double entry, double exit, double lots) {
@currencysecrets
currencysecrets / arrayUtility.mq4
Last active February 28, 2021 20:52
Handy Array Utility functions for MetaTrader 4
void flushArray( int& arr[] ) {
ArrayInitialize( arr, 0 );
ArrayResize( arr, 0 );
}
// append new element to end of int array
void intArrayPush( int& arr[], int elem ) {
int size = ArraySize( arr );
ArrayResize( arr, size + 1 );
arr[ size ] = elem;
@currencysecrets
currencysecrets / ArrayFunctions.mq4
Last active February 13, 2021 12:53
Array utility functions for MetaTrader 4. Helpful functions for doing some of the repetitive tasks in MQL.
/*
* clearIntArray
* This function deletes all items in array (sets it to 0) and resizes array according to size (default = 1).
* @param int& theArray - passing the array by reference
* @param int size - size of the array (default = 1)
* @return int blank array of size
*/
int clearIntArray( int& theArray[], int size = 0 ) {
ArrayResize( theArray, size );
if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }