Calculated Range variable as Int
- Universal MA Cross EA
- Take profit candle pips
- Useful features from KimIV
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.
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.
- 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.
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.