I'm trying to convert a functioning time range breakout EA that works with fixed stop loss and take profit to one where these values are derived from the high and low of the time period. I tried "double range = High[h] - Low[l]" and subtracting and adding "range" to High[h] or Low[l] for stop loss and take profit depending on the direction of the breakout. I also need to convert this "range" value to an integer for the money management calculation. I tried "int SL = range * 10000" (5 digit broker) and it doesn't seem to work. Am I in the ball park??
Files:
1min.1.0.mq4
13 kb
- Universal MA Cross EA
- Take profit candle pips
- Useful features from KimIV
bluesman:
I also need to convert this "range" value to an integer for the money management calculation.
Why ? what kind of a value does your MM need, what does the value represent ?
I also need to convert this "range" value to an integer for the money management calculation.
int init(){ if(Broker5Digits) { SL *= 10; TP *= 10; Slippage *= 10; k *= 10; } start(); return(0); }
- Every timeyou change pair/time frame/etc. the EA goes through a deinit/init cycle. Static/common(global) variables are NOT reloaded. so SL becomes 10X 100X 1000X
- You CAN NOT call start from init.
RaptorUK:
Why ? what kind of a value does your MM need, what does the value represent ?
The MM takes an integer and converts it Why ? what kind of a value does your MM need, what does the value represent ?
//Money management. It calculates the lot size getting the Stop Loss size and Risk input double GetLots(double RiskInPips) { double lot, dif; double MinLot; double MaxLot; double LotStep; double mpl; if(UseMoneyManagement) { double totalrisk = AccountBalance() * Risk / 100; double traderisk = totalrisk; double pip = traderisk/RiskInPips; lot = pip/MarketInfo(Symbol(), MODE_TICKVALUE); LotStep = MarketInfo(Symbol(),MODE_LOTSTEP); dif = MathMod(lot, LotStep); if(dif != 0) { lot -= dif; } } else { lot = Lots; } MinLot = MarketInfo(Symbol(), MODE_MINLOT); MaxLot = MarketInfo(Symbol(), MODE_MAXLOT); if(lot < MinLot) lot = MinLot; if(lot > MaxLot) lot = MaxLot; return(lot); }
I have a hard time with this editor. Anyway, the MM routine as shown above converts it to a percentage applid to account equity. I just thought since the routine is already written to accept an integer from ana external value that conversion of a calculated value to an integer would be the best way to go.
WHRoeder:
This EA worked fine when the SL and TP were entered as external value integers. The routine you cited is part of init and is only executed once eac h cycle. I have not had the problem you cite. The loop from Start has always executed fine I hired out to have the original ea written a few years ago and I have been just customizing it since.
- Every timeyou change pair/time frame/etc. the EA goes through a deinit/init cycle. Static/common(global) variables are NOT reloaded. so SL becomes 10X 100X 1000X
- You CAN NOT call start from init.
bluesman:
The MM takes an integer and converts it
The MM takes an integer and converts it
Nope, it takes a double . . .
double GetLots( double RiskInPips )
. . so you need to convert your "range", which is a price, to a number of pips . . . so divide your range by the currency point value and adjust for 4/5 Digit broker.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register