support.tsresearchgroup.com Forum Index

TSResearch | Software Products | Online Help | Free Download | Publications | Research

Username:   Password:   
Log me on automatically each visit
 

FAQ |  Search |  Memberlist |  Usergroups |  Profile |  Log in to check your private messages  Register |  Log in 

System building from blocks (units).
Goto page 1, 2  Next
 
Post new topic   Reply to topic    support.tsresearchgroup.com Forum Index -> TS Genetic Optimizer for TradeStation
View previous topic :: View next topic  
Author Message
VladGor
Support Team


Joined: 26 Jan 2004
Posts: 528

PostPosted: Fri Mar 12, 2004 12:14 pm    Post subject: System building from blocks (units). Reply with quote

System building from blocks (units).
(for discussing)

With the new optimizer the ability of strategy building from several signal became available, as it is available in the Omega Strategy Builder.

The idea of the approach.

Strategy is built from the different separate signals, implied in a special way. The difference from the regular signal (as it is in Omega) is that GO signal has in its beginning the block code which defines optimizable signal parameters (genes) and sample of the parameters values from the optimizer.

At the same time signal might not has any external parameters (operator Input).

Optimization is controlled from the separate block (signal), which is also included in strategy. This block is universal and might control the optimization with any sample of signals.

The control block has at least Gen parameter. Also it might have parameters for size population defining, for operating mode defining and so on.

This block organizes optimization for every signal. In this block OOS as well as WFO might be implemented in the future.

It is possible to include in the release standard block configuration so a client will just have to define his own signals.

The block is might included fitness calculation by using standard algorithms. Also it’s possible to implement an additional block (signal) for non-standard fitness calculation and also include this block into the strategy.

The example of the control block TS.GO.Manager
EasyLanguage:
Input: Gen(1),Show(0),ModeGO(0),NPop(50),FB(0),OOS(1);  
Vars: Fitness(0),R(0); 
  
If CurrentBar = 1 Then Begin 
    R = TS.GO.Start(GetStrategyName + "(" + GetSymbolName + ").rgo"); 
    If Gen = 1 Then Begin 
        R = TS.GO.Mode(ModeGO); 
        R = TS.GO.Popul(NPop); 
        R = TS.GO.FreshBlood(FB);  
     End;  
    R = TS.GO.Next(Gen); 
    R = TS.GO.Set("Show",Iff(R=1,Show,0)); 
    R = TS.GO.Set("Generation",Gen); 
End
 
if LastBarOnChart Then Begin 
    R = TS.GO.Set("NetProfit",NetProfit); 
    R = TS.GO.Set("PF",Iff(GrossLoss < 0,-GrossProfit/GrossLoss,0)); 
    R = TS.GO.Set("MaxIDD",MaxIDDrawDown); 
    R = TS.GO.Set("TotalTrades",TotalTrades); 
    R = TS.GO.Set("PercentProfit",PercentProfit); 
    R = TS.GO.Set("LargestWinTrade",LargestWinTrade); 
    R = TS.GO.Set("LargestLosTrade",LargestLosTrade); 
 
    Fitness = NetProfit - LargestWinTrade
    R = TS.GO.Fitness(Fitness); 
end

In this version control block does the following: transfers works parameters to the optimizer, generates new candidate or show chosen one, calculates/saves some statistic about the system, calculates optimization criteria and transfers signals to the optimizer.

For signal control, control block saves 2 parameters:
- Gen – current gene number.
- Show – current unit number for displaying.

TS.GO.MA4 signal example.
EasyLanguage:
Vars: Gen(0),Show(0),R(0),K(0); 
Vars: Len1(1),Len2(1),Len3(1),Len4(1),SL(0); 
 
If CurrentBar = 1 Then Begin 
    Gen  = TS.GO.Get("Generation",0); 
    Show = TS.GO.Get("Show",0); 
    If Gen = 1 Then Begin 
        K = TS.GO.Chrom("MA4.Buy.Signal"); 
        R = TS.GO.Gen("MA4.Len1",K,0,49,1); 
        R = TS.GO.Gen("MA4.Len2",K,0,49,1); 
     
        K = TS.GO.Chrom("MA4.Sell.Signal"); 
        R = TS.GO.Gen("MA4.Len3",K,0,49,1); 
        R = TS.GO.Gen("MA4.Len4",K,0,49,1); 
     
        K = TS.GO.Chrom("MA4.StopLoss"); 
        R = TS.GO.Gen("MA4.SL",K,100,10000,100); 
    End
    Len1 = TS.GO.Get("MA4.Len1",Show)+1; 
    Len2 = TS.GO.Get("MA4.Len2",Show)+1; 
    Len3 = TS.GO.Get("MA4.Len3",Show)+1; 
    Len4 = TS.GO.Get("MA4.Len4",Show)+1; 
    SL   = TS.GO.Get("MA4.SL"  ,Show); 
