You need to declare the variable at the global program level (in the "header" of the advisor)
//+------------------------------------------------------------------+ //| Expert 1.mq5 | //| Copyright 2021, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" //--- input parameters input int Input1=9; //--- double my_price; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- }
if(a==b) { my_price == ask; }
I think that you mean
if(a==b) { my_price = ask; }
if(c==d)
{
trade.Buy(......,my_price......);
}
Why do you need the variable my_price? Why not just use ask?
if(c==d)
{
trade.Buy(......,ask......);
}
Keith Watford:
Because ask value is always changing. I want trade with my_price variable which is the value of when necessery conditions are met.
I think that you mean
Why do you need the variable my_price? Why not just use ask?
ack234:
Because ask value is always changing. I want trade with my_price variable which is the value of when necessery conditions are met.
Because ask value is always changing. I want trade with my_price variable which is the value of when necessery conditions are met.
Yes, ask is always changing, but if you are placing a buy trade, the entry price has to be the current ask or you will get invalid price errors.
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
Hi, I have a basic question.
if(a==b) { my_price == ask; }
// ask variable was defined earlier and it gives instant ask value of parity.
if(c==d) { trade.Buy(......,my_price......); }
// I want to use my_price variable in this if fucntion. But of course I cant use it because my_price variable is not global variable. My question is how can I make my_price variable global in first if function. Is there any way to do that ?