Skip to content

Instantly share code, notes, and snippets.

View matthewkastor's full-sized avatar

Kastor matthewkastor

  • Atropa Inc. Intl.
  • Michigan
View GitHub Profile
@matthewkastor
matthewkastor / NUnit parameterized tests with typed specs.cs
Created January 25, 2016 19:37
Snippets of code for creating test spec objects, but still having NUnit list each method with it's args as an individual test in the tree
// NUnit can use a list of "TestParameters", but then it
// doesn't populate the list of tests with the method(parameter, parameter)
// item in the list. So, instead, I made a class so I could
// create the TestParameters object in queries, assign values
// to named properties, and when I need them in a list of
// object[] for NUnit, I just convert each one by calling it's
// ToObject() method.
/// <summary>
/// Structure of test parameters
@matthewkastor
matthewkastor / mql Close Open Order.mq4
Last active January 23, 2016 22:18
function to close the currently selected order in metatrader 4
// bool result = CloseOpenOrder(5);
// closes the currently selected order
bool CloseOpenOrder(int slippage){
double price;
if(OrderType() == OP_SELL) {
price = Ask;
} else {
price = Bid;
}
@matthewkastor
matthewkastor / mql Modify Open Order.mq4
Last active October 21, 2021 02:22
function that moves the stop loss and take profit levels if it is favorable to the open position on metatrader 4
// select the order http://docs.mql4.com/trading/orderselect
// OrderSelect(......
// then this method will work on the order selected
// bool result = ModifyOpenOrder(0.00300, 0.00900);
// returns true if the order was modified successfully
// returns false if the order didn't need modification or if modification failed
bool ModifyOpenOrder(double stopLossPips, double pipsProfit){
bool modify = false;
double takeProfit;
@matthewkastor
matthewkastor / mql Open Sell Order.mq4
Created January 23, 2016 21:17
function for opening a Sell order in metatrader 4
// int result = OpenSellOrder(0.01, 0.00300, 0.00900);
int OpenSellOrder(double lots, double stopLossPips, double pipsProfit){
double takeProfit = NormalizeDouble(Bid - pipsProfit, Digits);
double stopLoss = NormalizeDouble(Bid + stopLossPips, Digits);
return OrderSend(Symbol(),OP_SELL,lots,Bid,3,stopLoss,takeProfit,"",MAGICMA,0,clrPink);
}
@matthewkastor
matthewkastor / mql Open Buy Order.mq4
Created January 23, 2016 21:16
function for placing a buy order in metatrader 4
// int result = OpenBuyOrder(0.01, 0.00300, 0.0900);
int OpenBuyOrder(double lots, double stopLossPips, double pipsProfit){
double takeProfit = NormalizeDouble(Ask + pipsProfit, Digits);
double stopLoss =NormalizeDouble(Ask - stopLossPips, Digits);
return OrderSend(Symbol(),OP_BUY,lots,Ask,3,stopLoss,takeProfit,"",MAGICMA,0,clrPurple);
}
@matthewkastor
matthewkastor / mql Get Current Range.mq4
Last active January 23, 2016 21:11
get the range of price from the given quantity of bars in metatrader 4
// Gets the range (highest minus lowest) of price for the last 5 bars
// double currentRange = CalculateCurrentRange(5);
double CalculateCurrentRange(int howManyBars){
double highVal;
double lowVal;
int highVal_index=iHighest(NULL,0,MODE_HIGH,howManyBars,0);
int lowVal_index=iLowest(NULL,0,MODE_LOW,howManyBars,0);
@matthewkastor
matthewkastor / mql Get ADX indicator.mq4
Created January 23, 2016 21:04
function for knowing whether the adx indicator is above or below the given threshold level in metatrader 4
// int adxIndicator = AdxIndicator(20, 14, 0);
int AdxIndicator(int adxThreshold, int period, int shift) {
double adx = iADX(Symbol(),PERIOD_CURRENT,period,PRICE_TYPICAL,MODE_MAIN,shift);
//double adxDiPlus = iADX(Symbol(),PERIOD_CURRENT,period,PRICE_TYPICAL,MODE_PLUSDI,shift);
//double adxDiMinus = iADX(Symbol(),PERIOD_CURRENT,period,PRICE_TYPICAL,MODE_MINUSDI,shift);
int output = 0;
@matthewkastor
matthewkastor / mql Get Candle Direction.mq4
Last active January 23, 2016 20:53
function for getting the candle direction in metatrader 4
//int candleDirection = CandleDirection(1);
int CandleDirection(int index){
int output = 0;
if(Open[index] < Close[index]) {
output = 1;
}
if(Open[index] > Close[index]) {
output = -1;
}
@matthewkastor
matthewkastor / mql Get Candle Strength.mq4
Last active January 23, 2016 20:54
function for analyzing whether the candle body is at least 30 percent of its height in metatrader 4
// bool candleIsStrong = CandleIsStrong(1);
bool CandleIsStrong(int index) {
bool output = false;
double totalHeight = High[index] - Low[index];
double bodyHeight = MathAbs(Open[index] - Close[index]);
if(totalHeight != 0 && bodyHeight != 0) {
output = ((totalHeight / bodyHeight) > 1.3);
}
@matthewkastor
matthewkastor / mql Get MACD.mq4
Last active January 23, 2016 21:07
functions for getting the MACD indicator in metatrader 4
input int MovingPeriod = 12;
input int MovingShift = 0;
double GetMacd(int mode, int period, int shift) {
int fastEmaPeriod = period / 2.1555;
int slowEmaPeriod = period;
int signalPeriod = (period / 2.1555) * 0.75;
return iMACD(Symbol(),0,fastEmaPeriod,slowEmaPeriod,signalPeriod,PRICE_TYPICAL,mode,shift);
}