End
 
SetStopPosition
SetStopLoss(SL); 
 
Value1 = Average(C,Len1); 
Value2 = Average(C,Len2); 
Value3 = Average(C,Len3); 
Value4 = Average(C,Len4); 
 
if Value1 cross over  Value2 then Buy This Bar ; 
if Value3 cross below Value4 then Sell Short This Bar ; 

In the beginning of the code, there is a block which on the first bar of the first loop step defines signal genes, and on the first bar or an each following loop step defines genes values.

Then regular signal is following.

The example of the conversion regular signal to the GO signal
Source code for ATR Trailing LX signal

EasyLanguage:
{******************************************************************* 
Description    : ATR Trailing Stop Long Exit 
Provided By    : Omega Research, Inc. (c) Copyright 1999  
********************************************************************}
 
 
Inputs: ATRs(3); 
Variables: PosHigh(0), ATRVal(0); 
 
ATRVal = AvgTrueRange(10) * ATRs; 
 
If BarsSinceEntry = 0 Then 
    PosHigh = High
 
If MarketPosition = 1 Then Begin 
    If High > PosHigh Then 
        PosHigh = High
    ExitLong ("ATR"Next Bar at PosHigh - ATRVal Stop
End 
else 
    ExitLong ("ATR eb"Next bar at High - ATRVal Stop

Conversion results TS.ATR Trailing LX
EasyLanguage:
{******************************************************************* 
Description    : ATR Trailing Stop Long Exit 
Provided By    : Omega Research, Inc. (c) Copyright 1999  
Provided By    : TS Research (c) Copyright 2004 
********************************************************************}
 
Vars: ATRs(3),ATRlen(10); 
 
Vars: Gen(0),Show(0),R(0),K(0); 
If CurrentBar = 1 Then Begin 
    Gen  = TS.GO.Get("Generation",0); 
    Show = TS.GO.Get("Show",0); 
    If Gen = 1 Then Begin 
        K = TS.GO.Chrom("ATR Trailing LX"); 
        R = TS.GO.Gen("ATR.LX.Len",K,0,49,1); 
        R = TS.GO.Gen("ATR.LX.ATRs",K,1,50,0.5); 
    End
    ATRs   = TS.GO.Get("ATR.LX.ATRs",Show); 
    ATRlen = TS.GO.Get("ATR.LX.Len",Show)+1; 
End
 
Vars: PosHigh(0), ATRVal(0); 
 
ATRVal = AvgTrueRange(ATRlen) * ATRs; 
 
If BarsSinceEntry = 0 Then 
    PosHigh = High
 
If MarketPosition = 1 Then Begin 
    If High > PosHigh Then 
        PosHigh = High
    Sell ("ATR"Next Bar at PosHigh - ATRVal Stop
End 
else 
    Sell ("ATR eb"Next bar at High - ATRVal Stop

Strategy in TS2000 or groups of them in TS& might consist from the following signals:
- TS.GO.Manager – optimization manages.
- TS.GO.MA4 – main signal form inputs.
- TS.ATR Trailing LX - trailing exit.
- TS.ATR Trailing SX - trailing exit.
Back to top
View user's profile Send private message
kshultz
Guest


Joined: 12 Apr 2004
Posts: 12

PostPosted: Thu May 06, 2004 6:02 pm    Post subject: Reply with quote

I am still unclear as to the purpose of the variable: 'show' or 'showind'
" { If this is the last path, shows results for Ind = ShowInd;
Else get the next candidate Ind = 0; }
Ind = Iff(LastRun = 1,ShowInd,0); "

What is the impact or difference between using different values for showind? using 1 or using say, 10 with Gen = 1 to 1000?

Thank you
Back to top
View user's profile Send private message
VladGor
Support Team


Joined: 26 Jan 2004
Posts: 528

PostPosted: Fri May 07, 2004 9:57 am    Post subject: Reply with quote

Quote:
I am still unclear as to the purpose of the variable: 'show' or 'showind'
" { If this is the last path, shows results for Ind = ShowInd;
Else get the next candidate Ind = 0; }
Ind = Iff(LastRun = 1,ShowInd,0); "

What is the impact or difference between using different values for showind? using 1 or using say, 10 with Gen = 1 to 1000?


Variable Ind is used in functions that get value of gene before run of the system, for example:

ATRs = TS.GO.Get("ATR.LX.ATRs", Ind);

Second parameter of function TS.GO.Get sets the number of sample, for which value of gene is read.

On all runs exept the last Ind = 0.
This value is processed in function TS.GO.Get in special way and usually means reading the value of gene for the tested candidate of population.

Variable ShowInd sets the value of variable Ind at the last run of the system when optimization is already finished and chart with signals is getting drawn. Variable ShowInd sets NUMBER of sample in population which will be shown on chart after optimization is finished.
Back to top
View user's profile Send private message
kshultz
Guest


Joined: 12 Apr 2004
Posts: 12

PostPosted: Mon Jan 10, 2005 6:01 pm    Post subject: Reply with quote

This does not really answer my question. Please show an example of code using two different signals, for example the moving average cross over you show as an example and the addition of another signal, like an RSI, testing whether or not one is better than another combined or separate, for different inputs ( example for RSI might be inputs for RSILength, OverBoughtLevel, OverSold Level). In other words, MA Cross might be better with RSI above OB or below OS or RSI might be better than MA by itself. Might even want to test several signals with different input values. Thank you ks
Back to top
View user's profile Send private message
Mak
Developers Team


Joined: 26 Jan 2004
Posts: 465

PostPosted: Tue Jan 11, 2005 1:51 am    Post subject: Reply with quote

If we correctly understood your question then example is below.
We call it structural optimization that is optimization not only on parameters but also on system content.

For that in every signal one additional gene is added with two positions (On/Off) that manages the state of signal:
EasyLanguage:
R = TS.GO.Gen("MAL.On/Off",K,0,1,1);


Code of signal is placed in block:

EasyLanguage:
 
If MA_On > 0 Then Begin 
    .......... 
    Code of signal 
    ........ 
End


As a result TS.GO can turn on and off different signals in the system.

In the same time all parameters are optimized in the system, also for signals that are turned off at that time. That doesn't bother work of TS.GO, only decreases effectivness of optimization.


(See example below)

The example of the control block TS.GO.Manager

EasyLanguage:
Input: Gen(1),Show(0),ModeGO(0),NPop(50),FB(0),OOS(1);   
Vars: Fitness(0),R(0);  
   
If CurrentBar = 1 Then Begin  
    R = TS.GO.Start(GetStrategyName + "(" + GetSymbolName + ").rgo");  
    If Gen = 1 Then Begin  
        R = TS.GO.Mode(ModeGO);  
        R = TS.GO.Popul(NPop);  
        R = TS.GO.FreshBlood(FB);   
     End;   
    R = TS.GO.Next(Gen);  
    R = TS.GO.Set("Show",Iff(R=1,Show,0));  
    R = TS.GO.Set("Generation",Gen);  
End;  
  
if LastBarOnChart Then Begin  
    R = TS.GO.Set("NetProfit",NetProfit);  
    R = TS.GO.Set("PF",Iff(GrossLoss < 0,-GrossProfit/GrossLoss,0));  
    R = TS.GO.Set("MaxIDD",MaxIDDrawDown);  
    R = TS.GO.Set("TotalTrades",TotalTrades);  
    R = TS.GO.Set("PercentProfit",PercentProfit);  
    R = TS.GO.Set("LargestWinTrade",LargestWinTrade);  
    R = TS.GO.Set("LargestLosTrade",LargestLosTrade);  
  
    Fitness = NetProfit - LargestWinTrade;  
    R = TS.GO.Fitness(Fitness);  
end



TS.GO.MAL signal

EasyLanguage:
Vars: Gen(0),Show(0),R(0),K(0);  
Vars: Len1(1),Len2(1),MA_On(1);  
  
If CurrentBar = 1 Then Begin  
    Gen  = TS.GO.Get("Generation",0);  
    Show = TS.GO.Get("Show",0);  
    If Gen = 1 Then Begin  
        K = TS.GO.Chrom("MAL");  
    R = TS.GO.Gen("MAL.On/Off",K,0,1,1);  
        R = TS.GO.Gen("MAL.Len1",K,0,49,1);  
        R = TS.GO.Gen("MAL.Len2",K,0,49,1);  
    End;  
    MA_On = TS.GO.Get("MAL.On/Off",Show);  
    Len1  = TS.GO.Get("MAL.Len1",Show)+1;  
    Len2  = TS.GO.Get("MAL.Len2",Show)+1;  
End;  
  
If MA_On > 0 Then Begin 
    Value1 = Average(C,Len1);  
    Value2 = Average(C,Len2);  
    if Value1 cross over Value2 then Buy ("MAL"This Bar ;  
End



TS.GO.MAS signal

EasyLanguage:
Vars: Gen(0),Show(0),R(0),K(0);  
Vars: Len1(1),Len2(1),MA_On(1);  
  
If CurrentBar = 1 Then Begin  
    Gen  = TS.GO.Get("Generation",0);  
    Show = TS.GO.Get("Show",0);  
    If Gen = 1 Then Begin  
        K = TS.GO.Chrom("MAS");  
    R = TS.GO.Gen("MAS.On/Off",K,0,1,1);  
        R = TS.GO.Gen("MAS.Len1",K,0,49,1);  
        R = TS.GO.Gen("MAS.Len2",K,0,49,1);  
    End;  
    MA_On = TS.GO.Get("MAS.On/Off",Show);  
    Len1  = TS.GO.Get("MAS.Len1",Show)+1;  
    Len2  = TS.GO.Get("MAS.Len2",Show)+1;  
End;  
  
If MA_On > 0 Then Begin 
    Value1 = Average(C,Len1);  
    Value2 = Average(C,Len2);  
    if Value1 cross below Value2 then Sell Short ("MAS"This Bar ;  
End
Back to top
View user's profile Send private message
kshultz
Guest


Joined: 12 Apr 2004
Posts: 12

PostPosted: Tue Jan 11, 2005 2:31 am    Post subject: Reply with quote

How to combine 2 signals in one GO evaluation?
EasyLanguage:
var:MASell(false), MABuy(false), RSISell(false), RSIBuy(false); 
 
// MA block 
If MA_On = 0 Then Begin  
MASell=false
 MABuy =false
end
 
Value1 = Average(C,Len1);  
Value2 = Average(C,Len2);  
If MA_On =1Then Begin  
 
MABuy =  Value1 cross below Value2; 
MASell =  Value1 cross above Value2; 
end
If MA_On =2 Then Begin  
MABuy =  Value1 cross above Value2; 
MASell =  Value1 cross below Value2; 
end
 
//RSI block 
if RSI_on  = 0Then Begin 
RSISell =false
RSIBuy=false
end
value3 = RSI(price,RsiLen); 
 
if RSI_on = 1 Then Begin 
value3 = RSI(price,RsiLen); 
RSISell = value3 > OBLevel; 
RSIBuy = value3 < OSoldLevel; 
end
if RSI_on = 2 Then Begin 
value3 = RSI(price,RsiLen); 
RSISell = value3 < OBLevel; 
RSIBuy = value3 > OSoldLevel; 
end
if (RSIBuy and MABuy) or RSIBuy or MABuy then Buy this bar
if (RSISell and MASell) or RSISell or MASell then Sell short this bar
/////  end of sample


Starts getting pretty complicated, even more so with more signals to combine. Too many permutations. I don't know if this would even test all the possibilities?? Ken
Back to top
View user's profile Send private message
Mak
Developers Team


Joined: 26 Jan 2004
Posts: 465

PostPosted: Tue Jan 11, 2005 9:17 am    Post subject: Reply with quote

Well ...
It's not a TS.GO problem.
It's EasyLanguage programming problem ..

The next code have the same result,
but allow combine any number of signals.

EasyLanguage:
Var: SellSig(false), BuySig(false);  
  
SellSig = false;  
BuySig  = false;  
 
//MA block  
Value1 = Average(C,Len1);   
Value2 = Average(C,Len2);   
If MA_On = 1 Then Begin   
    BuySig  = Iff(BuySig,  True, Value1 cross below Value2);  
    SellSig = Iff(SellSig, True, Value1 cross above Value2);  
end;  
If MA_On =2 Then Begin   
    BuySig  = Iff(BuySig,  True, Value1 cross above Value2);  
    SellSig = Iff(SellSig, True, Value1 cross below Value2);  
end;  
  
//RSI block  
Value3 = RSI(Price,RsiLen);  
if RSI_on = 1 Then Begin  
    BuySig  = Iff(BuySig,  True, value3 < OSoldLevel);  
    SellSig = Iff(SellSig, True, value3 > OBLevel);  
end;  
if RSI_on = 2 Then Begin  
    BuySig  = Iff(BuySig,  True, value3 > OSoldLevel);  
    SellSig = Iff(SellSig, True, value3 < OBLevel);  
end;  
 
//MACD block  
................ 
............... 
 
if BuySig  then Buy this bar;  
if SellSig then Sell short this bar


But in blocks we use another code,
It's more simple and more useful.
For example, in this case you can use separate signals
and can use pyramiding ...

EasyLanguage:
//MA block  
Value1 = Average(C,Len1);   
Value2 = Average(C,Len2);   
If MA_On = 1 Then Begin   
    If Value1 cross below Value2 Then Buy;  
    If Value1 cross above Value2 Then Sell Short;  
end;  
If MA_On =2 Then Begin   
    If Value1 cross above Value2 Then Buy;  
    If Value1 cross below Value2 Then Sell Short;  
end;  
  
//RSI block  
Value3 = RSI(Price,RsiLen);  
if RSI_on = 1 Then Begin  
    If value3 < OSoldLevel Then Buy;  
    If value3 > OBLevel    Then Sell Short;  
end;  
if RSI_on = 2 Then Begin  
    If value3 > OSoldLevel Then Buy;  
    If value3 < OBLevel    Then Sell Short;  
end;  
 
//MACD block  
................ 
............... 


Sorry if I can't understend your question again ...
Back to top
View user's profile Send private message
kshultz
Guest


Joined: 12 Apr 2004
Posts: 12

PostPosted: Tue Jan 11, 2005 7:20 pm    Post subject: Reply with quote

Thank you, I think that will work. I will try it. ken
Back to top
View user's profile Send private message
krc
Guest


Joined: 02 Nov 2005
Posts: 8

PostPosted: Tue Nov 15, 2005 9:35 pm    Post subject: constructing systems from blocks Reply with quote

The following code actually runs with the optimizer but I'd like to be able to abstract the method and use something like the TSGO.Manager to allow a more orderly approach. The difficulty is that I want all three rules to be valid in order to enter a position. Today the TSGO.Manager passes this decision to the children. I'd also like to switch between (optimize) the entry type (market, limit, stop, etc.)

EasyLanguage:
inputs
    ruleA(1), 
    ruleB(1), 
    ruleC(1), 
    modelType(1),  
    parms2(1), 
    parms3(1), 
    parms4(1), 
    parms5(1), 
    parms6(1), 
    parms7(1), 
    parms8(1), 
    mLB1(1), 
    mLB2(1), 
    mLB3(1), 
    ATRs(4), 
    mmATRs(1); 
 
vars
    price(0), 
    lb1(0), 
    lb2(0), 
    bRuleA(false), 
    bRuleB(false), 
    bRuleC(false), 
    mom(0), 
    BullCr(false), 
    BearCr(false), 
    oDMIPlus( 0 ),  
    oDMIMinus( 0 ),  
    oDMI( 0 ),  
    oADX( 0 ),  
    oADXR( 0 ),  
    oVolty( 0 ), 
    oFastK( 0 ), 
    oFastD( 0 ), 
    oSlowK( 0 ), 
    oSlowD( 0 ), 
    myDMI( 0 ), 
    myStoch( 0 ), 
    myMACD( 0 ), 
    MACDAvg( 0 ), 
    MACDDiff( 0 ), 
    myATR(0), 
    ATRVal(0), 
    EntryATR(0), 
    posHigh(0), 
    posLow(0), 
    dummy(0); 
 
 
//setup 
price = close
myDMI = DirMovement( HLC, 14, oDMIPlus, oDMIMinus, oDMI, oADX, oADXR, oVolty ) ; 
myStoch = Stochastic(HLC, 14, 3, 3, 1, oFastK, oFastD, oSlowK, oSlowD ) ; 
MyMACD = MACDClose, mLB1, mLB2 ); 
MACDAvg = XAverage( MyMACD, 9 ) ; 
MACDDiff = MyMACD - MACDAvg ; 
MyATR = AvgTrueRange(10) * ATRs; 
ATRVal = AvgTrueRange(10) * mmATRs; 
Mom = Average(Momentum(close, mLB3), 3); 
BullCr = Mom Crosses Over 0; 
BearCr = Mom Crosses Under 0; 
 
//RuleA 
 
//case1 :: momentum crossover 
if ruleA = 1 then begin 
    if modelType = 1 then begin 
        bRuleA = BullCr AND (MRO(BearCR, 4, 1) = -1); 
    end else 
    if modelType = 2 then begin 
        bRuleA = BearCr AND (MRO(BullCR, 4, 1) = -1); 
    end
end
 
//case2 :: Price to SMA comparison 
If ruleA = 2 then begin 
    If modelType = 1 then begin 
        bRuleA = Price > AverageFC(Price,parms2); 
    end else 
    If modelType = 2 then begin 
        bRuleA = Price < AverageFC(Price,parms2); 
    end;     
end
 
//case3 :: Price to exponential MA comparison 
If ruleA = 3 then begin 
    If modelType = 1 then begin 
        bRuleA = Price > xAverage(Price,parms2); 
    end else 
    If modelType = 2 then begin 
        bRuleA = Price < xAverage(Price,parms2); 
    end;     
end
 
//case4 :: OI above linRegr 
If ruleA = 4 then  
        bRuleA = OpenInt > (LinearRegValueOpenInt, parms2, 0 )* (1+(parms3/100))); 
 
//case5 :: OI below linRegr 
If ruleA = 5 then  
        bRuleA = OpenInt < (LinearRegValueOpenInt, parms2, 0 )* (1-(parms3/100))); 
 
//case6 :: recent new highs 
If ruleA = 6 then 
    bRuleA = High > Highest(High,parms2)[1];     
 
//case7 :: recent new lows 
If ruleA = 7 then 
    bRuleA = Low < Lowest(Low,parms2)[1]; 
 
//case8 :: DMI test 
If ruleA = 8 then 
        bRuleA = oADX > parms2 AND oADX < parms3; 
 
//case9 :: Slow %K Test 
If ruleA = 9 then  
    bRuleA = oSlowK > parms2 AND oSlowK < parms3; 
 
//case10 :: macd slope direction 
If ruleA = 10 then begin 
    If modelType = 1 then begin 
        bRuleA = MACDAvg > MACDAvg[1] AND MACDAvg[1] > MACDAvg[2]; 
    end else 
    If modelType = 2 then begin 
        bRuleA = MACDAvg < MACDAvg[1] AND MACDAvg[1] < MACDAvg[2]; 
    end;     
end
 
//RuleB 
 
//case1 :: momentum crossover 
if ruleB = 1 then begin 
    if modelType = 1 then begin 
        bRuleB = BullCr AND (MRO(BearCR, 4, 1) = -1); 
    end else 
    if modelType = 2 then begin 
        bRuleB = BearCr AND (MRO(BullCR, 4, 1) = -1); 
    end
end
 
//case2 :: Price to SMA comparison 
If ruleB = 2 then begin 
    If modelType = 1 then begin 
        bRuleB = Price > AverageFC(Price,parms5); 
    end else 
    If modelType = 2 then begin 
        bRuleB = Price < AverageFC(Price,parms5); 
    end;     
end
 
//case3 :: Price to exponential MA comparison 
If ruleB = 3 then begin 
    If modelType = 1 then begin 
        bRuleB = Price > xAverage(Price,parms5); 
    end else 
    If modelType = 2 then begin 
        bRuleB = Price < xAverage(Price,parms5); 
    end;     
end
 
//case4 :: OI above linRegr 
If ruleB = 4 then  
        bRuleB = OpenInt > (LinearRegValueOpenInt, parms5, 0 )* (1+(parms6/100))); 
 
//case5 :: OI below linRegr 
If ruleB = 5 then  
        bRuleB = OpenInt < (LinearRegValueOpenInt, parms5, 0 )* (1-(parms6/100))); 
 
//case6 :: recent new highs 
If ruleB = 6 then 
    bRuleB = High > Highest(High,parms5)[1];     
 
//case7 :: recent new lows 
If ruleB = 7 then 
    bRuleB = Low < Lowest(Low,parms5)[1]; 
 
//case8 :: DMI test 
If ruleB = 8 then 
        bRuleB = oADX > parms5 AND oADX < parms6; 
{    end else 
    If modelType = 2 then begin 
        bRuleA = oADX > parms2 AND oDMIPlus < oDMIMinus; 
    end;     
end;}
 
 
//case9 :: Slow %K Test 
If ruleB = 9 then  
    bRuleB = oSlowK > parms5 AND oSlowK < parms6; 
 
//case10 :: macd slope direction 
If ruleB = 10 then begin 
    If modelType = 1 then begin 
        bRuleB = MACDAvg > MACDAvg[1] AND MACDAvg[1] > MACDAvg[2]; 
    end else 
    If modelType = 2 then begin 
        bRuleB = MACDAvg < MACDAvg[1] AND MACDAvg[1] < MACDAvg[2]; 
    end;     
end
 
//RuleC 
 
//case1 :: momentum crossover 
if ruleC = 1 then begin 
    if modelType = 1 then begin 
        bRuleC = BullCr AND (MRO(BearCR, 4, 1) = -1); 
    end else 
    if modelType = 2 then begin 
        bRuleC = BearCr AND (MRO(BullCR, 4, 1) = -1); 
    end
end
 
//case2 :: Price to SMA comparison 
If ruleC = 2 then begin 
    If modelType = 1 then begin 
        bRuleC = Price > AverageFC(Price,parms7); 
    end else 
    If modelType = 2 then begin 
        bRuleC = Price < AverageFC(Price,parms7); 
    end;     
end
 
//case3 :: Price to exponential MA comparison 
If ruleC = 3 then begin 
    If modelType = 1 then begin 
        bRuleC = Price > xAverage(Price,parms7); 
    end else 
    If modelType = 2 then begin 
        bRuleC = Price < xAverage(Price,parms7); 
    end;     
end
 
//case4 :: OI above linRegr 
If ruleC = 4 then  
        bRuleC = OpenInt > (LinearRegValueOpenInt, parms7, 0 )* (1+(parms8/100))); 
 
//case5 :: OI below linRegr 
If ruleC = 5 then  
        bRuleC = OpenInt < (LinearRegValueOpenInt, parms7, 0 )* (1-(parms8/100))); 
 
