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); }
TimeFrame[1 || 2 || 3]
-
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++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
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:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
-
Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 (2013)
-
-
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 toSLPrice = (iClose(pair[0], TimeFrame[1], 1))
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
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); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!