Home     News     Software     Order     Download     Support     Publications     Research     Contacts  
   Home

   News

  •  

  • Latest News
      
  •  

  • World News
      
  •  

  • Our achievements
      
       Software

  •  

  • TradeStation Solutions
      
  •  

  • Portfolio Software
      
  •  

  • Genetic Optimization
      
  •  

  • eSignal Solutions
      
  •  

  • Matlab & TradeStation Solutions
      
  •  

  • Excel & TradeStation Solutions
      
       Order

       Download

  •  

  • Free Download
      
  •  

  • Update
      
       Support

  •  

  • Online Help
      
  •  

  • Upgrade Policy
      
       Publications

  •  

  • Fractal dimension – numerical characteristic of trend
      
  •  

  • Volatility Models
      
  •  

  • Genetic optimization. Application in TradeStation environment.
      
  •  

  • Trading Systems Free
      
  •  

  • Money Management
      
       Research

  •  

  • TS Excel Link's using example
      
  •  

  • Strategy Optimization, Curve Fitting and Walk Forward Analysis.
      
  •  

  • Entropy Indicator in TradeStation using Matlab
      
  •  

  • TradeStaion Genetic Optimizer
      
  •  

  • Trading Strategy moving averages crossover based
      
  •  

  • System Code
      
  •  

  • Trading Strategy Result
      
  •  

  • Trading Strategy testing Out of Sample
      
       Contacts

    TradeStaion Genetic Optimizer: System Code

    EasyLanguage:
    {******************************************************************* 
    Name: TS.GO.12.Ex1 
    Analysis Type: Strategy 
    Description: Example Strategy for Genetic Optimizer v.1.x without Out of Sample 
    Example of simple trading system to show the possibilities of Genetic Optimizer for TradeStation. 
    The system is based on 2 moving average crossover.  
    Buy signal is generated when fast moving average crosses over slow moving average.  
    Additionaly Stop-loss is included in the system. 
    Used: TSGO12.dll 
    Provided By: Trade Smart Research (c) Copyright 2001 - 2004 
             www.tsresearchgroup.com 
    *******************************************************************}
     
     
    Inputs
    {Gen - input parameter, that assigns the number of generations. 
    Optimize in TradeStation with "Start = 1" and "Inc = 1"}
     
     Gen(1),  
     ShowInd(1), {ShowInd - number of individual in population to show} 
     ModeTSGO(0), 
     Population(50), 
     FreshBlood(0), 
     MyReportName("MySystem1"); 
         
     
    { Declaration of variables } 
    Vars: Len1(0),Len2(0),Len3(0),Len4(0),SL(0),DT(0),FA(0),PC(0), 
          Fitness(0),LastRun(0),R(0),K(0),Ind(0); 
      
    { ---------------------------------------------------------------------- } 
    { The Genetic Optimizer initialization and the definition of genes } 
     
    If CurrentBar = 1 Then Begin 
     
    { This block runs on every run of strategy on the first bar. 
     
      The function TS.GO.Start is called having the Parameter that defines 
      filename for milestones. 
      All the tunings of an optimizer and current population are stored in the 
      file, that allows to continue an optimization after break, or to draw 
      the input/output signals after the opening the TradeStation workspace with 
      the strategy. It is possible to open this file in graphic interface for viewing 
      population.}
     
     
        R = TS.GO.Start(MyReportName + "(" + GetSymbolName + ").rgo"); 
     
    { This block runs when the optimization is starting for the first bar only. } 
     
        If Gen = 1 Then Begin 
     
    { The initializing of optimizer determination of genes and the population 
      regime is executed (see the description of functions). 
      We start optimizer with empty population in a given example. }
     
     
            R = TS.GO.Mode(ModeTSGO); 
            R = TS.GO.Popul(Population); 
             R = TS.GO.FreshBlood(FreshBlood);  
     
    { Define User variables. } 
     
            R = TS.GO.Var("NetProfit"); 
            R = TS.GO.Var("PF"); 
            R = TS.GO.Var("MaxIDD"); 
     
    {***Sets up new chromosomes and new genes. 
      Chromosome Parameters: TS.GO.Chrom(Name)  
      Name ? name of chromosome. 
      Gene Parameters: TS.GO.Gen(Name,Chrom,Min,Max,Incr) 
      Name ? name of gene.  
      Chrom ? number of chromosome that contains gene (if 0 then gene doesn?t participate in mutations, it?s fixed).  
      Min ? minimal value of gene.  
      Max ? maximal value of gene.  
      Incr ? value increase (step), if = 0 then any values in set range can be used.***}
     
     
             
              K = TS.GO.Chrom("Buy.Signal"); 
            R = TS.GO.Gen("Buy.Signal.Len1",K,1,50,1); 
            R = TS.GO.Gen("Buy.Signal.Len2",K,1,50,1); 
     
            K = TS.GO.Chrom("Sell.Signal"); 
            R = TS.GO.Gen("Sell.Signal.Len3",K,1,50,1); 
            R = TS.GO.Gen("Sell.Signal.Len4",K,1,50,1); 
     
            K = TS.GO.Chrom("StopLoss"); 
            R = TS.GO.Gen("StopLoss.SL",K,1,1000,1); 
             
            K = TS.GO.Chrom("DollarTraling"); 
            R = TS.GO.Gen("DollarTraling.DT",K,1,1000,1); 
             
            K = TS.GO.Chrom("PercentTraling"); 
            R = TS.GO.Gen("PercentTraling.FA",K,1,1000,1); 
            R = TS.GO.Gen("PercentTraling.PC",K,1,100,1); 
             
        End;  
          
    { The generation of a new candidate in the population } 
     
        LastRun = TS.GO.Next(Gen); 
     
    { If this is the last path, shows results for Ind = ShowInd; 
      Else get the next candidate Ind = 0; }
     
     
        Ind = Iff(LastRun = 1,ShowInd,0); 
     
    { Get values of genes for choosen candidate. } 
     
        Len1 = TS.GO.Get("Buy.Signal.Len1",Ind); 
        Len2 = TS.GO.Get("Buy.Signal.Len2",Ind); 
        Len3 = TS.GO.Get("Sell.Signal.Len3",Ind); 
        Len4 = TS.GO.Get("Sell.Signal.Len4",Ind); 
        SL   = TS.GO.Get("StopLoss.SL",Ind); 
        DT   = TS.GO.Get("DollarTraling.DT",Ind); 
        FA   = TS.GO.Get("PercentTraling.FA",Ind); 
        PC   = TS.GO.Get("PercentTraling.PC",Ind); 
        R = TS.GO.ShowViewer
    End
     
    { ---------------------------------------------------------------------- } 
    { The basic strategy code. } 
     
    { Set up the stop-loss and traling-stop parameter. } 
     
    SetStopPosition
    SetStopLoss(SL); 
    SetDollarTrailing(DT); 
    SetPercentTrailing(FA,PC); 
     
    { The Moving Averages Calculation. } 
     
    Value1 = AverageFC(C,Len1); 
    Value2 = AverageFC(C,Len2); 
    Value3 = AverageFC(C,Len3); 
    Value4 = AverageFC(C,Len4); 
     
    { Generation of signals by moving averages crossover. 
      According to the signal, short positions are reversed to long positions and 
      vise versa. Besides, positions can be stopped by stop-loss and 
      trailing-stop orders. }
     
     
    if Value1 cross over  Value2 then Buy
    if Value3 cross below Value4 then Sell
     
    { End the basic strategy code. } 
    { ---------------------------------------------------------------------- } 
     
    { Calculation an optimization criteria. The simplest 
      criteria is used here. }
     
     
    Fitness = NetProfit + OpenPositionProfit
     
    if LastBarOnChart Then Begin 
     
    { Save user defined data. } 
         
        R = TS.GO.Set("NetProfit",NetProfit); 
        R = TS.GO.Set("PF",Iff(GrossLoss < 0,-GrossProfit/GrossLoss,0)); 
        R = TS.GO.Set("MaxIDD",MaxIDDrawDown); 
     
    { A fitness value is passed to the genetic optimizer on the last bar. 
      If the candidates are included in the current population depends on the 
      result of run. }
     
         
        R = TS.GO.Fitness(Fitness); 
     
    { One can look at all tested variants, assigning a print of the gene 
      values for each generation.  
      In PowerEditor in debug window to the debugger.}
     
     
        {print(Gen,Fitness,Len1,Len2,Len3,Len4,SL,DT,FA,PC);} 
    end
     
    {***** Copyright (c) 2001-2004 Trade Smart Research, Ltd. All rights reserved. www.tsresearchgroup.com ***** 
    ***** Trade Smart Research reserves the right to modify or overwrite this analysis technique  
          with each release. *****}
     
     
     

    To start Genetic Optimizer it is necessary to apply a strategy to a graph and to set optimization for parameter Gen from 1 to some large number with a step 1. The number defines how many generations will passed. Usually it is from hundreds to thousands.

    After the optimization start TradeStation alerts that input has a maximum value that is greater then the current MaxBarsBack setting. Do not care, push ?Continue? button.

    During the work TradeStation computes its own optimization criterion parallel to Genetic Optimizer that guided by a given fitness. Therefore optimal solution must not have the best TradeStation criterion value.


    <<< Trading Strategy moving averages crossover based
    Trading Strategy Result >>>


    Developed by: webdesign.tria.lv  

      About | Privacy Statement | Terms of use | TradeStation Disclaimer

    Copyright © 2004 TS Smart Research

    time: 0.0676 | queries: 3