Welcome to 4XLab.NET : Forex Lab Community Server Sign in | Join | Faq

Automated Trading Systems

Started by asimon at 06-10-2006 1:46 PM. Topic has 1 replies.

Print Search
Sort Posts:    
   06-10-2006, 1:46 PM
asimon is not online. Last active: 1/23/2010 8:15:16 PM asimon

Top 10 Posts
Joined on 03-07-2006
Posts 140
Trading System & Source Code: X Length Channel Breakout

Introduction:

This is a very simple channel breakout trading system. It does not utilize bollinger bands to detect a breakout condition, but rather a threshold based on the maximum and minimum values of the last X candles. If the threshold is exceeded by the current candle, a trade is placed in the direction of the breakout. Once a trade is entered, a trailing stop with a fixed value takes us out.

Rules:

The rules of the trading system are the following:

  • For the last X candles, store the High and Low values.
  • If the closing value of the current candle is higher than the maximum value for the last X candles, BUY to open.
  • If the closing value of the current candle is lower than the minimum value for the last X candles, SELL to open.
  • Once a trade is opened, a trailing stop is put in place.

Run Results:

The system was optimized with the tick file shipped with the compiled version of the software and the following parameters:

MINUTES:5;CHANNEL:10-30;TRAILSTOP:0.0003-0.0020,0.0001;LOG:3

The end of run summary results are listed at the end of this post.

As you can see, the optimization captured a fundamental characteristic unique to this file that results in profitability when the system uses a channel length greater than 25 and a trailing stop of 17 or 19 pips. I do not like the fact that a stop of 18 pips does not result in profitable trades.

For the system to exhibit robustness, a channel length of greater than 25 and a traling stop of between 17 and 19 pips would have to result in profitability.

These are encouraging results, but more optimization runs need to be conducted with other tick files. 

You can download the compiled program, or create an account to download the source code

Program Output:

...

_4XLab.NET.fXChannelBreakout Ended
Analyzing Run Results
----------------------
Profitable Parameters:
MINUTES:5;CHANNEL:16;TRAILSTOP:0.002;
MINUTES:5;CHANNEL:21;TRAILSTOP:0.0019;
MINUTES:5;CHANNEL:22;TRAILSTOP:0.0017;
MINUTES:5;CHANNEL:25;TRAILSTOP:0.0017;
MINUTES:5;CHANNEL:25;TRAILSTOP:0.0019;
MINUTES:5;CHANNEL:26;TRAILSTOP:0.0017;
MINUTES:5;CHANNEL:26;TRAILSTOP:0.0019;
MINUTES:5;CHANNEL:27;TRAILSTOP:0.0017;
MINUTES:5;CHANNEL:27;TRAILSTOP:0.0019;
MINUTES:5;CHANNEL:28;TRAILSTOP:0.0017;
MINUTES:5;CHANNEL:28;TRAILSTOP:0.0019;
MINUTES:5;CHANNEL:29;TRAILSTOP:0.0017;
MINUTES:5;CHANNEL:29;TRAILSTOP:0.0019;
MINUTES:5;CHANNEL:30;TRAILSTOP:0.0017;
MINUTES:5;CHANNEL:30;TRAILSTOP:0.0019;
----------------------
----------------------------
For Maximum Margin Gain:
Tick Source: E:\MyDocs\Visual Studio Projects\4XLab.NET\bin\Debug\EUR_USD_Jan_2006_Week1_Small.csv
Parameters Sent: MINUTES:5;CHANNEL:29;TRAILSTOP:0.0019;LOG:3; AMG:1000;ALV:50;AAL:0.3;LOG:3;ACOC:0.03;AAPI:600;
Parameters Reported By Transform:MINUTES:5;CHANNEL:29;TRAILSTOP:0.0019;
Margin Stats: O:1000.00, H:1035.80, L:975.84, C:1010.27 Drawdown:-36.78
PIP Stats: Pips Captured:0.00100, H:0.00300, L:-0.00190 Drawdown:-0.00290
Volume moved on account:22138.48
Orders Placed:30
Winning Trades:8
Maximum Winning Streak:4
Losing Trades:7
Maximum Losing Streak:2
Maximum Gain:0.00380
Maximum Loss:-0.00190
Minimum Gain:0.00020
Minimum Loss:-0.00040
Average Gain:0.00116
Average Loss:-0.00119
Total Gain:0.00930
Total Loss:-0.00830
----------------------------
----------------------------
For Minimum Drawdown:
Tick Source: E:\MyDocs\Visual Studio Projects\4XLab.NET\bin\Debug\EUR_USD_Jan_2006_Week1_Small.csv
Parameters Sent: MINUTES:5;CHANNEL:25;TRAILSTOP:0.0017;LOG:3; AMG:1000;ALV:50;AAL:0.3;LOG:3;ACOC:0.03;AAPI:600;
Parameters Reported By Transform:MINUTES:5;CHANNEL:25;TRAILSTOP:0.0017;
Margin Stats: O:1000.00, H:1020.61, L:973.54, C:1000.45 Drawdown:-31.51
PIP Stats: Pips Captured:0.00020, H:0.00180, L:-0.00210 Drawdown:-0.00250
Volume moved on account:22377.94
Orders Placed:34
Winning Trades:8
Maximum Winning Streak:3
Losing Trades:9
Maximum Losing Streak:2
Maximum Gain:0.00240
Maximum Loss:-0.00170
Minimum Gain:0.00040
Minimum Loss:-0.00020
Average Gain:0.00114
Average Loss:-0.00099
Total Gain:0.00910
Total Loss:-0.00890
----------------------------
System Tester Ended


   Report 
   07-29-2006, 8:00 AM
