Help Please on Variable Calling / Global Variable

 

I'm relatively new to MQL4 and have been loving it, however I have run into a problem. 

I have created an EA and I need to access variable: 'CaseNumber' from multiple functions and also change it. 

I have error checking in my code and everything else seems to be functioning correctly only 'CaseNumber' is not being changed.

I have tried 'CaseNumber' as a global variable as well with much the same result. 

Here are the basics of my code so to show the situation when using 'CaseNumber' on the global scope:

 int CaseNumber = 0; //global scope

 

OnTick(){

SignalFunction(); 

TrailFunction(); 

}//ontick End 

 

void SignalFunction() {

 if(EnterTradeFunction())

        CaseNumber++;

} //SignalFunction End

 

void EnterTradeFunction(){

        OrderSend(Symbol(),ordertype,(CaseNumberChecking()*0.01),price,Slippage,0,0,"Comment",0,0,clrNONE));

} //EnterTradeFunction End

 

int CaseNumberChecking(){

int LotSize= 0; //will change based on case number

         switch(CaseNumber)

        {

        case 0: LotSize = 1; break;

        case 1: LotSize= 1; break;

        case 2: LotSize= 1; break;

        case 3: LotSize= 2; break;

        case 4: LotSize = 3; break;

        case 5: LotSize = 5; break;

        case 6: LotSize= 8; break;

        . . . 

        }

        return(LotSize);

}//CaseNumberChecking End 

________________________________________________ 

 

Also using 'CaseNumber' as a local variable and calling it: 

 ________________________________________________

OnTick(){

     int CaseNumber = 0; 

SignalFunction(CaseNumber); 

        TrailFunction(CaseNumber);

}//ontick End 

 

int SignalFunction(int CaseNumber) {

 if(EnterTradeFunction())

        CaseNumber++;

     return(CaseNumber); 

} //SignalFunction End

 

void EnterTradeFunction(int CaseNumber){

        OrderSend(Symbol(),ordertype,(CaseNumberChecking()*0.01),price,Slippage,0,0,"Comment",0,0,clrNONE));

} //EnterTradeFunction End

 

int CaseNumberChecking(int CaseNumber){

int LotSize= 0; //will change based on case number

         switch(CaseNumber)

        {

        case 0: LotSize = 1; break;

        case 1: LotSize= 1; break;

        case 2: LotSize= 1; break;

        case 3: LotSize= 2; break;

        case 4: LotSize = 3; break;

        case 5: LotSize = 5; break;

        case 6: LotSize= 8; break;

        . . . 

        }

        return(LotSize);

}//CaseNumberChecking End

I understand that when I am calling it locally it is setting 'CaseNumber' back to '0' every tick but I don't know how to prevent that because my Signal and Trailing Stop functions both need the 'CaseNumber' variable as well as need to be called from the OnTick function.

I realize this is such a newbie problem but help would be so much appreciated.

 
void SignalFunction() {

 if(EnterTradeFunction())  //You are calling a void function

        CaseNumber++;

} //SignalFunction End

 

void EnterTradeFunction(){  //Change this to a bool function and code it to return true or false

        OrderSend(Symbol(),ordertype,(CaseNumberChecking()*0.01),price,Slippage,0,0,"Comment",0,0,clrNONE));

} //EnterTradeFunction End
I imagine that as you are calling a void function, your if() cannot be true
 
SavageSpirit:
...

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

Reason: