Hallo.
Habs mal so versucht. Davon abgesehn, dass ich eigentlich selber nicht mehr durch sehe, müsste das doch eigentlich funktionieren.
extern string ALSZ="Auto_Lotsize";
extern bool Percent_of_Balance=true;
extern bool Percent_of_Free_Margin=false;
extern string BT1="if both = true";
extern string BT2="Lotsize =";
extern string BT3="Percent_of_Balance";
extern double Auto_Lotsize_Perc=0.72;
extern int Units_of_1_Lot=100000;
Lots=MathMax(MathMin(Lots,MarketInfo(Symbol(),MODE _MAXLOT)),MarketInfo(Symbol(),MODE_MINLOT));
double M_REQ=MarketInfo(Symbol(),MODE_MARGINREQUIRED);//nötige Margin für 1 Lot (100.000)
double A_FM=AccountFreeMargin();//verfügbare Margin
double A_BAL=AccountBalance();//momentaner Kontostand
double Min_L=MarketInfo(Symbol(),MODE_MINLOT);//Mindest_Lot_Einsatz
double Max_L=MarketInfo(Symbol(),MODE_MAXLOT);//Maximaler_Lot_Einsatz
//Einheiten von 1_Lot geteilt durch Mindest_Lot, um später auszurechnen, wie viel Margin für kleinst möglichstes Lot nötig ist.
double U1L_Min_L=NormalizeDouble(Units_of_1_Lot/Min_L*_Point,_Digits);
//Margin_für_1_Lot geteilt durch Ergebnis, um raus zu finden, wie viel Margin für Mindest_Lot benötigt wird.
double M_REQ_Min_L=M_REQ/U1L_Min_L;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(Percent_of_Free_Margin==true&&Percent_of_Balanc e==false){
// Free_Margin / Margin_für_Min_Lot, um rauszufinden, wie viel Min_Lot mit der Free_Margin möglich sind.
double A_FM_M_REQ_Min_L=A_FM/M_REQ_Min_L;
// P_ML = "Possible_Min_Lots" geteilt durch "HP" (Hundred_Percent)
double A_FM_P_ML_HP=A_FM_M_REQ_Min_L/100.0;
Lots=A_FM_P_ML_HP*Auto_Lotsize_Perc;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if((Percent_of_Balance==true)||(Percent_of_Balance ==true&&Percent_of_Free_Margin==true)){
// Kontostand geteilt durch für Min_Lot nötige Margin, um rauszufinden, wie viel Min_Lot mit Kontostand möglich sind.
double A_BAL_M_REQ_Min_L=A_BAL/M_REQ_Min_L;
// Mit Kontostand_mögliche_Mindest_Lots geteilt durch "HP" (hundred Percent)
double A_BAL_P_ML_HP=A_BAL_M_REQ_Min_L/100.0;
Lots=A_BAL_P_ML_HP*Auto_Lotsize_Perc;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(Lots<Min_L)Lots=Min_L;
if(Lots>Max_L)Lots=Max_L;