Trading System & Source Code: Random Entries, Momentum Exits

Automated Trading Systems

Trading System & Source Code: Random Entries, Momentum Exits


asimon 06-20-2006, 5:00 PM

A presentation by GB007

http://woodiescciclub.com/vegas/gb007/gb007-vegas-2003.doc

He emphasizes the importance of money management by giving an example of a random entry trading system.

The system rules are as follows

  • At the beginning of a 5 minute candle, enter a long or short position randomly.
  • For a long trade, stay in the trade if the close of the current bar is higher than the close of the previous bar.
  • For a short trade, stay in the trade if the close of the current bar is lower than the close of the previous bar.

This system is supposed to make money by being long and short an equal number of times, but cutting the losses short and letting the profits run. I could not get positive confirmation with the file included in the demo. Perhaps testing over longer periods would get different results.

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

Source Code: Random Entries, Momentum Exits


asimon 07-29-2006, 7:57 AM

//
// 4X Lab.NET © Copyright 2005-2006 ASCSE LLC
// http://www.4xlab.net
// email: 4xlab@4xlab.net
//
using System;
namespace _4XLab.NET
{
   public class fRandomEntryMomentumExit : ForexObject
   {
      int Minutes;
      Random RNG;
      int randomint;
      sCandle OldCandle,NewCandle;
      double spread;
      cCandleBuilder cbx;


      public fRandomEntryMomentumExit()
      {
      }


      public override void Init(string pParameters)
      {
         this.InitializeParameters(pParameters,"MINUTES:5;");
         Minutes = (
int)PParser.GetDouble("MINUTES",0);
         RNG =
new Random();
         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"))
         {
            OldCandle = NewCandle;
            NewCandle = pCandle;
            DecisionFunction();
         }
      }

      private void DecisionFunction()
      {
         randomint = (
int)(RNG.NextDouble()*1000);
         switch (Framework.Account.InTrade())
         {
            case 0:
            {
               if (Framework.Account.InTrade()==0)
               {
                  if (EntryCriteriaLong())
                  {
                     Framework.Account.EnterTrade(1);
                  }
               }
               if (Framework.Account.InTrade()==0)
               {
                  if (EntryCriteriaShort())
                  {
                     Framework.Account.EnterTrade(-1);
                  }
               }
               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+","+NewCandle.C);
      }

      private bool EntryCriteriaLong()
      {
         bool v = false;
         if (randomint >= 500)
         {
            v =
true;
         }
         return v;
      }
   

      private bool EntryCriteriaShort()
      {
         bool v = false;
         if (randomint <= 500)
         {
            v =
true;
         }
         return v;
      }
   

      private bool ExitCriteriaLong()
      {
         bool v = false;
         if (NewCandle.C < OldCandle.C)
         {
            v =
true;
         }
         return v;
      }

      private bool ExitCriteriaShort()
      {
         bool v = false;
         if (NewCandle.C > OldCandle.C)
         {
            v =
true;
         }
         return v;
      }


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

      public override string Title()
      {
         return "Random Entries Momentum Exit";
      }


   }
}

Forex Lab .NET | 4X Lab .NET © Copyright 2005-2006 ASCSE LLC | Disclaimer

Powered by Community Server, by Telligent Systems