asimon is not online. Last active: 1/23/2010 8:15:16 PM asimon

Top 10 Posts
Joined on 03-07-2006
Posts 140
Source Code: X Length Channel Breakout

//
// 4X Lab.NET © Copyright 2005-2006 ASCSE LLC
// http://www.4xlab.net
// email: 4xlab@4xlab.net
//
using System;
namespace _4XLab.NET
{
   public class fXChannelBreakout : ForexObject
   {
      int Minutes;
      int channel;
      double trailstop;
      iMinMax minmax;
      sCandle Candle;
      double spread;
      cCandleBuilder cbx;


      public fXChannelBreakout()
      {
      }

      public override void Init(string pParameters)
      {
         this.InitializeParameters(pParameters,"MINUTES:5;CHANNEL:25;TRAILSTOP:0.0010;");
         Minutes = (
int)PParser.GetDouble("MINUTES",0);
         channel = (
int)PParser.GetDouble("CHANNEL",0);
         trailstop = PParser.GetDouble("TRAILSTOP",0);
         minmax =
new iMinMax(2*channel);
         cbx =
new cCandleBuilder(Minutes,10); 
         Framework.TickServer.RegisterTickListener("cbx","*",cbx);
         cbx.RegisterCandleListener("cbx",
this);
         Framework.TickServer.RegisterTickListener("System","*",
this);
         Framework.WriteGraphLine("InTrade,Margin,C"); 
      }

      public override void ReceiveTick(sTick pTick)
      {
         spread = pTick.Ask - pTick.Bid;
      }

      public override void ReceiveCandle(sCandle pCandle, int pPeriod, string pCBTitle)
      {
         if ((pPeriod==Minutes) && (pCBTitle=="cbx"))
         {
            Candle = pCandle;
            if (minmax.isPrimed())
            {
               DecisionFunction();
            }
            // do not include current candle in Min/Max data
            // until after the decision function
            minmax.ReceiveTick(Candle.H);
            minmax.ReceiveTick(Candle.L);
         }
      }

      private void DecisionFunction()
      {
         switch (Framework.Account.InTrade())
         {
            case 0:
            {
               if (Framework.Account.InTrade()==0)
               {
                  if (EntryCriteriaLong())
                  {
                     Framework.Account.EnterTrade(1);
                     Framework.Account.SetTrailingStop(trailstop);
                  }
               }
               if (Framework.Account.InTrade()==0)
               {
                  if (EntryCriteriaShort())
                  {
                     Framework.Account.EnterTrade(-1);
                     Framework.Account.SetTrailingStop(trailstop);
                  }
               }
               break;
            }

            case 1:
            {
               if (ExitCriteriaLong())
               {
                  //Framework.Account.ExitTrade();
               }
               break;
            }

            case -1:
            {
               if (ExitCriteriaShort())
               {
                  //Framework.Account.ExitTrade();
               }
               break;
            }
         }

         double logInTrade = Framework.Account.InTrade();
         double logMargin = Framework.Account.GetAccount().C;
         //Framework.WriteGraphLine("InTrade,Margin,C"); 
         Framework.WriteGraphLine(logInTrade+","+logMargin+","+Candle.C);
      }

      private bool EntryCriteriaLong()
      {
         bool v = false;
         if (Candle.C > minmax.Max())
         {
            v =
true;
         }
         return v;
      }

      private bool EntryCriteriaShort()
      {
         bool v = false;
         if (Candle.C < minmax.Min())
         {
            v =
true;
         }
         return v;
      }

      private bool ExitCriteriaLong()
      {
         bool v = false;
         if (v)
         {
            v =
true;
         }
         return v;
      }

      private bool ExitCriteriaShort()
      {
         bool v = false;
         if (v)
         {
            v =
true;
         }
         return v;
      }

      public override bool Finished()
      {
         bool returnv = true;
         return returnv;
      }

      public override string Title()
      {
      return "X Length Channel Breakout";
      }

   }
}


   Report 
4XLab.NET : For... » 4XLab.NET » Automated Tradi... » Trading System & Source Code: X Length Channel Breakout

Powered by Community Server, by Telligent Systems