How to switch an trailing methane in EA (Wizard created code)

 

I want to try to put in a method switcher to the EA generated by the wizard. Indeed learning curve still lacks. 

//--- Creation of trailing object
   switch (Trailing_Method)
      {
      case 0:  CTrailingNone *trailing       = new CTrailingNone;       break; 
      case 1:  CTrailingFixedPips *trailing  = new CTrailingFixedPips;  break;
      case 2:  CTrailingMA *trailing         = new CTrailingMA;         break;
      case 3:  CTrailingPSAR *trailing       = new CTrailingPSAR;       break;
      }
   if(trailing == NULL)
     {
      //--- failed
      printf(__FUNCTION__ + ": error creating trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__ + ": error initializing trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set trailing parameters
   switch (Trailing_Method)
      {
      // CTrailingNone
      case 1:  trailing.StopLevel(Trailing_FixedPips_StopLevel); trailing.ProfitLevel(Trailing_FixedPips_ProfitLevel);  // CTrailingFixedPips
      case 2:  trailing.Period(Trailing_MA_Period); trailing.Shift(Trailing_MA_Shift); trailing.Method(Trailing_MA_Method); trailing.Applied(Trailing_MA_Applied);  // CTrailingMA
      case 3:  trailing.Step(Trailing_ParabolicSAR_Step); trailing.Maximum(Trailing_ParabolicSAR_Maximum);  // CTrailingPSAR
      }

I'm getting compiling errors like:

'*' - initialization of variable skipped by 'case' label, use { }

'trailing' - variable already defined

'trailing' - undeclared identifier

'trailing' - parameter conversion not allowed


As the Variable trailing is not declared outside of the switch but also depends on different object classes, I run out of ideas on how to create a trailing method switch option. Any ideas or is this a dead end idea?

Thanks a lot for any hint :)



 

This suggestion system is awesome! 

CExpert Pointer compilation error gave me the hint to do it right. Problem solved

CExpert Pointer compilation error
CExpert Pointer compilation error
  • 2017.06.21
  • www.mql5.com
Hello guys! First post here! I always read a lot of post in this forum and since now all coding problems that I had were solved just searching here...