Swap value return EA

 

Hello Great people, 

I am new to coding. I attempted to write a code for a simple expert advisor (MQL5) to return the value 0, if the swap on a long position (or series of long positions) is positive. If the swap is negative, the EA should retrieve, add up all the negative swaps of all Buy positions (for the symbol) and return the result. E.g -1.08 (Position1 swap)  + -0.64 (Position2 swap)  = -1.72 (Total negative swap).  While compiling, I keep getting the errors: 1. unexpected end of program and 2. unbalanced parenthesis.

My code is as follows:

void OnTick() 
  {
 
 double GetSwap(){
  double Swap=0.0;
   if ((SymbolInfoDouble (SYMBOL_SWAP_LONG)) > 0){ 
    Swap==0.00;
     
     
     
     }
     else  (Swap==(SymbolInfoDouble (SYMBOL_SWAP_LONG)));
   
           }
           
       
  
    
    
    
    
    
    


    Kindly help take a look at this.

    Thank you.

    

 

You are trying to declare a function inside a function (OnTick here). This is not possible. Do the declaration outside on the global scope.

double GetSwap()
  {
   double swap=0.0;
   if (SymbolInfoDouble(_Symbol,SYMBOL_SWAP_LONG) < 0)
     {
      // go through all open BUY positions for _Symbol and add swaps here
     }
   return swap;
 }

void OnTick() 
  {
...

And think about negative swap for SHORT positions.

 
lippmaje:

You are trying to declare a function inside a function (OnTick here). This is not possible. Do the declaration outside on the global scope.

And think about negative swap for SHORT positions.

Thank you so much lippmaje. I will try this and see how it goes. 

Very much appreciated.

Reason: