Skip to content

Instantly share code, notes, and snippets.

View currencysecrets's full-sized avatar

Ryan currencysecrets

View GitHub Profile
@currencysecrets
currencysecrets / CSAutomatedTrendLines.mq4
Last active May 13, 2017 19:32
Plots automated trend lines and horizontal support and resistance lines on existing chart. This represents now version 3.0 of this script as it has had a rewrite on the level of swings, rather than limiting it to 3 levels through a series of multiple if-statements! This script will also form the basis for the automated trading aspect, so expect …
//+------------------------------------------------------------------+
//| CS Trend Line Breakout.mq4 |
//| Ryan Sheehy |
//| http://www.currencysecrets.com |
//| Version: 3.0 |
//| Released: 7 Jan 13 |
//+------------------------------------------------------------------+
#property copyright "Ryan Sheehy"
#property link "http://www.currencysecrets.com"
@currencysecrets
currencysecrets / CS period_converter.mq4
Created January 11, 2013 03:41
Commenting out of the update in the period_converter script in MetaTrader.
//+------------------------------------------------------------------+
//| Period_Converter.mq4 |
//| Copyright © 2005-2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property show_inputs
#include <WinUser32.mqh>
@currencysecrets
currencysecrets / CS Auto Trend Lines (Offline).mq4
Last active December 11, 2015 00:28
This Expert Advisor plots the historical trend lines on the offline charts.
//+------------------------------------------------------------------+
//| CS Auto Trend Lines (Offline).mq4 |
//| Ryan Sheehy |
//| http://www.currencysecrets.com |
//| Version: 1.0 |
//| Released: 12 Jan 13 |
//+------------------------------------------------------------------+
#property copyright "Ryan Sheehy"
#property link "http://www.currencysecrets.com"
@currencysecrets
currencysecrets / checkOpenTrades.mq4
Last active December 14, 2015 11:18
Silent orders with reversable positions.
/*
* checkOpenTrades
* This function checks open trades and compares them to risk levels.
* @param sym
* @return int -1 = error
*/
int checkOpenTrades( string sym ) {
int type, revType, tradeReady, tkt, dir;
double p, revP, profit, trailingStop;
for ( int i = 0; i < OrdersTotal(); i++ ) {
@currencysecrets
currencysecrets / SimpleChannelBreakout.mq4
Last active May 13, 2017 19:21
This was the simple breakout system designed for the series on creating a MetaTrader 4 system in Sublime Text's text editor. The series can be found on our website http://www.currencysecrets.com.
//+------------------------------------------------------------------+
//| Simple Channel Breakout System.mq4
//| Copyright 2013, Ryan Sheehy
//| http://www.currencysecrets.com
//| v1.1 - errors fixed (getLots & multipleOrders)
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Ryan Sheehy"
#property link "http://www.currencysecrets.com"
//--- input parameters
@currencysecrets
currencysecrets / getQtyOrders.mq4
Created April 13, 2013 06:42
This function returns the number of orders, both open or pending, for the currency and the type specified.
// this function will return the quantity of orders (both open and pending)
// on the selected currency for the order type requested.
int getQtyOrders( int type, string sym ) {
int result = 0;
int tot = OrdersTotal();
for ( int i = 0; i < tot; i++ ) {
if ( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) {
if ( OrderSymbol() == sym ) {
if ( OrderType() == type ) {
result += 1;
@currencysecrets
currencysecrets / getOpenBar.mq4
Last active December 16, 2015 04:29
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 );
}
}
}
@currencysecrets
currencysecrets / getSpread.mq4
Created April 13, 2013 07:29
This function returns the spread in double digit form, eg 0.00030 rather than 30.
// this function returns the spread of the currency in double form
double getSpread( string sym ) {
return( MarketInfo( sym, MODE_SPREAD ) * MarketInfo( sym, MODE_POINT ) );
}
@currencysecrets
currencysecrets / alertMe.mq4
Last active December 16, 2015 06:58
Using the SendEmail function to alert me of potential problems in my MetaTrader live code.
// 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 ,
@currencysecrets
currencysecrets / removeOldOrders.mq4
Created April 17, 2013 01:40
Removing pending orders when they do not match the new trading system's version number. It does assume that the system tag is placed in the OrderComment area of a new order.
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() );
}
}