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

 

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.

 

   res=0;
//--- 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)));
   fslots.Input().Add(fsTrend);
//-----
   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)));
   fslots.Input().Add(fspricerange);
//--- 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)));
   fslots.Output().Add(fvlots);
//--- 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
   fslots.Rules().Add(rule1);
   fslots.Rules().Add(rule2);
   fslots.Rules().Add(rule3);
   fslots.Rules().Add(rule4);
   fslots.Rules().Add(rule5);
   fslots.Rules().Add(rule6);
   fslots.Rules().Add(rule7);
//--- 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;
   p_od_counter_arrayup.SetAll(fsTrend,counter_arrayu);
   p_od_move.SetAll(fspricerange,movement);
   in.Add(p_od_counter_arrayup);
   in.Add(p_od_move);      
//--- Get result
   CList *result;
   Dictionary_Obj_Double *p_od_lots;
   result=fslots.Calculate(in);
   p_od_lots=result.GetNodeAtIndex(0);
   res=NormalizeDouble(p_od_lots.Value(),_Digits);
//---
   delete in;
   delete result;
   delete fslots;
   
  
 
 return(res);
 
But does this EA make money ?
 
Good article. The fuzzy logic is clearly and correctly described and applied. Interesting
 
Hi there, great article. I just downloaded the FuzzyNet and the lib had several errors. I hoped if there is anyone who has a working version of the lib? thanks
 
Thank you so much.

Reason: