Trading System & Source Code: Random Entries, Fixed Profit

Automated Trading Systems

Trading System & Source Code: Random Entries, Fixed Profit


asimon 06-10-2006, 2:25 PM

Random Entries System, Fixed Target Profit/Stop Loss

This is a crazy system, but gives interesting results. It is based on random entries. Each time a candle is received, the system flips a virtual coin and decides to go long or short. A fixed stop loss is set in place, and a fixed take profit is set at a multiple of the stop loss.

For example. MINUTES:5;STOP:0.0010;PROFIT:1;  specifies that 5 minute candles are to be used, a fixed stop loss of 10 pips is in place, and a take profit is set at a multiple of 1 times the stop loss, resulting in a 10pips order.

The trade is allowed to run until it hits the stop loss, or the take profit level, which might occur at any time.

Money Management techniques, which indicate to cut our losses and let our profits run might tempt us to use a PROFIT:3; parameter, to have take profit orders which are three times the size of the stop loss, ie: 10 pip stop loss, 30 pip take profit.

Experiments:

  • use MINUTES:5;STOP:0.0010;PROFIT:3;   run several times, note profitability.
  • use  MINUTES:5;STOP:0.0010;PROFIT:1;   run several times, note profitability.
  • use  MINUTES:5;STOP:0.0080;PROFIT:1;   run several times, note profitability.
  • use  MINUTES:5;STOP:0.0080;PROFIT:3;   run several times, note profitability

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

Source Code: Random Entries, Fixed Target Profit/Stop Loss


asimon 07-29-2006, 8:11 AM

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

      public fRandomEntryFixedProfit()
      {
      }

      public override void Init(string pParameters)
      {
         this.InitializeParameters(pParameters,"MINUTES:5;STOP:0.0003;PROFIT:3;");
         Minutes = (
int)PParser.GetDouble("MINUTES",0);
         iStopLoss = PParser.GetDouble("STOP",0);
         iTargetProfit = PParser.GetDouble("PROFIT",0) * iStopLoss;
         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"))
         {
            Candle = 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);
                     Framework.Account.SetStop(iStopLoss);
                     Framework.Account.SetTakeProfit(iTargetProfit);
                  }
               }
               if (Framework.Account.InTrade()==0)
               {
                  if (EntryCriteriaShort())
                  {
                     Framework.Account.EnterTrade(-1);
                     Framework.Account.SetStop(iStopLoss);
                     Framework.Account.SetTakeProfit(iTargetProfit);
                  }
               }
               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 (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 (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 "Random Entries Fixed Profit/Loss";
      }

   }
}

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

Powered by Community Server, by Telligent Systems