I think you have to 'split' the parameters you want to change:
... input int MA_Period=13; int _MA_Period, MA_handle; ... void OnInit() { ... _MA_Period = MA_Period <= 0 ? 14 : MA_Period; ... MA_handle=iCustom(NULL,0,"Examples\\Custom Moving Average", _MA_Period, MA_Shift, MA_Method, PRICE_CLOSE // using the close prices ); }
Carl Schreiber:
I think you have to 'split' the parameters you want to change:
Sorry I don't get it.
What I want to do again. is define a function F() with optional parameter of type MqlParam:
void F(MqlParam &parm=NULL) // here the = is not accepted because it's a reference parameter. I try to make the parameter optional { } OnStart() { F(); // this call to F without parm is what I need }
Amir Yacoby:
Thanks, but struct does not have pointer apparently.
I like whroeder1's first idea: use two functions.
void OnStart() { // Call with no parameters F(); // Call with a parameter MqlParam mparm = {TYPE_BOOL,1,1.0,"string"}; // Initialize F(mparm); } void F(MqlParam& parm) { // Dummy parm passed? if ( parm.integer_value == 0 ) { Print("NOOP"); } else { Print(parm.type); Print(parm.integer_value); Print(parm.double_value); Print(parm.string_value); } } // No parameter version simple sends a dummy parm void F(void) { MqlParam parm = {0}; F(parm); }
Amir Yacoby:
Many thanks whroeder1, and Anthony for elaborating what I missed in his answer.
Many thanks whroeder1, and Anthony for elaborating what I missed in his answer.
Or use a class :
class CMqlParam { public: ENUM_DATATYPE type; long integer_value; double double_value; string string_value; CMqlParam(ENUM_DATATYPE t,long i,double d,string s) : type(t),integer_value(i),double_value(d),string_value(s) {}; CMqlParam(MqlParam &p) : type(p.type),integer_value(p.integer_value),double_value(p.double_value),string_value(p.string_value) {}; }; void F(CMqlParam *parm=NULL) { //--- do your stuff if(parm==NULL) { Print("NOOP"); } else { Print(parm.type); Print(parm.integer_value); Print(parm.double_value); Print(parm.string_value); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { MqlParam param={TYPE_DATETIME,0,100.0,""}; CMqlParam myparam1(TYPE_BOOL,1,1.0,"string"); CMqlParam myparam2(param); F(&myparam1); F(&myparam2); F(); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
For some reason I can't find a solution.
I am trying to declare an optional MqlParam parameter In a method:
but the compiler will not accept an assignment to a reference parameter.
Any ideas?
IndicatorCreate is an example where the 5th parameter is what I want.