Download MetaTrader 5

Discussion of article "Applying fuzzy logic in trading by means of MQL4"

To add comments, please log in or register
MetaQuotes Software Corp.
MetaQuotes Software Corp.  

New article Applying fuzzy logic in trading by means of MQL4 has been published:

The article deals with examples of applying fuzzy set theory in trading by means of MQL4. The use of FuzzyNet library for MQL4 in the development of an indicator and an Expert Advisor is described as well.

The modern-day trading cannot be imagined without automated trading systems usually called Expert Advisors or robots. Most, if not all, of them feature a clear, hard-coded trading strategy and money management system. Their main advantage is a rigid algorithm excluding the human factor. However, this advantage is also their main drawback since trading robots lack flexibility. Regardless of the market conditions, an Expert Advisor always applies the same trading strategy with the same strictly categorized parameters. In other words, the system always acts rigidly: average trend > enter the market with one lot, strong trend > enter the market with two lots. No deviations!

Unlike an automated system, human traders think in fuzzy categories and may have different opinions on similar market entry signals. They are often doubtful and keep asking themselves if the trend is moderate or strong. And even if the trend is significant, is it strong enough to enter in two lots? Such fuzzy categories can be handled by the fuzzy logic. The fuzzy logic does not set rigid boundaries between the categories. Instead, it "blurs" them making a trading system more flexible and combining the rigidness of a trading robot with the flexibility of a human mind. The article provides examples of applying the fuzzy logic system in trading by means of MQL4.

Fig. 6. Describing a trend using the fuzzy logic

Author: Alexander Fedosov


Hi there i been work on fuzzy logic it work good apart from this undeleted ojects.

i code the old way OOP is new to me  do i need to call a Destructor to fix this.

7882896 objects of type S_ShapedMembershipFunction left

7882896 undeleted objects left


 thank you.


//--- Mamdani Fuzzy System  
   MamdaniFuzzySystem *fslots=new MamdaniFuzzySystem();
//--- Create input variables for the system
   FuzzyVariable *fsTrend=new FuzzyVariable("trend",0.0,9.0);
   fsTrend.Terms().Add(new FuzzyTerm("down", new Z_ShapedMembershipFunction(1.0, 6.0)));
   fsTrend.Terms().Add(new FuzzyTerm("notrend", new TrapezoidMembershipFunction(3.0,5.0,6.0,8.0)));
   fsTrend.Terms().Add(new FuzzyTerm("up",new S_ShapedMembershipFunction(7.0,9.0)));
   FuzzyVariable *fspricerange=new FuzzyVariable("price",0.000128,0.000147);
   fspricerange.Terms().Add(new FuzzyTerm("small", new Z_ShapedMembershipFunction(0.000131, 0.000136)));
   fspricerange.Terms().Add(new FuzzyTerm("med", new P_ShapedMembershipFunction(0.000132, 0.000136, 0.000139, 0.000143)));
   fspricerange.Terms().Add(new FuzzyTerm("big", new S_ShapedMembershipFunction(0.000137, 0.000144)));
//--- Create Output
   FuzzyVariable *fvlots=new FuzzyVariable("lots",0.0,5.0);
   fvlots.Terms().Add(new FuzzyTerm("bad", new TriangularMembershipFunction(0.0, 0.0, 0.25)));
   fvlots.Terms().Add(new FuzzyTerm("low", new TriangularMembershipFunction(0.25, 1.0, 1.75)));
   fvlots.Terms().Add(new FuzzyTerm("normal", new P_ShapedMembershipFunction(1.0, 1.8, 2.5,3.1)));
   fvlots.Terms().Add(new FuzzyTerm("high", new S_ShapedMembershipFunction(2.7,5.0)));
//--- Create three Mamdani fuzzy rules
   MamdaniFuzzyRule *rule1 = fslots.ParseRule("if (trend is notrend) and (price is small)then lots is bad");
   MamdaniFuzzyRule *rule2 = fslots.ParseRule("if (trend is up) and (price is small) then lots is low");
   MamdaniFuzzyRule *rule3 = fslots.ParseRule("if (trend is up) and (price is med) then lots is normal");
   MamdaniFuzzyRule *rule4 = fslots.ParseRule("if (trend is up) and (price is big)then lots is high");
   MamdaniFuzzyRule *rule5 = fslots.ParseRule("if (trend is down) and (price is small) then lots is low");
   MamdaniFuzzyRule *rule6 = fslots.ParseRule("if (trend is down) and (price is med) then lots is normal");
   MamdaniFuzzyRule *rule7 = fslots.ParseRule("if (trend is down) and (price is big)then lots is high");
//--- Add three Mamdani fuzzy rules in the system
//--- Set input value
   CList *in=new CList;
   Dictionary_Obj_Double *p_od_counter_arrayup=new Dictionary_Obj_Double;
   Dictionary_Obj_Double *p_od_move=new Dictionary_Obj_Double;
//--- Get result
   CList *result;
   Dictionary_Obj_Double *p_od_lots;
   delete in;
   delete result;
   delete fslots;
Rob Wise
Rob Wise  
But does this EA make money ?
To add comments, please log in or register