//case6 :: recent new highs 
If ruleC = 6 then 
    bRuleC = High > Highest(High,parms7)[1];     
 
//case7 :: recent new lows 
If ruleC = 7 then 
    bRuleC = Low < Lowest(Low,parms7)[1]; 
 
//case8 :: DMI test 
If ruleC = 8 then 
        bRuleC = oADX > parms7 AND oADX < parms8; 
{    end else 
    If modelType = 2 then begin 
        bRuleA = oADX > parms2 AND oDMIPlus < oDMIMinus; 
    end;     
end;}
 
 
//case9 :: Slow %K Test 
If ruleC = 9 then  
    bRuleC = oSlowK > parms7 AND oSlowK < parms8; 
 
//case10 :: macd slope direction 
If ruleC = 10 then begin 
    If modelType = 1 then begin 
        bRuleC = MACDAvg > MACDAvg[1] AND MACDAvg[1] > MACDAvg[2]; 
    end else 
    If modelType = 2 then begin 
        bRuleC = MACDAvg < MACDAvg[1] AND MACDAvg[1] < MACDAvg[2]; 
    end;     
end
 
 
If modelType = 1 AND bRuleA AND bRuleB AND bRuleC then 
            Buy ( "LE" ) next bar at market
If modelType = 2 AND bRuleA AND bRuleB AND bRuleC then 
            Sell Short ( "SE" ) next bar at market
 
If BarsSinceEntry = 0 Then  
    PosHigh = High
    PosLow = Low;  
    EntryATR = myATR; 
  
If MarketPosition = 1 Then Begin 
   Sell ("2L"Next Bar at EntryPrice + EntryATR Limit
   Sell ("mmL"Next Bar at EntryPrice - ATRVal Stop
End
 
If MarketPosition = -1 Then Begin 
    Buy to Cover ("2S"Next Bar at EntryPrice - EntryATR Limit
    Buy to Cover ("mmS"Next Bar at EntryPrice + ATRVal Stop
End
 
If LastBarOnChart Then Begin 
    value1 = ShowLongStop(EntryPrice + EntryATR); 
    value1 = ShowShortStop(EntryPrice - EntryATR); 
End
Back to top
View user's profile Send private message
krc
Guest


Joined: 02 Nov 2005
Posts: 8

PostPosted: Wed Nov 16, 2005 8:06 am    Post subject: how many chromosomes? Reply with quote

I think the question is about using Chromosomes correctly. The default translation of the above code through the 'Code Converter' is not optimal. I expect that at least each 'Rule' should have its own chromosome.
Back to top
View user's profile Send private message
VladGor
Support Team


Joined: 26 Jan 2004
Posts: 528

PostPosted: Wed Nov 16, 2005 5:44 pm    Post subject: Reply with quote

We didn't quite understand your question.
Do you want us to help you to modify code of your system for TSGO so that every rule has separate chromosome?

Regarding convertor.
Convertor is made to simplify work or users.
More experienced users can add new chromosomes by themselves after conversion.
Back to top
View user's profile Send private message
krc
Guest


Joined: 02 Nov 2005
Posts: 8

PostPosted: Wed Nov 16, 2005 6:57 pm    Post subject: best practice? Reply with quote

Let me rephrase my questions:

If I have a complex strategy (like the one above), how do I determine the right number of chromosomes to use?

Are there any other factors that I should consider?

With this particular strategy my guess is three chromosomes. Is this correct? (and it would be six if longs and shorts were not discrete)

Is there any easy way to utilize TSGO.Manager in a way that the actual order is not given until multiple strategies vote that an order is given? Maybe using TSGO.GO.Set in the child strategies and TSGO.GO.Get in the actual order placing strategy.

Or maybe I should have 30 strategies / chromosomes each using an additional gene with On/Off?

Would that allow up to 30 strategies to vote on a given order?

Or maybe I can't do this in a Genetic Optimizer and need a Neural Net.
Back to top
View user's profile Send private message
krc
Guest


Joined: 02 Nov 2005
Posts: 8

PostPosted: Wed Nov 16, 2005 8:05 pm    Post subject: trying the on-off thing Reply with quote

Idea
I think 10 systems with the (on-off) gene might do what I am trying to accomplish.

At least it should be interesting...

Smile Sorry for any confusion...
Back to top
View user's profile Send private message
VladGor
Support Team


Joined: 26 Jan 2004
Posts: 528

PostPosted: Thu Nov 17, 2005 3:14 pm    Post subject: Reply with quote

Quote:
Let me rephrase my questions:
If I have a complex strategy (like the one above), how do I determine
the right number of chromosomes to use?


Using chromosomes allows to notify optimizator about parameters that can be viewed together. Optimizator will use chromosomes from succesful samples.

Threfore genes should be devided into chromosomes with meaning. For example to separate different type parameters to chromosomes.

It influence only speed of search not result.

When there is nonly one chromosome and every gene in chromosome gives similar result there is slow analogy.

Quote:
Are there any other factors that I should consider?
With this particular strategy my guess is three chromosomes. Is this
correct? (and it would be six if longs and shorts were not discrete)

We didn't analyze your code but probably yes. You use 3 rule, parameters of each can be placed in 3 different chromosomes.

Parameters of ruleA, ruleB and ruleC can be placed in according chromosomes then optimization will be performed also by rule.

If you want to do optimization on modelType then it should be made as 4th chromosome.

Quote:
Is there any easy way to utilize TSGO.Manager in a way that the actual order is not given until multiple strategies vote that an order is
given? Maybe using TSGO.GO.Set in the child strategies and TSGO.GO.Get
in the actual order placing strategy.

You can use function TSGO.GO.Set/TSGO.GO.Get for transfering data between signals, only you should keep in mind that order of performing code of signals on one bar is not set (that is the way how TradeStation works).

Another way - make signal as function that return value, for example:
-1 - Sell
0 - Out
+1 - Buy

Then they can be combined in one signal.

TSGO.Manager allows to designe sistem that consists of independent signal as it's done in TradeStation.

Quote:
Or maybe I should have 30 strategies / chromosomes each using an additional gene with On/Off?

It's better to include On/Off in the chromosome of signal.

Quote:
Would that allow up to 30 strategies to vote on a given order?

No, that will allow you to optimize not only parameters of strategy but also content of system. For that you need to use technique described above.

Quote:
Or maybe I can't do this in a Genetic Optimizer and need a Neural Net.

We didn't quite understand this but you can perform voting for signals making them as functions or use data transfering function TSGO.GO.Set or use other utilities like TS Excel Link or others.

TS Excel Link:
http://www.tsresearch.com/software/ts_solutions/excel_link/
Back to top
View user's profile Send private message
Hannibal
Guest


Joined: 08 Feb 2006
Posts: 6

PostPosted: Wed Feb 08, 2006 5:51 am    Post subject: Summation of General Principles Reply with quote

Hi; I just got your toolset. I would like to request clarification of how it seems to work;

1. A gene is simply a parameter that you wish to test (optimise) and as long as it is numeric, it is usable.

2. A chromosome is used to group specific genes together so (for example) in a strategy with 20 different setups, you would logically put all of the genes for each setup into their own unique chromosome - that way the system wastes less time testing non-correlated combinations between chromosomes.

3. In hierarchal systems such as a system that has algorithms that determine biases for a given market environment, and then has setups that are unique to each type of environment, you should use a chromosome for each market environment algorithm (assuming more than one) and then individual unique chromosomes for each "sub-setup."

4. If you set the GOMode to 1, and place the Population input ABOVE the Gen input, then you can effectively extend the possible iterations (generations) from 100 up to 100,000 by optimising (in Tradestation) on Population = 1 to 100 AND Gen = 1 to 1000; Since Gen is second in line, TS will set Population to 1 (this is an extreme example, I would probably start population at 20, or else I would add a bit of code to allow me to count DOWN instead of UP.) and then it will cycle through all values of Gen before incrementing Population and restarting. This should effectively cause you to analyse each result set as the basis for the next analysis until you reach the last Population value. Actually, I suppose you could even just introduce a dummy input (unused except for being declared) and use that as your "recycling" counter for reiterating infinitely (if you wished).

Comments, and especially corrections please!

Also, is there a more detailed document on how to use this toolset - the stuff on the site is rather light in terms of being comprehensive.

Marc
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    support.tsresearchgroup.com Forum Index -> TS Genetic Optimizer for TradeStation All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright © TS Research Group

Powered by phpBB © 2001, 2002 phpBB Group

Developed by: webdesign.tria.lv