Download MetaTrader 5

Libraries: FuzzyNet Fuzzy Logic Library

To add comments, please log in or register
Automated-Trading
Admin
100954
Automated-Trading 2015.09.02 17:29 

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:

  • 8 new membership functions.
  • 4 new defuzzification methods for Mamdani-type systems.

Author: MetaQuotes Software Corp.

Rasoul Mojtahedzadeh
28244
Rasoul Mojtahedzadeh 2015.09.23 02:01  

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!

MetaQuotes Software Corp.
Moderator
182454
MetaQuotes Software Corp. 2015.09.24 09:03  
Thank you for your message. The issue has been fixed and files have been updated.
Carl Schreiber
6670
Carl Schreiber 2015.09.24 11:48  
Rasoul Mojtahedzadeh:

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?

EA_MARSI
EA_MARSI
  • votes: 70
  • 2012.06.12
  • Alexander Puzikov
  • www.mql5.com
The Expert Advisor is based on EMA_RSI_VA indicator.
Rasoul Mojtahedzadeh
28244
Rasoul Mojtahedzadeh 2015.09.24 13:16  
calli:

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

Rasoul Mojtahedzadeh
28244
Rasoul Mojtahedzadeh 2015.09.24 16:04  
MetaQuotes Software Corp.:
Thank you for your message. The issue has been fixed and files have been updated.
Thank you for your prompt response. The problem is now solved, and it works fine :-)
To add comments, please log in or register