#define VOLUME 1.0 // Auftragsvolumen
#define DEVIATION 100 // Abstand für das Platzieren von schwebenden Aufträgen
#define STOP_LIMIT 50 // Abstand eines StopLimit-Auftrages distance
//+------------------------------------------------------------------+
//| Skript Programm Start Funktion |
//+------------------------------------------------------------------+
void OnStart()
{
string currency=AccountInfoString(ACCOUNT_CURRENCY);
int array_types[8]={ORDER_TYPE_BUY,
ORDER_TYPE_SELL,
ORDER_TYPE_BUY_LIMIT,
ORDER_TYPE_SELL_LIMIT,
ORDER_TYPE_BUY_STOP,
ORDER_TYPE_SELL_STOP,
ORDER_TYPE_BUY_STOP_LIMIT,
ORDER_TYPE_SELL_STOP_LIMIT };
//--- in einer Schleife durch das Ordertyp-Array
for(int i=0; i<(int)array_types.Size(); i++)
{
//--- abhängig vom Ordertyp, entweder ORDER_TYPE_BUY oder ORDER_TYPE_SELL
ENUM_ORDER_TYPE type=MarketOrderByOrderType((ENUM_ORDER_TYPE)array_types[i]);
//--- abhängig vom Auftragstyp den Preis abrufen
double price=PriceByOrderType(_Symbol, type);
//--- Abrufen des Margenbetrags, der für die „action“-angegebenen Auftragstyp benötigt wird
double margin=EMPTY_VALUE;
ResetLastError();
if(!OrderCalcMargin(type, _Symbol, VOLUME, price, margin))
{
Print("OrderCalcMargin() failed. Error ",GetLastError());
continue;
}
//--- Ausdruck des Ergebnisses im Journal
PrintFormat("Margin required for %.2f %s order at price %.*f on %s symbol: %.2f %s", VOLUME, OrderTypeDescription((ENUM_ORDER_TYPE)i), _Digits, price, _Symbol, margin, currency);
}
/*
Ergebnis:
Margin required for 1.00 Buy order at price 1.31668 on GBPUSD symbol: 1316.68 USD
Margin required for 1.00 Sell order at price 1.31661 on GBPUSD symbol: 1316.61 USD
Margin required for 1.00 Buy Limit order at price 1.31568 on GBPUSD symbol: 1315.68 USD
Margin required for 1.00 Sell Limit order at price 1.31761 on GBPUSD symbol: 1317.61 USD
Margin required for 1.00 Buy Stop order at price 1.31768 on GBPUSD symbol: 1317.68 USD
Margin required for 1.00 Sell Stop order at price 1.31561 on GBPUSD symbol: 1315.61 USD
Margin required for 1.00 Buy Stop Limit order at price 1.31718 on GBPUSD symbol: 1317.18 USD
Margin required for 1.00 Sell Stop Limit order at price 1.31611 on GBPUSD symbol: 1316.11 USD
*/
}
//+------------------------------------------------------------------+
//| Rückgabe des Auftragstyps „Kaufen“-oder „Verkaufen“- |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE MarketOrderByOrderType(ENUM_ORDER_TYPE type)
{
switch(type)
{
case ORDER_TYPE_BUY : case ORDER_TYPE_BUY_LIMIT : case ORDER_TYPE_BUY_STOP : case ORDER_TYPE_BUY_STOP_LIMIT :
return(ORDER_TYPE_BUY);
case ORDER_TYPE_SELL : case ORDER_TYPE_SELL_LIMIT : case ORDER_TYPE_SELL_STOP : case ORDER_TYPE_SELL_STOP_LIMIT :
return(ORDER_TYPE_SELL);
}
return(WRONG_VALUE);
}
//+------------------------------------------------------------------+
//| Rückgabe des Eröffnungspreises nach Auftragsart |
//+------------------------------------------------------------------+
double PriceByOrderType(const string symbol, const ENUM_ORDER_TYPE order_type)
{
int digits=0;
double point=0;
MqlTick tick={};
//--- Abrufen vom Punktwert des Symbols
ResetLastError();
if(!SymbolInfoDouble(symbol, SYMBOL_POINT, point))
{
Print("SymbolInfoDouble() failed. Error ", GetLastError());
return 0;
}
//--- Abrufen der Anzahl der Dezimalen des Symbols
long value=0;
if(!SymbolInfoInteger(symbol, SYMBOL_DIGITS, value))
{
Print("SymbolInfoInteger() failed. Error ", GetLastError());
return 0;
}
digits=(int)value;
//--- Aktuelle Preise eines Symbols abrufen
if(!SymbolInfoTick(symbol, tick))
{
Print("SymbolInfoTick() failed. Error ", GetLastError());
return 0;
}
//--- Preis abhängig von der Auftragsart zurückgeben
switch(order_type)
{
case ORDER_TYPE_BUY : return(tick.ask);
case ORDER_TYPE_SELL : return(tick.bid);
case ORDER_TYPE_BUY_LIMIT : return(NormalizeDouble(tick.ask - DEVIATION * point, digits));
case ORDER_TYPE_SELL_LIMIT : return(NormalizeDouble(tick.bid + DEVIATION * point, digits));
case ORDER_TYPE_BUY_STOP : return(NormalizeDouble(tick.ask + DEVIATION * point, digits));
case ORDER_TYPE_SELL_STOP : return(NormalizeDouble(tick.bid - DEVIATION * point, digits));
case ORDER_TYPE_BUY_STOP_LIMIT : return(NormalizeDouble(tick.ask + DEVIATION * point - STOP_LIMIT * point, digits));
case ORDER_TYPE_SELL_STOP_LIMIT : return(NormalizeDouble(tick.bid - DEVIATION * point + STOP_LIMIT * point, digits));
default : return(0);
}
}
//+------------------------------------------------------------------+
//| Rückgabe der Beschreibung des Auftragstyps |
//+------------------------------------------------------------------+
string OrderTypeDescription(const ENUM_ORDER_TYPE order_type)
{
switch(order_type)
{
case ORDER_TYPE_BUY : return("Buy");
case ORDER_TYPE_SELL : return("Sell");
case ORDER_TYPE_BUY_LIMIT : return("Buy Limit");
case ORDER_TYPE_SELL_LIMIT : return("Sell Limit");
case ORDER_TYPE_BUY_STOP : return("Buy Stop");
case ORDER_TYPE_SELL_STOP : return("Sell Stop");
case ORDER_TYPE_BUY_STOP_LIMIT : return("Buy Stop Limit");
case ORDER_TYPE_SELL_STOP_LIMIT : return("Sell Stop Limit");
case ORDER_TYPE_CLOSE_BY : return("Close By");
default : return("Unknown order type");
}
}
//+------------------------------------------------------------------+
|