Global variable warning

 

I am getting the warning "declaration of 'SLPrice' hides global variable". (When I click on the error it takes me to where I've added ***). Pretty sure this warning leads to another one as I input my stop loss as "stopLossPrice(SLPrice)". The subsequent warning is as follows: "implicit conversion from number to string". Think solving the first issue will help with the second. Ive looked online for hours yet still unsure how to solve this problem. Appreciate everyone's help in advance!


   double StopLossPrice()
   {// Buying Opportunities
      if(BullishCandlestick() == true && BullishHammer() == true)
      {
         SLPrice = (iClose(pair[0], TimeFrame[1 || 2 || 3], 1)) - (stopLossinPips * GetPipValue());
      }
      else if(BullishCandlestick() == false && BullishHammer() == true)
      {	
         SLPrice = (iClose(pair[0], TimeFrame[1 || 2 || 3], 1)) - (stopLossinPips * GetPipValue());
      }
      return SLPrice;
   }
   
   double SLPrice = StopLossPrice(); 
  
  
   string stopLossPrice(double ***SLPrice)
   {
      return DoubleToStr(SLPrice, Digits);
   }
 
Interesting code.

Replace the 3 * with one underscore.
You have defined a local variable with the same name as your global variable.

The statement in [] wi always resolve to 1, since you are using boolean operators this will yield in true, which in turn is interpreted as int 1.


 
Dominik Egert #:
Interesting code.

Replace the 3 * with one underscore.
You have defined a local variable with the same name as your global variable.

The statement in [] wi always resolve to 1, since you are using boolean operators this will yield in true, which in turn is interpreted as int 1.


Perfect thanks for help. How would I refer to my StopLoss in the rest of my code? This doesn't seem to revolve the second issue as I thought it would

stopLossPrice(double _SLPrice)
 
   string stopLossPrice(double _SLPrice)
   {
      return DoubleToStr(_SLPrice, Digits);
   }
 
What the hell is this supposed to do?

TimeFrame[1 || 2 || 3]
 
  1.    double SLPrice = StopLossPrice(); 

    That is not an assignment; it's initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and

      Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

    4. Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
                external static variable - MQL4 programming forum #2 (2013)

  2. SLPrice = (iClose(pair[0], TimeFrame[1 || 2 || 3], 1))
    Zero is false and non-zero is true. True or True is true. Code is identical to
    SLPrice = (iClose(pair[0], TimeFrame[1], 1))

 
Dominik Egert #:
What the hell is this supposed to do?

Check 3 different timeframes at once. Assuming that can't be done?

 
jsc #:

Check 3 different timeframes at once. Assuming that can't be done?

It can but not that way, you have to call iClose for each timeframe, also you could write a function that receives an array
of timeframes and do that check for each one in a loop.
 
Alexandre Borela #:
It can but not that way, you have to call iClose for each timeframe, also you could write a function that receives an array
of timeframes and do that check for each one in a loop.

For the first way, would I have to create a different function for each timeframe? And for the second, I'll have to do some research into that, no idea how that's done

 
Dominik Egert #:

Not sure if you understood what I meant. How would I replace what I currently have as my StopLoss (stopLossPrice(SLPrice)) so the warning " implicit conversion from number to string" doesn't appear

I've obviously tried stopLossPrice(SLPrice)/ stopLossPrice(_SLPrice)/ stopLossPrice(double _SLPrice) but they don't work

if(BuyingEntryRequirement1() == true)
   {   
      OrderSend(pair[0], OP_BUY, OptimalLotSizeLow(), Ask, 0, stopLossPrice(SLPrice), LongTakeProfit[0], NULL, LongMagicNumber1H[0], 0, clrNONE);
   }

 
The error says it all.
YYour function is returning a string, you pass this string into OrderSend and the signature of this function requires a double value for the sl parameter.




Reason: