Download MetaTrader 5

String Problem in Function

To add comments, please log in or register
fly7680
636
fly7680  

Hi, I wrote a function with input parameters but I could not insert an operator as a string:

void MyFunction(int Freccia, string Dir){

    //.......My code

    ObjectCreate("Freccia"+T,OBJ_ARROW,0,Time[1],Low[1] Dir 30*Point); 
    ObjectSet   ("Freccia"+T,OBJPROP_COLOR,White); 
    ObjectSet   ("Freccia"+T,OBJPROP_ARROWCODE,Freccia);
}

void OnTick(){
  
       MyFunction(241, "-");

}

Carl Schreiber
7301
Carl Schreiber  

You should have got a compiler error here:

ObjectCreate("Freccia"+T,OBJ_ARROW,0,Time[1],Low[1] Dir 30*Point); 

I would just use:

ObjectCreate("Freccia"+T,OBJ_ARROW,0,Time[1],Low[1]); 

Everything else I would set using ObjectSet("Freccia"+T,..)

fly7680
636
fly7680  
I would like to set an arrow distance but at the same time I can decide how to enter the input value if I use the + or - operator but I did not understand what you want to tell me. I'm sorry
Nguyen Nga
10878
Nguyen Nga  
void MyFunction(int Freccia, string Dir = "-"){

    //.......My code
    int iDir = -1; if(Dir=="+") iDir = 1;
    
    ObjectCreate("Freccia"+T,OBJ_ARROW,0,Time[1],Low[1]+iDir*30*Point); 
    ObjectSet   ("Freccia"+T,OBJPROP_COLOR,White); 
    ObjectSet   ("Freccia"+T,OBJPROP_ARROWCODE,Freccia);
}

fly7680
636
fly7680  
Brilliant solution, thank you very much !!!
whroeder1
15934
whroeder1  
fly7680: Brilliant solution, thank you very much !!!
  1. Even better, don't use strings, at all.
    void MyFunction(int Freccia, double Dir = -1.0){
    
        //.......My code
        
        ObjectCreate("Freccia"+T,OBJ_ARROW,0,Time[1],Low[1]+Dir*30*Point); 
        ObjectSet   ("Freccia"+T,OBJPROP_COLOR,White); 
        ObjectSet   ("Freccia"+T,OBJPROP_ARROWCODE,Freccia);
    }
    

  2. You are not adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
    double   pip          = StringFind(_Symbol,"JPY") < 00.010.0001;
    int      pipsToPoints = int(pip / _Point);
    int      pipDigits    = (int)MathLog10(pipsToPoints);
    int      slippage     = 3 * pipsToPoints;
fly7680
636
fly7680  
Thank you whroeder1, although I'm not very good, I'm learning a lot with you!

Thanks so much
To add comments, please log in or register