commit [14/03/2018]
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,393 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CTrade_Sample_EA.mq5 |
|
||||
//| Copyright 2012, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2012, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#include<Trade\Trade.mqh>
|
||||
#property description "This Expert Advisor shows some examples of working "
|
||||
#property description "with CTrade class. Its functions are not called."
|
||||
|
||||
//--- object for performing trade operations
|
||||
CTrade trade;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- set MagicNumber for your orders identification
|
||||
int MagicNumber=123456;
|
||||
trade.SetExpertMagicNumber(MagicNumber);
|
||||
//--- set available slippage in points when buying/selling
|
||||
int deviation=10;
|
||||
trade.SetDeviationInPoints(deviation);
|
||||
//--- order execution mode
|
||||
trade.SetTypeFilling(ORDER_FILLING_RETURN);
|
||||
//--- logging mode: it would be better not to declare this method at all, the class will set the best mode on its own
|
||||
trade.LogLevel(1);
|
||||
//--- what function is to be used for trading: true - OrderSendAsync(), false - OrderSend()
|
||||
trade.SetAsyncMode(true);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//--- Buy sample
|
||||
//+------------------------------------------------------------------+
|
||||
//| Buying a specified volume at the current symbol |
|
||||
//+------------------------------------------------------------------+
|
||||
void BuySample1()
|
||||
{
|
||||
//--- 1. example of buying at the current symbol
|
||||
if(!trade.Buy(0.1))
|
||||
{
|
||||
//--- failure message
|
||||
Print("Buy() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Buying with specified volume and symbol |
|
||||
//+------------------------------------------------------------------+
|
||||
void BuySample2()
|
||||
{
|
||||
//--- 2. example of buying at the specified symbol
|
||||
if(!trade.Buy(0.1,"GBPUSD"))
|
||||
{
|
||||
//--- failure message
|
||||
Print("Buy() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Buying with specifying all order parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
void BuySample3()
|
||||
{
|
||||
//--- 3. example of buying at the specified symbol with specified SL and TP
|
||||
double volume=0.1; // specify a trade operation volume
|
||||
string symbol="GBPUSD"; //specify the symbol, for which the operation is performed
|
||||
int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places
|
||||
double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point
|
||||
double bid=SymbolInfoDouble(symbol,SYMBOL_BID); // current price for closing LONG
|
||||
double SL=bid-1000*point; // unnormalized SL value
|
||||
SL=NormalizeDouble(SL,digits); // normalizing Stop Loss
|
||||
double TP=bid+1000*point; // unnormalized TP value
|
||||
TP=NormalizeDouble(TP,digits); // normalizing Take Profit
|
||||
//--- receive the current open price for LONG positions
|
||||
double open_price=SymbolInfoDouble(symbol,SYMBOL_ASK);
|
||||
string comment=StringFormat("Buy %s %G lots at %s, SL=%s TP=%s",
|
||||
symbol,volume,
|
||||
DoubleToString(open_price,digits),
|
||||
DoubleToString(SL,digits),
|
||||
DoubleToString(TP,digits));
|
||||
if(!trade.Buy(volume,symbol,open_price,SL,TP,comment))
|
||||
{
|
||||
//--- failure message
|
||||
Print("Buy() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//--- Examples for placing a limit order
|
||||
//+------------------------------------------------------------------+
|
||||
//| Placing a limit order at the current symbol |
|
||||
//+------------------------------------------------------------------+
|
||||
void BuyLimit_Sample1()
|
||||
{
|
||||
//--- 1. example of placing a Buy Limit pending order
|
||||
string symbol="GBPUSD"; // specify the symbol, at which the order is placed
|
||||
int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places
|
||||
double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point
|
||||
double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price
|
||||
double price=1000*point; // unnormalized open price
|
||||
price=NormalizeDouble(price,digits); // normalizing open price
|
||||
//--- everything is ready, sending a Buy Limit pending order to the server
|
||||
if(!trade.BuyLimit(0.1,price))
|
||||
{
|
||||
//--- failure message
|
||||
Print("BuyLimit() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("BuyLimit() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Placing a limit order specifying all the parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
void BuyLimit_Sample2()
|
||||
{
|
||||
//--- 2. example of placing a Buy Limit pending order with all parameters
|
||||
double volume=0.1;
|
||||
string symbol="GBPUSD"; // specify the symbol, at which the order is placed
|
||||
int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places
|
||||
double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point
|
||||
double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price
|
||||
double price=1000*point; // unnormalized open price
|
||||
price=NormalizeDouble(price,digits); // normalizing open price
|
||||
int SL_pips=300; // Stop Loss in points
|
||||
int TP_pips=500; // Take Profit in points
|
||||
double SL=price-SL_pips*point; // unnormalized SL value
|
||||
SL=NormalizeDouble(SL,digits); // normalizing Stop Loss
|
||||
double TP=price+TP_pips*point; // unnormalized TP value
|
||||
TP=NormalizeDouble(TP,digits); // normalizing Take Profit
|
||||
datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_D1);
|
||||
string comment=StringFormat("Buy Limit %s %G lots at %s, SL=%s TP=%s",
|
||||
symbol,volume,
|
||||
DoubleToString(price,digits),
|
||||
DoubleToString(SL,digits),
|
||||
DoubleToString(TP,digits));
|
||||
//--- everything is ready, sending a Buy Limit pending order to the server
|
||||
if(!trade.BuyLimit(volume,price,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment))
|
||||
{
|
||||
//--- failure message
|
||||
Print("BuyLimit() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("BuyLimit() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//--- Examples for placing a stop order
|
||||
//+------------------------------------------------------------------+
|
||||
//| Placing a stop order at the current symbol |
|
||||
//+------------------------------------------------------------------+
|
||||
void BuyStop_Sample1()
|
||||
{
|
||||
//--- 1. example of placing a Buy Stop pending order
|
||||
string symbol="USDJPY"; // specify the symbol, at which the order is placed
|
||||
int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places
|
||||
double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point
|
||||
double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price
|
||||
double price=1000*point; // unnormalized open price
|
||||
price=NormalizeDouble(price,digits); // normalizing open price
|
||||
//--- everything is ready, sending a Buy Stop pending order to the server
|
||||
if(!trade.BuyStop(0.1,price))
|
||||
{
|
||||
//--- failure message
|
||||
Print("BuyStop() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("BuyStop() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Placing a stop order specifying all the parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
void BuyStop_Sample2()
|
||||
{
|
||||
//--- 2. example of placing a Buy Stop pending order with all parameters
|
||||
double volume=0.1;
|
||||
string symbol="USDJPY"; // specify the symbol, at which the order is placed
|
||||
int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places
|
||||
double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point
|
||||
double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price
|
||||
double price=1000*point; // unnormalized open price
|
||||
price=NormalizeDouble(price,digits); // normalizing open price
|
||||
int SL_pips=300; // Stop Loss in points
|
||||
int TP_pips=500; // Take Profit in points
|
||||
double SL=price-SL_pips*point; // unnormalized SL value
|
||||
SL=NormalizeDouble(SL,digits); // normalizing Stop Loss
|
||||
double TP=price+TP_pips*point; // unnormalized TP value
|
||||
TP=NormalizeDouble(TP,digits); // normalizing Take Profit
|
||||
datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_D1);
|
||||
string comment=StringFormat("Buy Stop %s %G lots at %s, SL=%s TP=%s",
|
||||
symbol,volume,
|
||||
DoubleToString(price,digits),
|
||||
DoubleToString(SL,digits),
|
||||
DoubleToString(TP,digits));
|
||||
//--- everything is ready, sending a Buy Stop pending order to the server
|
||||
if(!trade.BuyStop(volume,price,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment))
|
||||
{
|
||||
//--- failure message
|
||||
Print("BuyStop() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("BuyStop() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//--- Examples for working with positions
|
||||
//+------------------------------------------------------------------+
|
||||
//| Position opening |
|
||||
//+------------------------------------------------------------------+
|
||||
void Open()
|
||||
{
|
||||
//--- number of decimal places
|
||||
int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);
|
||||
//--- point value
|
||||
double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
|
||||
//--- receiving a buy price
|
||||
double price=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
|
||||
//--- calculate and normalize SL and TP levels
|
||||
double SL=NormalizeDouble(price-1000*point,digits);
|
||||
double TP=NormalizeDouble(price+1000*point,digits);
|
||||
//--- filling comments
|
||||
string comment="Buy "+_Symbol+" 0.1 at "+DoubleToString(price,digits);
|
||||
//--- everything is ready, trying to open a buy position
|
||||
if(!trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,0.1,price,SL,TP,comment))
|
||||
{
|
||||
//--- failure message
|
||||
Print("PositionOpen() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("PositionOpen() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Closing a position specifying only a symbol |
|
||||
//+------------------------------------------------------------------+
|
||||
void Close()
|
||||
{
|
||||
//--- closing a position at the current symbol
|
||||
if(!trade.PositionClose(_Symbol))
|
||||
{
|
||||
//--- failure message
|
||||
Print("PositionClose() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("PositionClose() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Modification for Long position of StopLoss and TakeProfit levels|
|
||||
//+------------------------------------------------------------------+
|
||||
void ModifyPosition()
|
||||
{
|
||||
//--- number of decimal places
|
||||
int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);
|
||||
//--- point value
|
||||
double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
|
||||
//--- receiving the current Bid price
|
||||
double price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
|
||||
//--- calculate and normalize SL and TP levels
|
||||
double SL=NormalizeDouble(price-1000*point,digits);
|
||||
double TP=NormalizeDouble(price+1000*point,digits);
|
||||
//--- everything is ready, trying to modify the buy position
|
||||
if(!trade.PositionModify(_Symbol,SL,TP))
|
||||
{
|
||||
//--- failure message
|
||||
Print("Ìåòîä PositionModify() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("PositionModify() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//--- Examples for working with orders
|
||||
//+------------------------------------------------------------------+
|
||||
//| Deleting an order by its ticket |
|
||||
//+------------------------------------------------------------------+
|
||||
void DeleteOrder()
|
||||
{
|
||||
//--- this is a sample order ticket, it should be received
|
||||
ulong ticket=1234556;
|
||||
//--- everything is ready, trying to modify the buy position
|
||||
if(!trade.OrderDelete(ticket))
|
||||
{
|
||||
//--- failure message
|
||||
Print("OrderDelete() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("OrderDelete() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Modifying a pending order |
|
||||
//+------------------------------------------------------------------+
|
||||
void ModifyOrder()
|
||||
{
|
||||
//--- this is a sample order ticket, it should be received
|
||||
ulong ticket=1234556;
|
||||
//--- this is a sample symbol, it should be received
|
||||
string symbol="EURUSD";
|
||||
//--- number of decimal places
|
||||
int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
|
||||
//--- point value
|
||||
double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
|
||||
//--- receiving a buy price
|
||||
double price=SymbolInfoDouble(symbol,SYMBOL_ASK);
|
||||
//--- calculate and normalize SL and TP levels
|
||||
//--- they should be calculated based on the order type
|
||||
double SL=NormalizeDouble(price-1000*point,digits);
|
||||
double TP=NormalizeDouble(price+1000*point,digits);
|
||||
//--- setting one day as a lifetime
|
||||
datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_D1);
|
||||
//--- everything is ready, trying to modify the order
|
||||
if(!trade.OrderModify(ticket,price,SL,TP,ORDER_TIME_GTC,expiration))
|
||||
{
|
||||
//--- failure message
|
||||
Print("OrderModify() method failed. Return code=",trade.ResultRetcode(),
|
||||
". Code description: ",trade.ResultRetcodeDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("OrderModify() method executed successfully. Return code=",trade.ResultRetcode(),
|
||||
" (",trade.ResultRetcodeDescription(),")");
|
||||
}
|
||||
//---
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,69 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Demo_CAccountInfo.mq5 |
|
||||
//| Copyright 2012, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2012, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
|
||||
#include <Trade\AccountInfo.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- object for working with the account
|
||||
CAccountInfo account;
|
||||
//--- receiving the account number, the Expert Advisor is launched at
|
||||
long login=account.Login();
|
||||
Print("Login=",login);
|
||||
//--- clarifying account type
|
||||
ENUM_ACCOUNT_TRADE_MODE account_type=account.TradeMode();
|
||||
//--- if the account is real, the Expert Advisor is stopped immediately!
|
||||
if(account_type==ACCOUNT_TRADE_MODE_REAL)
|
||||
{
|
||||
MessageBox("Trading on a real account is forbidden, disabling","The Expert Advisor has been launched on a real account!");
|
||||
return(-1);
|
||||
}
|
||||
//--- displaying the account type
|
||||
Print("Account type: ",EnumToString(account_type));
|
||||
//--- clarifying if we can trade on this account
|
||||
if(account.TradeAllowed())
|
||||
Print("Trading on this account is allowed");
|
||||
else
|
||||
Print("Trading on this account is forbidden: you may have entered using the Investor password");
|
||||
//--- clarifying if we can use an Expert Advisor on this account
|
||||
if(account.TradeExpert())
|
||||
Print("Automated trading on this account is allowed");
|
||||
else
|
||||
Print("Automated trading using Expert Advisors and scripts on this account is forbidden");
|
||||
//--- if the permissible number of orders has been set
|
||||
int orders_limit=account.LimitOrders();
|
||||
if(orders_limit!=0)Print("Maximum permissible amount of active pending orders: ",orders_limit);
|
||||
//--- displaying company and server names
|
||||
Print(account.Company(),": server ",account.Server());
|
||||
//--- displaying balance and current profit on the account in the end
|
||||
Print("Balance=",account.Balance()," Profit=",account.Profit()," Equity=",account.Equity());
|
||||
//--- final display
|
||||
Print(__FUNCTION__," completed");
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,69 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Demo_CSymbolInfo.mq5 |
|
||||
//| Copyright 2012, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2012, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
|
||||
#include<Trade\SymbolInfo.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- object for receiving symbol settings
|
||||
CSymbolInfo symbol_info;
|
||||
//--- set the name for the appropriate symbol
|
||||
symbol_info.Name(_Symbol);
|
||||
//--- receive current rates and display
|
||||
symbol_info.RefreshRates();
|
||||
Print(symbol_info.Name()," (",symbol_info.Description(),")",
|
||||
" Bid=",symbol_info.Bid()," Ask=",symbol_info.Ask());
|
||||
//--- receive minimum freeze levels for trade operations
|
||||
Print("StopsLevel=",symbol_info.StopsLevel()," pips, FreezeLevel=",
|
||||
symbol_info.FreezeLevel()," pips");
|
||||
//--- receive the number of decimal places and point size
|
||||
Print("Digits=",symbol_info.Digits(),
|
||||
", Point=",DoubleToString(symbol_info.Point(),symbol_info.Digits()));
|
||||
//--- spread data
|
||||
Print("SpreadFloat=",symbol_info.SpreadFloat(),", Spread(current)=",
|
||||
symbol_info.Spread()," pips");
|
||||
//--- request order execution type for limitations
|
||||
Print("Limitations for trade operations: ",EnumToString(symbol_info.TradeMode()),
|
||||
" (",symbol_info.TradeModeDescription(),")");
|
||||
//--- clarifying trades execution mode
|
||||
Print("Trades execution mode: ",EnumToString(symbol_info.TradeExecution()),
|
||||
" (",symbol_info.TradeExecutionDescription(),")");
|
||||
//--- clarifying contracts price calculation method
|
||||
Print("Contract price calculation: ",EnumToString(symbol_info.TradeCalcMode()),
|
||||
" (",symbol_info.TradeCalcModeDescription(),")");
|
||||
//--- contracts' size
|
||||
Print("Standard contract size: ",symbol_info.ContractSize(),
|
||||
" (",symbol_info.CurrencyBase(),")");
|
||||
//--- minimum and maximum volumes in trade operations
|
||||
Print("Volume info: LotsMin=",symbol_info.LotsMin()," LotsMax=",symbol_info.LotsMax(),
|
||||
" LotsStep=",symbol_info.LotsStep());
|
||||
//--- final display
|
||||
Print(__FUNCTION__," completed");
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,49 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Demo_CTrade.mq5 |
|
||||
//| Copyright 2012, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2012, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
|
||||
#include<Trade\Trade.mqh>
|
||||
//--- object for performing trade operations
|
||||
CTrade trade;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- set MagicNumber for your orders identification
|
||||
int MagicNumber=123456;
|
||||
trade.SetExpertMagicNumber(MagicNumber);
|
||||
//--- set available slippage in points when buying/selling
|
||||
int deviation=10;
|
||||
trade.SetDeviationInPoints(deviation);
|
||||
//--- order execution mode
|
||||
trade.SetTypeFilling(ORDER_FILLING_RETURN);
|
||||
//--- logging mode
|
||||
trade.LogLevel(1); // it would be better not to declare this method at all, the class will set the best mode on its own
|
||||
//--- what function is to be used for trading: true - OrderSendAsync(), false - OrderSend()
|
||||
trade.SetAsyncMode(true);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//---
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user