I created a script to show my problem. To create the class works fine, the problem is with the result processing. The first iteration is ok, but if I wannt a second the, Inputs.Clear() dissapear the firstTerm object. To see more please run the script.
//+------------------------------------------------------------------+//| Fuzzy tester.mq4 |//| Copyright 2021, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2021, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property strict#include <Math\Fuzzy\mamdanifuzzysystem.mqh>
CMamdaniFuzzyRule *rule1 ,*rule2, *rule3;
//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
CMamdaniFuzzySystem *OurFuzzy=new CMamdaniFuzzySystem();
CList *Inputs=new CList;
CFuzzyVariable *firstInput= new CFuzzyVariable("diff", 0.0, 10.0);
CFuzzyVariable *fuzzyOut = new CFuzzyVariable("out",0.0, 10.0);
CDictionary_Obj_Double *firstTerm= new CDictionary_Obj_Double;
CDictionary_Obj_Double *Output;
firstInput.Terms().Add(new CFuzzyTerm("buy", new CZ_ShapedMembershipFunction (0.0, 5.0)));
firstInput.Terms().Add(new CFuzzyTerm("sell", new CZ_ShapedMembershipFunction (3.0, 7.0)));
firstInput.Terms().Add(new CFuzzyTerm("neutral", new CZ_ShapedMembershipFunction (3.0, 10.0)));
OurFuzzy.Input().Add(firstInput);
fuzzyOut.Terms().Add(new CFuzzyTerm("buy", new CZ_ShapedMembershipFunction (0.0, 5.0)));
fuzzyOut.Terms().Add(new CFuzzyTerm("neutral", new CNormalMembershipFunction (3.0, 7.0)));
fuzzyOut.Terms().Add(new CFuzzyTerm("sell", new CS_ShapedMembershipFunction (3.0, 10.0)));
OurFuzzy.Output().Add(fuzzyOut);
rule1 = OurFuzzy.ParseRule("if (diff is buy) then (out is buy)");
rule2 = OurFuzzy.ParseRule("if (diff is sell) then (out is sell)");
rule3 = OurFuzzy.ParseRule("if (diff is neutral) then (out is neutral)");
OurFuzzy.Rules().Add(rule1);
OurFuzzy.Rules().Add(rule2);
OurFuzzy.Rules().Add(rule3);
for(int i=1; i<10; i++)
{
Print("Iteration: ", i);
//set i as the first input value
firstTerm.SetAll(firstInput,i);
Print("Iteration value: ",firstTerm.Value());
//clear previous inputs
Inputs.Clear(); //<the clear process delete the firstTerm object!//add value to the input
Inputs.Add(firstTerm);
Print("Number of data on the input: ",Inputs.Total());
//calculate
CList *FuzzResult=OurFuzzy.Calculate(Inputs);
//get result
Output=FuzzResult.GetNodeAtIndex(0);
double res = Output.Value();
//print resultPrint("Result: ",i," ",res);
//delete objectdelete FuzzResult;
}
delete Inputs;
delete OurFuzzy;
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi!
I created a script to show my problem. To create the class works fine, the problem is with the result processing. The first iteration is ok, but if I wannt a second the, Inputs.Clear() dissapear the firstTerm object. To see more please run the script.
Thank you for your help!