/*------------------------------------------------------------------------------- Trading Strategy Code Population member: 156 Max bars back: 100 Created by: Adaptrade Builder version 1.7.2.1 Created: 2/19/2015 5:46:07 AM Scripting language: MetaTrader 4 (MQL4) Price files: EURUSD-240-TS.txt EURUSD240.csv Build dates: 11/14/2011 to 12/12/2013 Project file: C:\...\Adaptrade\HybridNN\HybridNN.gpstrat -------------------------------------------------------------------------------*/ #include #define STRATORDERID 1522042 // Strategy inputs extern int NL1 = 16; // Indicator look-back length (bars), long trades extern int NL2 = 5; // Day of week (0 to 6 for Sunday to Saturday), long trades extern int NL3 = 18; // Indicator look-back length (bars), long trades extern int NL4 = 81; // Indicator look-back length (bars), long trades extern int NL5 = 3; // Number of standard deviations, long trades extern int NL6 = 4; // Indicator look-back length (bars), long trades extern int NL7 = 100; // Indicator look-back length (bars), long trades extern int NL8 = 57; // Indicator look-back length (bars), long trades extern int NL9 = 62; // Indicator look-back length (bars), long trades extern int NL10 = 67; // Indicator look-back length (bars), long trades extern int NL11 = 34; // Indicator look-back length (bars), long trades extern int NL12 = 4; // Day of week (0 to 6 for Sunday to Saturday), long trades extern int ShiftL1 = 13; // Indicator shift value (bars), long trades extern int ShiftL2 = 17; // Indicator shift value (bars), long trades extern int ShiftL3 = 14; // Indicator shift value (bars), long trades extern int ShiftL4 = 15; // Indicator shift value (bars), long trades extern int ShiftL5 = 19; // Indicator shift value (bars), long trades extern int NS1 = 59; // Indicator look-back length (bars), short trades extern int NS2 = 5; // Price pattern look-back length (bars), short trades extern double Wgt1 = -0.1480; // Neural network weight value (-1 to 1) extern double Wgt2 = -0.2172; // Neural network weight value (-1 to 1) extern double Wgt3 = -0.4254; // Neural network weight value (-1 to 1) extern double Wgt4 = -0.5144; // Neural network weight value (-1 to 1) extern double Wgt5 = -0.0287; // Neural network weight value (-1 to 1) extern double Wgt6 = 0.2224; // Neural network weight value (-1 to 1) extern double Wgt7 = -0.3087; // Neural network weight value (-1 to 1) extern double Wgt8 = -0.5567; // Neural network weight value (-1 to 1) extern double Wgt9 = 0.2203; // Neural network weight value (-1 to 1) extern double Wgt10 = -0.5853; // Neural network weight value (-1 to 1) extern double PSParam = 100000.00; // Position sizing parameter value extern bool RoundPS = true; // Round-to-nearest (true/false) extern int RoundTo = 1; // Round-to position size value extern int MinSize = 1; // Minimum allowable position size extern int SizeLimit = 100000; // Maximum allowable position size // Global strategy variables int MaxBarsBack = 100; double PointValue = 1.000000; int MaxSlippage = 3; double SharesPerLot = 100000; // Main strategy code void OnTick() { if (IsTradeAllowed() && Bars >= MaxBarsBack) { ManageOrders(Symbol(), STRATORDERID, MaxSlippage); if (Volume[0] <= 1) { // Entry and exit conditions double VarL1 = iATR(NULL, 0, 1, 1); double VarL2 = iStdDev(NULL, 0, NL1, 0, MODE_SMA, PRICE_HIGH, ShiftL1 + 1); double VarS1 = iATR(NULL, 0, NS1, 1); double VarS2 = High[NS2 + 1]; double VarS3 = VarS1 + VarS2; double VarS4 = DayLow(); bool EntCondL = VarL1 < VarL2; bool EntCondS = VarS3 > VarS4; // Neural network inputs double NNInputs[10]; double VarL3 = TimeDayOfWeek(Time[1]); double VarL10 = iCustom(NULL, 0, "ZLTrend", PRICE_HIGH, NL9, 0, ShiftL4); double VarL11 = DayHigh(); double VarL15 = TimeDayOfWeek(Time[1]); NNInputs[0] = VarL3 - NL2; NNInputs[1] = iCustom(NULL, 0, "InvFisherCycle", PRICE_OPEN, NL3, 0, 0); NNInputs[2] = iBands(NULL, 0, NL4, NL5, 0, PRICE_LOW, MODE_UPPER, 1); NNInputs[3] = iCustom(NULL, 0, "InvFisherRSI", PRICE_LOW, NL6, 0, ShiftL2); NNInputs[4] = iCustom(NULL, 0, "InvFisherCycle", PRICE_LOW, NL7, 0, 0); NNInputs[5] = iCustom(NULL, 0, "ZLTrend", PRICE_HIGH, NL8, 0, ShiftL3); NNInputs[6] = VarL10 - VarL11; NNInputs[7] = iStdDev(NULL, 0, NL10, 0, MODE_SMA, PRICE_OPEN, 1); NNInputs[8] = iCustom(NULL, 0, "InvFisherRSI", PRICE_OPEN, NL11, 0, ShiftL5); NNInputs[9] = VarL15 - NL12; // Evaluate neural network function double NNWeights[10]; NNWeights[0] = Wgt1; NNWeights[1] = Wgt2; NNWeights[2] = Wgt3; NNWeights[3] = Wgt4; NNWeights[4] = Wgt5; NNWeights[5] = Wgt6; NNWeights[6] = Wgt7; NNWeights[7] = Wgt8; NNWeights[8] = Wgt9; NNWeights[9] = Wgt10; double NNOutput = NNCompute(NNInputs, 10, NNWeights, 10, 100); // Position sizing calculations double NShares = PSParam; if (RoundPS && RoundTo > 0) NShares = MathFloor(NShares/RoundTo) * RoundTo; NShares = MathMax(NShares, MinSize); NShares = MathMin(NShares, SizeLimit); double Lots = NShares/SharesPerLot; // Prepare to place trading orders int MarketPosition = CurrentPosition(); double InitialStop = 0; // Entry orders if (EntCondL && NNOutput >= 0.5) { EnterLongMarket(Symbol(), Lots, InitialStop, MarketPosition, MaxSlippage, STRATORDERID); } if (EntCondS && NNOutput <= -0.5) { EnterShortMarket(Symbol(), Lots, InitialStop, MarketPosition, MaxSlippage, STRATORDERID); } } } }