Use code-format like I've done below.
double A = 0.1; //Buy double B = 0.2; //Sell int OnInit() { int Ticket1 = 0; int Ticket2 = 0; return(INIT_SUCCEEDED); } void OnTick() { Ticket1 = OrderSend(Symbol(),OP_BUY,A,up,1,cp-20*Point*10,cp+15*Point*10); Ticket2 = OrderSend(Symbol(),OP_SELLSTOP,B,down,1,down+20*Point*10,down-15*Point*10); }
A and B have to be outside the OnInit. Putting them inside only make them available to OnInit ONLY. It is impossible for the other events to see those variables.
This is not always the case. For custom functions, you could call them with reference to the created variables, but the variables will still get deleted when you get out of the function in which they are declared.
This is what I mean:
void OnInit(){ double A = 0.1; //Buy double B = 0.2; //Sell custom_function(A,B); } void custom_function(const double & variable1,const double & variable 2){ //--- const means that we do not want to change the variables in here. //--- the & means that we want to use the variable we passed in, not to create a copy (happens if you don't use it) /* You can use your variables A and B, only in here, they have nicknames variable1 and variable2. */ }
Cheers!
Please edit your post and
use the code button (Alt+S) when pasting code
It is a good idea to use meaningful variable names, especially where they are going to be used elsewhere from where they are declared.
Instead of A, maybe Lotsize_A
Instead of B, maybe Lotsize_B
that way they are instantly recognisable, especially when other people are trying to follow your code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Error: Un declared Identifier,....
pease help me on this .... as iam quit new to MQL4....