VladGor Support Team
Joined: 26 Jan 2004 Posts: 528
|
Posted: Thu Mar 04, 2004 6:23 pm Post subject: List of functions TS.GO v. 1.2 or higher |
|
|
TS.GO v. 1.2
List of functions.
TS.GO.Start(FileName)
Starts the optimization and sets the name of file for current population storage. This function always should be called on the first bar.
Parameters:
FileName name of the file for current population storage. If special folder is not set then the file will be created in Reports folder (for example: ...\Program Files\TradeSmart\TS GO\reports ).
Return of value:
1 successful completion.
-1 error creating a new file or opening an indicated file.
Usage Example:
| EasyLanguage: |
If CurrentBar = 1 Then Begin Value1 =TS.GO.Start("MyName.rgo"); End;
|
Function Code:
| EasyLanguage: |
Inputs: FName(StringSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Start",LPSTR; TS.GO.Start = GO_Start(FName);
|
TS.GO.Mode(ModeGO)
Sets up the optimization mode.
Parameters:
ModeGO optimization mode.
0 deletes old population and begins from empty population.
1 recalculates old population and continues optimization.
2 continues optimization without recalculation of old population.
Returned values:
1 successful completion.
-1 wrong number of mode.
Usage Example:
| EasyLanguage: |
{ 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.} Value1 = TS.GO.Mode(0); End;
|
Function Code:
| EasyLanguage: |
Inputs: ModeGO(NumericSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Set_Mode",int; TS.GO.Mode = GO_Set_Mode(ModeGO);
|
TS.GO.Popul(NPop)
Sets up the size of population.
Size of population in current version is limited from 10 to 1000.
In process of optimization size of population can dynamically change in range from 10 to NPop. Current size of population is displayed in bold in the window of Viewer.
Parameters:
NPop maximum size of population.
Returned values:
1 successful completion.
-1 wrong size of population.
Usage Example:
| EasyLanguage: |
{ 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.} Value1 = TS.GO.Popul(50); End;
|
Function Code:
| EasyLanguage: |
Inputs: NPop(NumericSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Set_Population",int; TS.GO.Popul = GO_Set_Population(NPop);
|
TS.GO.Chrom(Name)
Sets up new chromosome or search of existing chromosome.
Parameters:
Sets up new chromosome or search of existing chromosome.
Parameters:
Name name of chromosome.
Returned values:
>0 number of found or created chromosome.
-1 wrong name of chromosome (for example it is blank).
-2 array of chromosome is overloaded (in new version max. number of chromosome is equal to 1000).
Usage Example:
Usage Example:
| EasyLanguage: |
If Gen = 1 Then Begin { The description of 5 genes is as follows. The First parameter - a gene number. If it's zero, generate gene number. The Second parameter - a chromosome number that the gene belongs to. The Third parameter - a minimum parameter value. The Fourth parameter - a maximum parameter value. The Fifth parameter - an increment of the parameter. It is possible to assign 0. Sixth parameter - a name of the gene, one can use it as a commentary in the graphic interface. } K = TS.GO.Chrom("Buy.Signal"); R = TS.GO.Gen("Len1",K,1,50,1); R = TS.GO.Gen("Len2",K,1,50,1); K = TS.GO.Chrom("Sell.Signal"); R = TS.GO.Gen("Len3",K,1,50,1); R = TS.GO.Gen("Len4",K,1,50,1); K = TS.GO.Chrom("StopLoss"); R = TS.GO.Gen("SL",K,100,1000,100); End;
|
Function Code:
| EasyLanguage: |
Inputs: Name(StringSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Def_Chrom",LPSTR; TS.GO.Chrom = GO_Def_Chrom(Name);
|
TS.GO.Gen(Name,Chrom,Min,Max,Incr)
Sets up new gene or search of existing gene.
Parameters:
Name name of gene.
Chrom number of chromosome that contains gene (if 0 then gene doesnt participate in mutations, its 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.
Returned values:
>0 number of found or created gene.
-1 wrong name of gene (for example it is blank).
-2 array of gene overloaded (in new version max. number of genes = 1000).
-3 wrong number of chromosome (<0 or chromosome is not defined).
Usage Example:
| EasyLanguage: |
If Gen = 1 Then Begin { The description of 5 genes is as follows. The First parameter - a gene number. If it's zero, generate gene number. The Second parameter - a chromosome number that the gene belongs to. The Third parameter - a minimum parameter value. The Fourth parameter - a maximum parameter value. The Fifth parameter - an increment of the parameter. It is possible to assign 0. Sixth parameter - a name of the gene, one can use it as a commentary in the graphic interface. } K = TS.GO.Chrom("Buy.Signal"); R = TS.GO.Gen("Len1",K,1,50,1); R = TS.GO.Gen("Len2",K,1,50,1); K = TS.GO.Chrom("Sell.Signal"); R = TS.GO.Gen("Len3",K,1,50,1); R = TS.GO.Gen("Len4",K,1,50,1); K = TS.GO.Chrom("StopLoss"); R = TS.GO.Gen("SL",K,100,1000,100); End;
|
Function Code:
| EasyLanguage: |
Inputs: GName(StringSimple), Chrom(NumericSimple), Min(NumericSimple), Max(NumericSimple), Incr(NumericSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Def_Gen",int,int,float,float,float,LPSTR; TS.GO.Gen = GO_Def_Gen(0,Chrom,Min,Max,Incr,GName);
|
TS.GO.Next(Generation)
Generates new candidate of population or determines the best candidate of population. The end of optimization (final run on strategy) is determined by the value of parameter Generation <= than value in previous run.
Parameters:
Generation number of generation. It should be growing value.
Returned values:
1 last run of strategy after finishing optimization. The best sample of population will be marked.
0 instant run of optimization. Instant candidate of population is generated.
Usage Example:
| EasyLanguage: |
Input: ShowInd(1); Var:LastRun (0),Ind(0); { 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);
|
Function Code:
| EasyLanguage: |
Inputs: Generation(NumericSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Next",int; TS.GO.Next = GO_Next(Generation);
|
TS.GO.Finish
Returns the characteristics of the last run of strategy.
No parameters.
Returned values:
1 the last run of strategy after finishing optimization.
0 instant run of optimization.
Usage Example:
| EasyLanguage: |
Value1 = TS.GO.Finish;
|
Function Code:
| EasyLanguage: |
DefineDLLFunc: "TSGO12.dll", int, "GO_IsFinish"; TS.GO.Finish = GO_IsFinish;
|
TS.GO.Error
Returns error code of performed function.
No parameters.
Returned values:
>0 normal completion.
=0 normal completion, special case.
<0 code of error.
Usage Example:
| EasyLanguage: |
If TS.GO.Error < 0 Then { Your condition };[/code] Function Code: [code] DefineDLLFunc: "TSGO12.dll", int, "GO_Error"; TS.GO.Error = GO_Error;
|
TS.GO.Var(Name)
Creates users variable.
Variable is tied to sample of population and allows to keep and choose user data. This data is displayed in viewer together with gene values and can be extracted into Excel for further analysis. Also they can be used for transferring data among functions in one strategy.
Usage of this function is not necessary because variable is created automatically on attempt to write in it. This function can be used to reserve order of variables (order of columns in viewer).
Parameters:
Name name of users variable.
Returned values:
>0 number of gene where variable is written.
-1 wrong name of variable (for example it is blank).
-2 table of genes and variables is overloaded (its size in current version is 1000).
Usage Example:
| EasyLanguage: |
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(0); R = TS.GO.Popul(50); R = TS.GO.FreshBlood(3); { Define User variables. } R = TS.GO.Var("NetProfit"); R = TS.GO.Var("PF"); R = TS.GO.Var("MaxIDD"); End;
|
Function Code:
| EasyLanguage: |
Inputs: Name(StringSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Def_Gen",int,int,float,float,float,LPSTR; TS.GO.Var = GO_Def_Gen(0,0,0,0,0,Name);
|
TS.GO.Get(Name,Individ)
Gets value of gene or variable of user by Name from sample number Individ.
Parameters:
Name name of gene or users variable. For reading value of fitness, fixed name "Fitness" is used.
Individ number of sample in population from which value of gene is read.
1 - the best sample.
2 - next sample.
0 - special value. During optimization data of regular candidate of population is returned but at the last run data of best candidate is returned.
Returned values:
Value of gene or parameter of user is returned.
Error codes (can be obtained with function TS.GO.Error):
1 - normal completion.
-1 - wrong name of gene (it is blank or missing).
-2 - wrong number of sample (< 0 or > size of population).
Usage Example:
| EasyLanguage: |
If Gen = 1 Then Begin { Get values of genes for choosen candidate. } Len1 = TS.GO.Get("Len1",Ind); Len2 = TS.GO.Get("Len2",Ind); Len3 = TS.GO.Get("Len3",Ind); Len4 = TS.GO.Get("Len4",Ind); SL = TS.GO.Get("SL" ,Ind); End;
|
Function Code:
| EasyLanguage: |
Inputs: Name(StringSimple),Individ(NumericSimple); DefineDLLFunc: "TSGO12.dll", float, "GO_Get_Gen",LPSTR,int; TS.GO.Get = GO_Get_Gen(Name,Individ);
|
TS.GO.Set(Name,Val)
Sets new value of users variable for current sample of population. This function should be called after function TS.GO.Next and before TS.GO.Fitness.
Parameters:
Name name of users variable.
Val written value.
Returned values:
>0 normal completion. Number of gene is returned.
-1 wrong name of variable (for example it is blank).
-2 table of genes or variables is overloaded (its size in current version is 1000).
Usage Example:
| EasyLanguage: |
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); End;
|
Function Code:
| EasyLanguage: |
Inputs: Name(StringSimple),Val(NumericSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Set_Gen",LPSTR,float; TS.GO.Set = GO_Set_Gen(Name,Val);
|
TS.GO.Fitness(Fitness)
Informs about results of executed run on system.
Software uses the following assumption negative value of Fitness is bad, so these samples are not included in population.
Parameters:
Fitness value of optimization criteria following the results of system.
Returned values:
1 successful completion.
Usage Example:
| EasyLanguage: |
{ 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. } Fitness = NetProfit + OpenPositionProfit; R = TS.GO.Fitness(Fitness);
|
Function Code:
| EasyLanguage: |
Inputs: Fitness(NumericSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Fitness",float; TS.GO.Fitness = GO_Fitness(Fitness);
|
TS.GO.FreshBlood(FB_factor)
Sets up value of factor "fresh blood" in population.
This function increases effective size of population prohibiting possibilities of leaders domination and giving chance to other candidates. Thus optimization is accelerated using varying genes bank and avoiding over fitting the system.
Parameters:
FB_factor value of factor.
=0 function is turned off, work is same as it was in previous version.
>0 additional mixing of population is turned on, typical value is 1.
Returned values:
1 normal completion.
-1 wrong value of parameter (<0).
Usage Example:
| EasyLanguage: |
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(0); R = TS.GO.Popul(50); R = TS.GO.FreshBlood(3); End;
|
Function Code:
| EasyLanguage: |
Inputs: FB_factor(NumericSimple); DefineDLLFunc: "TSGO12.dll", int, "GO_Set_FreshBlood",float; TS.GO.FreshBlood = GO_Set_FreshBlood(FB_factor);
|
TS.GO.Stat
This function calculates different statistics of system in EasyLanguage.
Obtained statistical results are saved in GO file in users variables. They are tied to current testing sample.
Its possible:
· to see them in report viewer,
· extract them in Excel for analysis,
· use them as fitness in optimization,
· they can be viewed as built in fitness.
No parameters.
Returned values:
1 successful completion.
Usage Example:
| EasyLanguage: |
{ Call of functions for statistics calculation } { Should be called on every bar } R = TS.GO.Stat; if LastBarOnChart Then Begin { Selection of calculated t_Test for current sample} Fitness = TS.GO.Get("%T_Test",0); { Transmiting of fitness } R = TS.GO.Fitness(Fitness);
|
Function Code:
| EasyLanguage: |
Vars: MP(0),TotTr(0),Winners(0),ConsecWin(0),MaxConsecWin(0),ConsecLoss(0), WinLoss2(0),WinLoss1(0),MaxWinner(0),SumWin(0),Losers(0),MaxConsecLoss(0), MaxLoser(0),SumLoss(0),ChPos(0),CumProf(1),EqTop(0),TopBar(0),EqBot(0), TopInt(0),FlatTime(0),DD(0),MaxDD(0),AvgTrade(0),DevTrade(0),t_Test(0),Pf(0); Vars: R(0); Array: Prof[10000](0); MP = MarketPosition; TotTr = MinList(10000,TotalTrades); if MP <> MP[1] and MP[1] <> 0 then begin Prof[TotTr] = MP[1] * (ExitPrice(1) - EntryPrice(1)) / EntryPrice(1); if Prof[TotTr] > 0 then begin Winners = Winners + 1; ConsecWin = ConsecWin + 1; MaxConsecWin = MaxList(MaxConsecWin, ConsecWin); ConsecLoss = 0; WinLoss2 = WinLoss1; WinLoss1 = 1; Condition1 = true; MaxWinner = MaxList(MaxWinner, Prof[TotTr]); SumWin = SumWin + Prof[TotTr]; end else begin Losers = TotTr - Winners; ConsecLoss = ConsecLoss + 1; MaxConsecLoss = MaxList(MaxConsecLoss, ConsecLoss); ConsecWin = 0; WinLoss2 = WinLoss1; WinLoss1 = -1; Condition1 = true; MaxLoser = MinList(MaxLoser, Prof[TotTr]); SumLoss = SumLoss + Prof[TotTr]; end; if Condition1 then if WinLoss1 <> WinLoss2 then ChPos = ChPos + 1; CumProf = CumProf * (1 + Prof[TotTr]); EqTop = MaxList(EqTop, CumProf); if EqTop > EqTop[1] then begin TopBar = CurrentBar; EqBot = EqTop; end; EqBot = MinList(EqBot, CumProf); TopInt = CurrentBar - TopBar; FlatTime = MaxList(TopInt, FlatTime); if EqTop > 0 then DD = (CumProf/EqTop - 1); MaxDD = MinList(MaxDD, DD); AvgTrade = Average_a(Prof, TotTr); If TotTr > 1 then DevTrade = StdDevS_a(Prof, TotTr); t_Test = Iff(DevTrade > 0, AvgTrade / DevTrade * SquareRoot(TotTr), 0); Pf = Iff(GrossLoss < 0,-(GrossProfit - LargestWinTrade)/GrossLoss,0); R = TS.GO.Set("NetProfit",NetProfit); R = TS.GO.Set("PF",Pf); R = TS.GO.Set("MaxDD",MaxIDDrawDown); R = TS.GO.Set("Trades",TotalTrades); R = TS.GO.Set("PercentProfit",PercentProfit); R = TS.GO.Set("MaxWin",LargestWinTrade); R = TS.GO.Set("MaxLoss",LargestLosTrade); R = TS.GO.Set("Winners",Winners); R = TS.GO.Set("Losers",Losers); R = TS.GO.Set("MaxConsecWin",MaxConsecWin); R = TS.GO.Set("MaxConsecLoss",MaxConsecLoss); R = TS.GO.Set("ChPos",ChPos); R = TS.GO.Set("%MaxWin",MaxWinner*100); R = TS.GO.Set("%SumWin",SumWin*100); R = TS.GO.Set("%MaxLoss",MaxLoser*100); R = TS.GO.Set("%SumLoss",SumLoss*100); R = TS.GO.Set("%CumProf",CumProf*100); R = TS.GO.Set("%MaxDD",MaxDD*100); R = TS.GO.Set("%AvgTrade",AvgTrade*100); R = TS.GO.Set("%DevTrade",DevTrade*100); R = TS.GO.Set("%T_Test",t_Test); end; TS.GO.Stat = 1;
|
Calculation of fitness can be more complicated. |
|