Coders, given that the lot size is now a changeable thingy, then Lot needs te remain permanent. I declared SendLot as a program-wide variable to hold the value of the adapted lot size.
This snippet holds the key:
Code: Select all
void CalculateLotsizeAndProfitTarget()
{
//Auto lot size, calculated as LotsPerThousandOfBalance per $1000
SendLot = Lot;
if (LotsPerThousandOfBalance > 0)
{
//Code for rounding down the account balance to bare thousands profided by Garyfritz. Many thanks Gary.
double BaseMag = MathPow(10, MathFloor(MathLog(AccountBalance()) / MathLog(10))); // 4376.59 -> 1000
double RoundDown = MathFloor(AccountBalance() / BaseMag) * BaseMag;
Lot = (RoundDown * 0.1) / 1000;
}//if (LotsPerThousandOfBalance > 0)
//Adaptive take profit
if (CashProfitPerLot > 0)
{
CashProfitTarget = NormalizeDouble(Lot * CashProfitPerLot, 0);
}//if (CashProfitPerLot > 0)
//Users can opt for incrementing the lotsize with each successive trade in the grid
if (OpenTrades > 0) IncrementLot();
//Lotsize idiot check
double MinLot = MarketInfo(Symbol(), MODE_MINLOT);
double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT);
if (SendLot < MinLot) Lot = MinLot;
if (SendLot > MaxLot) Lot = MaxLot;
}//End void CalculateLotsizeAndProfitTarget()
Code: Select all
Lot = (RoundDown * 0.1) / 1000; Code: Select all
SendLot = (RoundDown * 0.1) / 1000; 
