Newbie question - MQL4 - Signal return value to custom function to determine order

 
void CheckForMATrade()
{
string signal;
double CurrentFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,1);
double CurrentSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,1);
double PreviousFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,2);
double PreviousSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,2); 

if(PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)
{signal="buy";}       						     // signal for buy signal
if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)
{signal="sell";}     						     // signal for sell signal

string MASignalValue=signal;                                         // i would like to send this signal to Signal Center Function
}

void CheckForRSITrade()
{
string signal;
double CurrentRSIValue = iRSI(_Symbol,_Period,14,PRICE_CLOSE,0);     // Calculate the RSI value
double PreviousRSIValue = iRSI(_Symbol,_Period,14,PRICE_CLOSE,1);    // Calculate the previous RSI value
if (CurrentRSIValue<70 && PreviousRSIValue>70)
{signal="sell";}       // signal for sell signal
if (CurrentRSIValue>30 && PreviousRSIValue<30)
{signal="buy";}        // signal for buy signal

string  RSISignalValue=signal;                                       // i would like to send this signal to Signal Center Function
}

void SignalCenter()                                                  // this is the section i am having problems with, MASIgnalValue & RSISignalValue
{                                                                    //    
string MASignalValue;                                                // call the MASignalValue from the CheckMATradeFunction
string RSISignalValue;                                               // call the RSISignalValue from the CheckForRSITrade function
if (MASignalValue=="buy" && RSISignalValue=="buy")OrderEntry(0);     // this would be the definition for a buy order =OrderEntry     
if (MASignalValue=="sell" && RSISignalValue=="sell")OrderEntry(1);   // this would be the definition for a sell order =OrderEntry   
}

void OrderEntry(int direction)
{
   if(direction==0)    
      if(OpenOrdersThisPair(Symbol())==0)
         OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);
   if(direction==1)
      if(OpenOrdersThisPair(Symbol())==0)
         OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red);
}

Hi All,

I hope i have added this correctly in the forum. Hopefully it should be listed in the MQ4 section. Thankyou in advance to any one who may be of help :)

I've been learning to write MQL4 for the past few weeks and do not have that much programming experience apart from basic HTML. Using YouTube to learn is only 'so' helpful and i can not find anything on coding multi function EA's.(Although i cant help but feel the answer is staring me straight in the face somewhere). I have also been through the forum and can not find specifically what information i am after.


I would like to use the values 'MASignalValue' and 'RSISignalValue' from the 'CheckForMATrade' function and the 'CheckForRSITrade' function and send them to the 'SignalCenter' function.

In the SignalCenter function, i would like to use both signals to determine together whether a buy/sell order can be placed, which i believe i can do by asking a simple if command ?,  whilst returning the answer/command to the 'OrderEntry'

if (MASignalValue=="buy" && RSISignalValue=="buy")OrderEntry(0);     // this would be the definition for a buy order = OrderEntry     
if (MASignalValue=="sell" && RSISignalValue=="sell")OrderEntry(1);   // this would be the definition for a sell order = OrderEntry


My question is, how am i able to return the values needed from the strings created to the different functions.


I have tried to include some basic information on the lines of code for what it is the line does or what i would like it to do. All of these lines are user defined functions and written outside of the OnTick function. I have no errors with the way the code is written in the error log.

However the EA will not make trades on a strategy tester.

Any help on the matter would be greatly appreciated. Also, i understand that the way i have coded this may seem strange to others. 

I am basically trying to get two different indicators, the MovingAverage and RSI to send a signal to a signal center which will then process and determine a buy or sell order.

If there is an easier way to do this,. i would be grateful to hear what you have to say about this.


CryptoKurt

 
CryptoKurt: My question is, how am i able to return the values needed from the strings created to the different functions.

You return them. Change your code.

If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

 
William Roeder:

You return them. Change your code.

If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

Ok, i will go back through the MQL4 book and read more on return values, as well as how to reference it properly in the forum. Thank you for your advice.  
 

Just to follow up on my own question. I realized where it is that i went wrong and understand now how i over complicated things alot. Looking at my previous code its pretty embarrassing haha.

After a couple of days i finally worked it out. Doubles, it was all about the doubles,. oh and keeping everything together instead of over separating functions.

Here is the updated code. I hope it helps anyone else, if in the same situation.

void SignalCenter()
{
string signal ="";                                                                     // string for signal   
string signal1 ="";                                                                    // string for signal1
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
double CurrentFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,1);    // calculate the current moving average
double CurrentSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,1);    // calculate the current moving average
double PreviousFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,2);   // calculate the previous moving average
double PreviousSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,2);   // calculate the previous moving average
 
double CurrentRSIValue = iRSI(_Symbol,_Period,14,PRICE_CLOSE,0);                       // Calculate the RSI value
double PreviousRSIValue = iRSI(_Symbol,_Period,14,PRICE_CLOSE,1);                      // Calculate the previous RSI value
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
if(PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)                               // calculate the signal values
signal="buy";                                                                          // signal for buy 
                                                                                                                   
double ab_0 = (PreviousFast<PreviousSlow && CurrentFast>CurrentSlow);                  // created double to return to trade center                

if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)                               // calculate the signal values                             
signal="sell";                                                                         // signal for sell 

double as_1 =(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow);                                       // created double to return to trade center
//+------------------------------------------------------------------+ 
//+------------------------------------------------------------------+   
if (CurrentRSIValue>30 && PreviousRSIValue<30)                                         // calculate the signal values                                        
signal1="buy";                                                                         // signal for buy 

double bb_0 = (CurrentRSIValue>30 && PreviousRSIValue<30);                             // created double to return to trade center
//+------------------------------------------------------------------+

if (CurrentRSIValue<70 && PreviousRSIValue>70)                                         // calculate the signal values
signal1="sell";                                                                        // signal for sell 
                                                                                        
double bs_1 = (CurrentRSIValue<70 && PreviousRSIValue>70);                             // created double to return to trade center 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
Comment (
         "MovingAverage: ",signal,"\n",                                                // signal string output to chart
         "RSI Signal: ",signal1,"\n"                                                   // signal1 string output to chart
         );
//+------------------------------------------------------------------+
//                      Trade Center
//+------------------------------------------------------------------+
if (ab_0 && bb_0)OrderEntry(0);                                                        // buy order
if (as_1 && bs_1)OrderEntry(1);                                                        // sell order
}
void OrderEntry(int direction)
{
   if(direction==0)    
      if(OpenOrdersThisPair(Symbol())==0)
         OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);
   if(direction==1)
      if(OpenOrdersThisPair(Symbol())==0)
         OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red);
}
Reason: