Home
Software
Prices
Download
Yahoo Charts
NEW:
ADVANCED
TRADESTATION TECHNIQUE
US Markets Daily
snapshots
Technical
Description
| |
sFLC3 EASY LANGUAGE CODE
It must be noted that the following (commented) code assumes the TSFLC DLL to be placed in
the Program sub-folder (or Windows\System32).
// Declarations
// TSFLC_Init is the function to call to instantiate a single new FLC
// It does not use any specific variable from the EL code, and returns the FLC
number
// or -1 if memory allocation failed
external method: "TSFLCmap.dll", int, "TSFLC_Init";
// This function creates a FLC in a single call
// It requires 2 arrays for Fuzzy Sets and Rule Set information
// These 2 arrays MUST BE 1-dim and have an upper boundary set to 3 (see
definitions below)
// This function returns 0 if successful, otherwise a negative error number
external method: "TSFLCmap.dll", int , "TSFLC_BuildTurnKeyFLC",
int, int, string , string, int;
// Each FLC is initially disabled when first built. This means that any new FLC
above the
// available credit may be disabled or disable another older one.
external method: "TSFLCmap.dll", int , "TSFLC_Enabled", int;
// This function calculates the FLC output for given FLC
external method: "TSFLCmap.dll", double, "TSFLC_CalcOutput",
int, double, double;
// This function calculates the FLC output for given FLC
external method: "TSFLCmap.dll", double, "TSFLC_GetOutputs",
int, double, double, string;
// _OnDestroyHandler is the function to call when the study is deactivated or
removed from the chart
// It does not use any specific variable from the EL code, and cannot return a
code.
// Logging to file is the only way to trace proper object destruction
external method: "TSFLCmap.dll", int, "_OnDestroyHandler";
// This function will return the credit left in the DLL when the object was
created, or -1 in case of error
external method: "TSFLCmap.dll", int, "TSFLC_Credit", int;
// This function will return the CURRENT usage level in the DLL
external method: "TSFLCmap.dll", int, "TSFLC_Usage", int;
external method: "TSFLCmap.dll", string, "TSFLC_RSName", int;
external method: "TSFLCmap.dll", string, "TSFLC_FSName", int,
int;
external: "TSFLCmap.dll", int, "TSFLC_FSMax", int;
external: "TSFLCmap.dll", int, "TSFLC_RSMax", int;
external: "TSFLCmap.dll", int, "TSFLC_MapSize";
#Events
OnDestroy = _OnDestroyHandler; // clear memory allocation (destroy map)
#End;
inputs:
int FLCN(numericref), // FLC number
double Input1(numeric), // FLC Input1
double Input2(numeric), // FLC Input2
double Output1(numericref),
double Output2(numericref),
double Output3(numericref),
double Output4(numericref),
double Output5(numericref),
int Shape(numeric), // Shape : 0 for 3x3, 1 for 5x5
int FuzzySet1(numeric), // Fuzzy Set Model for Input1
int FuzzySet2(numeric), // Fuzzy Set Model for Input2
int FuzzySet3(numeric), // Fuzzy Set Model for Output
int FuzzySetLabels1(numeric), // Fuzzy Set labels for Input1
int FuzzySetLabels2(numeric), // Fuzzy Set labels for Input2
int FuzzySetLabels3(numeric), // Fuzzy Set labels for Output
int DefaultRuleSetModel(numeric); // Default Rule Set Model
vars:
double Output(0), // FL controller output
int BuildOK(0), // Build Flag
int RSmodel(DefaultRuleSetmodel),// Rule Set model
int sn(iff(Shape<>0,1,0)), // Shape Number (only 0 or 1)
int Enabled(-1), // Activation Flag
bool ParamOK(true),
int RSmax(-1), // Max RS value
int FSmax(-1), // Max FX value
int Usage(-1), // DLL usage
int Credit(-1), // DLL credit left
int ret(0),
bool verbose(false);
Arrays: // REQUIRED IN DLL (NAME AND TYPE MUST BE LEFT UNCHANGED)
double Outputs[5](-1), // Array used in TSFLC_GetOutputs call
int fsm[3](0), // Array dimension MUST be 3 (2 inputs, 1 output)
int fslab[3](0); // Array dimension MUST be 3 (2 inputs, 1 output)
// TSFLC_Init must be called once only, on CurrentBar = 1 or on a controlled
event
// Otherwise, a new FL Controller will be created on each call.
if currentbar = 1 then begin
// One must first check whether parameters are valid
RSmax = TSFLC_RSMax(sn);
FSmax = TSFLC_FSMax(sn);
if FuzzySet1 < 0 or FuzzySet1 > FSMax then ParamOK = False;
if FuzzySet2 < 0 or FuzzySet2 > FSMax then ParamOK = False;
if FuzzySet3 < 0 or FuzzySet3 > FSMax then ParamOK = False;
if RSmodel < 0 or RSmodel > RSMax then ParamOK = False;
if ParamOK then
begin
flcn = TSFLC_Init; // Initialize new FLC on the map
if flcn < 0 then // InitOK = 0 on successful creation
print ("FLC Init:", flcn:0:0, " Error") // should never occur anyway
else
begin
fsm[1] = FuzzySet1; // Element 0 is not used.
fsm[2] = FuzzySet2;
fsm[3] = FuzzySet3;
fslab[1] = FuzzySetLabels1;
fslab[2] = FuzzySetLabels2;
fslab[3] = FuzzySetLabels3;
BuildOK = TSFLC_BuildTurnKeyFLC( flcn, sn, "fsm", "fslab", rsmodel);
switch (BuildOK)
begin
case >=0:
print("FLC", flcn:0:0, " has been built successfully. Status: ", BuildOK:0:0 );
case -1:
print ("FLC", flcn:0:0, "- No FLC (TSFLC_Init statement missing?)");
case -2:
print ("FLC", flcn:0:0, "- FLC has already been built.");
case -3:
print ("FLC", flcn:0:0, "- FLC number exceeded DLL limit (check user rights)");
case -4:
print ("FLC", flcn:0:0, "- Fuzzy sets could not be created" );
case -5:
print ("FLC", flcn:0:0, "- Fuzzy sets could not be initialised.");
case -6:
print ("FLC", flcn:0:0, "- Fuzzy sets could not be defined.");
case -7:
print ("FLC", flcn:0:0, "- Variable set could not be created.");
case -8:
print ("FLC", flcn:0:0, "- Fuzzy sets could not be allocated to variables.");
case -9:
print ("FLC", flcn:0:0, "- Rule Set size is unknown.");
case -10:
print ("FLC", flcn:0:0, "- Rule Set could not be initialised.");
case -11:
print ("FLC", flcn:0:0, "- Default Rule Set could not be loaded.");
case -12:
print ("FLC", flcn:0:0, "- Array Error. Arrays must be '[3]'");
default:
print ("FLC", flcn:0:0, "- Unknown error...");
end;
end;
end
else
print ("Parameter error");
end
else
begin
if flcn >= 0 then
begin
Enabled = TSFLC_Enabled(flcn);
Output = TSFLC_CalcOutput(flcn, Input1, Input2);
ret = TSFLC_GetOutputs(flcn, Input1, Input2, "Outputs");
Usage = TSFLC_Usage(flcn);
Credit = TSFLC_Credit(flcn);
Output1 = Outputs[0];
Output2 = Outputs[1];
Output3 = Outputs[2];
Output4 = Outputs[3];
Output5 = Outputs[4];
end;
if lastbaronchart and verbose then print("FLC: ", flcn:0:0,
" Build: ", BuildOK:0:0,
" Status: ", Enabled:0:0,
" Usage: ", Usage:0:0,
" Credit: ", Credit:0:0,
" In1: ", Input1,
" In2: ", Input2,
" Out: ", Output );
end;
FLC_Single = Output;
|