String Problem in Function

 

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, "-");

}

 

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,..)

 
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
 
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);
}

 
Brilliant solution, thank you very much !!!
 
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;
 
Thank you whroeder1, although I'm not very good, I'm learning a lot with you!

Thanks so much
Reason: