|
Startseite | Registrieren | Hilfe | Benutzerliste | Kalender | Suchen | Heutige Beiträge | Alle Foren als gelesen markieren |
Programmierung MQL4 Hier gehts rund ums Programmieren in MQL4. |
|
Themen-Optionen | Thema durchsuchen | Ansicht |
|
|||
OrderHistory als Basis für Lotsize
Hallo,
mein EA soll die Lotgröße abhängig vom Ergebnis der letzten Trades bestimmen. Den Anfangswert von lots kann der User selbst eintragen. Die Anfangsgröße von lots soll in meinem Beispiel 0.4 sein. Fall 1: Letzter Trade war positiv => Lotsize für nächsten Trade soll 1*lots sein Fall 2: Letzter Trade war negativ => Lotsize für nächsten Trade soll 2*lots sein Fall 3: Die Letzten beiden Trades waren negativ => Lotsize für nächsten Trade soll 3*lots sein Mit folgenden Code klappt das auch. Allerdings nur mit den festen Konstanten 0.4, 0.8 und 1.2. Code:
//+------------------------------------------------------------------+ //| 01_Lot.mqh | //| Hylocharis | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Hylocharis" #property link "http://www.mql5.com" #property strict //----------------------------------------------------------------------------- 1 -- // Function calculating the amount of lots. // Global variables: // double lots_new - the amount of lots for new orders (calculated) // double lots - the desired amount of lots defined by the user. // int percent - max loss of balance in percentage per trade defined by the user // Returned values: // true - if there is enough money for the minimum volume // false - if there is no enough money for the minimum volume //----------------------------------------------------------------------------- 2 -- bool Lot() // User-defined function { string symbol = Symbol(); // Symbol double one_lot = MarketInfo(symbol,MODE_MARGINREQUIRED);//!-lot cost double min_lot = MarketInfo(symbol,MODE_MINLOT);// Min. amount of lots double step = MarketInfo(symbol,MODE_LOTSTEP);//Step in volume changing double tick_value = MarketInfo(Symbol(),MODE_TICKVALUE); double free_margin = AccountFreeMargin(); // Free margin double new_balance =(AccountBalance()+AccountProfit()); // amount of money on the account double max_loss; //----------------------------------------------------------------------------- 3 -- if (lots>0) // Volume is explicitly set.. { // ..check it double money = lots * one_lot; // Order cost if(money <= AccountFreeMargin()) // Free margin covers it.. { int cnt=0; double profit; int ls = 1; lots_new = lots; //Lot - initiale LotSize if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.01) ls = 2; for(int i=OrdersHistoryTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == 3333) { profit = OrderProfit(); if (profit < 0) cnt++; else { if (cnt == 0) { //lots_new = NormalizeDouble(lots, ls); lots_new = 0.4; } if (cnt == 1) { //lots_new = NormalizeDouble(lots*2, ls); lots_new = 0.8; } if (cnt >= 2) { //lots_new = NormalizeDouble(lots*3, ls); lots_new = 1.2; } break; } } } } } else // If free margin is not enough.. lots_new=MathFloor(free_margin/one_lot/step)*step;// Calculate lots } //----------------------------------------------------------------------------- 4 -- if (lots_new < min_lot) // If it is less than allowed.. lots_new = min_lot; // .. then minimum if (lots_new * one_lot > AccountFreeMargin())// It isn't enough even.. { // ..for the min. lot:( Inform(11,0,min_lot); // Message.. return(false); // ..and exit } return(true); // Exit user-defined function } //----------------------------------------------------------------------------- 6 -- Wie kann ich das richtig programmieren? |
|
|||
Das ganze nett sich Martingale (bzw eine Form davon) und killt zuverlässig jeden Account.
|
|
|||
Dass die Martingale Strategie irgendwann den Account killt, davon bin ich auch überzeugt. Deshalb möchte ich meine Lotsize auch nur max. 2 mal erhöhen. Von 0.4 auf 0.8 und ggf. auf 1.2. Danach ist Schluss mit erhöhen. Sobald dann ein Trade mit Profit abgeschlossen wird, fange ich wieder bei 0.4 an. Die Backtests mit dieser Strategie haben bisher ein recht vernünftiges Ergebnis abgeliefert.
|
|
|||
Da würde ich die die Recovery Funktion des WSFR empfehlen.
Der verdoppelt nicht sondern erhöht ganz leicht. Das solltest über die mathematische Steigung (y=mx+t) gut hinbekommen. Die Steigung m ist dein Risiko pro Trade. Sagen wir 3%. Und dann die Lotsize im Verhältnis zum Minusabstand der Equity zur Steigung erhöhen. Ist auf Dauer viel sicherer. Geändert von PortfolioTrader (25.06.14 um 22:14 Uhr) Grund: typo |
Lesezeichen |
Stichworte |
historie, lotgröße, lotsize, mql4, order historie, order historie lotgröße, orderhistorie lotgröße, orderhistory lotsize, programmierung, programmierung metatrader |
Themen-Optionen | Thema durchsuchen |
Ansicht | |
|
|