I wrote the following code to test this fuzzy lib,
//+------------------------------------------------------------------+ //| Test.mq4 | //| Copyright 2015, Rasoul Mojtahedzadeh | //| http://rasoulfx.blogspot.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Rasoul Mojtahedzadeh" #property link "http://rasoulfx.blogspot.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Connecting libraries | //+------------------------------------------------------------------+ #include <Math\FuzzyNet\MamdaniFuzzySystem.mqh> //--- input parameters input double InpV1 = 5.0; input double InpV2 = 1.5; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- Mamdani Fuzzy System MamdaniFuzzySystem *fsTest=new MamdaniFuzzySystem(); FuzzyVariable *fvV1=new FuzzyVariable("V1",0.0,10.0); FuzzyVariable *fvV2=new FuzzyVariable("V2",0.0,10.0); //--- Create first input variables for the system fvV1.Terms().Add(new FuzzyTerm("Small", new TriangularMembershipFunction(-10, 0, 5))); fvV1.Terms().Add(new FuzzyTerm("Medium", new TriangularMembershipFunction(3, 5, 7))); fvV1.Terms().Add(new FuzzyTerm("Large", new TriangularMembershipFunction(5, 10, 40))); fsTest.Input().Add(fvV1); //--- Create second input variables for the system fvV2.Terms().Add(new FuzzyTerm("Small", new TriangularMembershipFunction(-1.0, 0, 1.0))); fvV2.Terms().Add(new FuzzyTerm("Medium", new TriangularMembershipFunction(0.1, 1.0, 1.25))); fvV2.Terms().Add(new FuzzyTerm("Large", new TriangularMembershipFunction(1.25, 1.5, 10.0))); fsTest.Input().Add(fvV2); //--- Create Output FuzzyVariable *fvOutput=new FuzzyVariable("Output",0.0,1.0); fvOutput.Terms().Add(new FuzzyTerm("Out1", new TriangularMembershipFunction(-0.5, 0.0, 0.75))); fvOutput.Terms().Add(new FuzzyTerm("Out2", new TriangularMembershipFunction(0.5, 0.75, 1.0))); fsTest.Output().Add(fvOutput); //--- Create three Mamdani fuzzy rule MamdaniFuzzyRule *rule1 = fsTest.ParseRule("if (V1 is Small) or (V1 is Large) then Output is Out1"); MamdaniFuzzyRule *rule2 = fsTest.ParseRule("if (V2 is Small) or (V2 is Large) then Output is Out1"); MamdaniFuzzyRule *rule3 = fsTest.ParseRule("if (V1 is Medium) and (V2 is Medium) then Output is Out2"); //--- Add three Mamdani fuzzy rule in system fsTest.Rules().Add(rule1); fsTest.Rules().Add(rule2); fsTest.Rules().Add(rule3); CList *inList=new CList; Dictionary_Obj_Double *p_od_V1=new Dictionary_Obj_Double; Dictionary_Obj_Double *p_od_V2=new Dictionary_Obj_Double; p_od_V1.SetAll(fvV1, InpV1); p_od_V2.SetAll(fvV2, InpV2); inList.Add(p_od_V1); inList.Add(p_od_V2); CList *result; Dictionary_Obj_Double *p_od_Output; result=fsTest.Calculate(inList); p_od_Output=result.GetNodeAtIndex(0); Alert("Output: ",p_od_Output.Value()); delete inList; delete result; delete fsTest; } //+------------------------------------------------------------------+
but I receive the below error message in Experts tab of my terminal:
2015.09.23 01:56:43.849 Script Test CADJPY,H1: removed 2015.09.23 01:56:43.849 Test CADJPY,H1: uninit reason 1 2015.09.23 01:56:43.849 invalid pointer access in 'List.mqh' (374,7) 2015.09.23 01:56:43.848 Test CADJPY,H1: initialized 2015.09.23 01:56:43.839 Test CADJPY,H1 inputs: InpV1=5.0; InpV2=1.5;
and when I copy and paste above code into OnTick() function of an EA, I get the following error:
2015.09.24 00:09:14.912 2014.01.01 23:00 invalid pointer access in 'GenericFuzzySystem.mqh' (225,25)
Any idea what I'm doing wrong here?
Edit: I run above script in MetaTrader 5, and it works just fine!
I wrote the following code to test this fuzzy lib,
but I receive the below error message in Experts tab of my terminal:
and when I copy and paste above code into OnTick() function of an EA, I get the following error:
Any idea what I'm doing wrong here?
Edit: I run above script in MetaTrader 5, and it works just fine!
May be this question is insolent to you! In this case I beg your pardon and just ignore it!
But if you are developing an EA would you mind to post your code using the fuzzy libs here.
Of course you can exchange your indicators and and entry and exit strategy or you can use an existing here posted EA
like this one: https://www.mql5.com/en/code/913?

- votes: 70
- 2012.06.12
- Alexander Puzikov
- www.mql5.com
May be this question is insolent to you! In this case I beg your pardon and just ignore it!
But if you are developing an EA would you mind to post your code using the fuzzy libs here.
Of course you can exchange your indicators and and entry and exit strategy or you can use an existing here posted EA
like this one: https://www.mql5.com/en/code/913?
Hello Calli,
I'm upgrading RFX Breakout Trader EA with using this fuzzy library. Since it is a product in the market, I cannot post the source code.
Best,
Rasoul
Thank you for your message. The issue has been fixed and files have been updated.
Cool library but I'm also having similar issues mentioned about the 'Var' overloads. Line 206 and again on 217 and 228 in FuzzyRule.mqh
I also get the same error with 'Term' Line 207 and 218 and 229 in FuzzyRule.mqh
And another error on Line 485 of FuzzyRule.mqh "cannot convert type Lexem * to reference of type CObject *
I don't know enough to figure these issues out, so if you could provide some support for this library it would be much appreciated, as I was really looking forward to using it.
Thanks
Very impressive fuzzy library.
But may I know if more complicated rules can be specified, like for instance:
MamdaniFuzzyRule *rule4 = fsTest.ParseRule("if ((V1 is Medium) or (V1 is Large)) and ((V2 is Medium) or (V2 is Large) then Output is Out2");
Thanks in advance.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
FuzzyNet Fuzzy Logic Library:
FuzzyNet is one of the most popular mathematical libraries for creating fuzzy models
Fuzzy Logic Library for Microsoft.Net (FuzzyNet) is an easy to use component that implements Mamdani and Sugeno fuzzy inference systems.
FuzzyNet includes:
The following additions have been made when converting the library into MQL4:
Author: MetaQuotes Software Corp.