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
Hello,
I have a very intricate custom indicator I created with many variables.
When I call this icustom indicator into the Expert Advisor, how do I pull some of the variable values (esp. Bool) from the indicator code into the Expert Advisor to use them in decision making?
Here's the portion of the expert advisor code I wrote that doesn't seem to be working:
Here's where I call the custom indicators....TradeL, Trade S and RSI_Length_L are the Variables I want to pull into the Expert Advisor.
...
double K_L=iCustom(NULL,PeriodShort,"CUSTOM INDICATOR",TradeL,RSI_Length_L,0,0);
double D_L=iCustom(NULL,PeriodShort,"CUSTOM INDICATOR",TradeL,RSI_Length_L,1,0);
double K_S=iCustom(NULL,PeriodLong,"CUSTOM INDICATOR",TradeS,RSI_Length_L,0,0);
double D_S=iCustom(NULL,PeriodLong,"CUSTOM INDICATOR",TradeS,RSI_Length_L,1,0);
...
Here's where I try to use the TradeS and TradeL variables:
...
if (TradeL==False || TradeS==False)
{
Alert ("Do not trade at this Pair and TImeframe set at this time.");
return(0);
}
...
The problem is that the alert always sounds meaning TradeL and TradeS are always false, which I know their not.
Any suggestions would be appreciated!
Thank You
ThemBonezThemBonez
TradeL and TradeS variable are always going to remain unchanged. You can not change the passed parameters values from the called indicator (they are passed by value not by reference)
Thanks for your reply.
I want the value from the indicator. I don't want to change.
TradeL is a boolean variable, so I want to know if its false or true.
But it seems even when it is True in the indicator....its showing up false in the EA.
Did I code it write as I displayed?
Thanks for your reply.
I want the value from the indicator. I don't want to change.
TradeL is a boolean variable, so I want to know if its false or true.
But it seems even when it is True in the indicator....its showing up false in the EA.
Did I code it write as I displayed?ThemBonez
In metatrader you simply can not retrieve custom indicators variables values. The only thing you can retrieve is the value of a buffer. Try saving those variables values to a buffer and then get it from buffer or try using global variables for that purpose - otherwise you are never going to be able to get those values
So If I turn TradeS and TradeL into Global Variables, it will work right?
PS....How would I assign it to a buffer and retrieve it from the buffer.
Yes, this is my first custom indicator and EA, so I am fairly new to MQL4 programming.
Actually I have the TradeL and TradeS variables assigned as static bool global variables in both the Indicator code and the EA
Actually I have the TradeL and TradeS variables assigned as static bool global variables in both the Indicator code and the EA
Those variables are visible only within the code of the indicator
Use the global variables functions for that (see this thread for more information : https://www.mql5.com/en/forum/173017 )
Hi,
I read up On GlobalVariableSet and Get and see how this can be valuable, but I think there may be an issue. Let me explain.
In my custom indicator, I do an intricate analysis of an indicator and then create the bool TradeS and TradeL variables. If true, I can trade the pair, if false I cannot. I can't do the analysis in the EA, because the analysis determines not only if I can trade, but also optimizes the settings of how the indicator will be drawn and used. The challenge I see is if I have the EA operating on multiple pairs, will not the GlobalVariable values get confused between the different pairs?
Thanx
ThemBonez
I'm doing some experimenting using GlobalVariable Functions
I put this code in my indicator:
test=1;
GlobalVariableSet(GV,test);
Alert("Indicator GV= ",GV," Trade= ",test);
...
and I put this code in my EA:
GlobalVariableGet(GV);
Alert("EA GV= ",GV);
...
I made GV' and test both "int" variables in head of the code.
When I run the ea, the alert has GV=0, so obviously the "test" value of 1, is not being passed.
What am I doing wrong?
I'm doing some experimenting using GlobalVariable Functions
I put this code in my indicator:
test=1;
GlobalVariableSet(GV,test);
Alert("Indicator GV= ",GV," Trade= ",test);
...
and I put this code in my EA:
GlobalVariableGet(GV);
Alert("EA GV= ",GV);
...
I made GV' and test both "int" variables in head of the code.
When I run the ea, the alert has GV=0, so obviously the "test" value of 1, is not being passed.
What am I doing wrong?ThemBonez
Here is an example how you can do that :