Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
I have been up and running with automated trading with Metatrader 4 for about a year now, but I'm trying to figure out Oanda's API using c++ now and I just don't understand about half of what is in the code. wondering if anyone here knows how to take what I have in a mql4 program and turn it into a c++ program that will work with the following example that I recieved from Oanda. Sorry it is so long, but this is what they gave me as an example... looks a lot harder to learn than was the MACD Sample that came with Metatrader! If someone could even just make a sample program of this type that was like the MACD sample I would really appreciate it!
Quote:
/*
Example 2
Comprehensive example of use of the FXTrade API
Ported from Java by Chris MacGregor, January 2006
*/
// get user selection
cout << endl
<< "Enter the account number or place in list to switch to [0]: ";
unsigned int accountNumber;
cin >> accountNumber;
// return if the user presses enter or 0
if (accountNumber == 0) return;
if (accountNumber <= accounts.size())
{
// if the input number is small, assume the user is picking from the list
g_account = accounts.at(accountNumber - 1);
accountNumber = g_account->accountId();
cout << "Now trading on account " << accountNumber << endl;
}
else
{
// otherwise, assume they tried to enter an actual account number
Account *temp = g_user->getAccountWithId(accountNumber);
// check if they actually did
if (temp == NULL)
{
cerr << accountNumber << " is not a valid account number"
<< ", current account not switched\n";
return;
}
else
{
cout << "Now trading on account " << accountNumber << endl;
g_account = temp;
}
}
}
void casePrintAccountData()
{
if (!g_fxclient.isLoggedIn()) return;
// print out some financial information for the current account
cout << endl
<< " Ticket | Type | Pair | Units | Price | Link
| Diaspora "
<< "| Time \n"
<<
"---------------------------------------------------------------------------------"
<< "-------------------------\n";
for (unsigned int count = 0; count < transactions.size(); count++)
{
Transaction t = transactions.at(count);
// convert timestamp time to string
const time_t temp = t.timestamp();
DateString ds = FXClient::timestampToString(temp);
//string timestamp = ctime(&temp);
//timestamp[24] = 0; // chomp newline from time string
// for Box orders, use 2-digit precision, otherwise, use 5-digit
string desc = t.getDescription();
int precision = 2;
if (desc.find("Box") == string::npos) precision = 5;
// get the number of units
cout << "Number of units [100]: ";
int numUnitsInput;
cin >> numUnitsInput;
if (numUnitsInput == 0) numUnitsInput = 100; //default to 100
marketOrder.units(numUnitsInput);
// find out if it's a buy or a sell
cout << "(B)uy or (S)ell [b]: ";
string buySell;
cin >> buySell;
bool buy = true; // default to buy
if (strcmp(buySell.c_str(), "") != 0) buy = (buySell[0] == 'B');
if (!buy) marketOrder.units(-1 * marketOrder.units()); // negative units for a
sell
void caseModifyMarketOrder()
{
if (!g_fxclient.isLoggedIn()) return;
// fetch and print a list of the users open market orders
vector<MarketOrder> marketOrders = g_account->getTrades();
if (marketOrders.size() == 0)
{
cout << "Cannot modify: no market orders currently open\n";
return;
}
caseListOpenMarketOrders();
// === fetch the market order to modify
MarketOrder marketOrder;
// get user selection
cout << "Please enter a ticket number or place in list [0]: ";
unsigned int ticket;
cin >> ticket;
// return if the user presses enter or 0
if (ticket == 0) return;
if (ticket <= marketOrders.size())
{
// if the ticket number is low, assume it is a list position
marketOrder = marketOrders.at(ticket - 1);
ticket = marketOrder.orderNumber();
}
else
{
// otherwise, get market order via ticket number
bool foundTrade = g_account->getTradeWithId(marketOrder, ticket);
if (!foundTrade) // Bail if the trade was not found
{
cerr << "Could not find market order #" << ticket << endl;
return;
}
}
// === get the updated stop loss and take profit for the market order
cout << "Stop Loss [" << marketOrder.stopLossOrder.price() << "]: ";
double tempSL;
cin >> tempSL;
if (tempSL != 0) marketOrder.stopLossOrder.price(tempSL);
void caseCloseMarketOrder()
{
if (!g_fxclient.isLoggedIn()) return;
// fetch and print a list of the users open trades
vector<MarketOrder> marketOrders = g_account->getTrades();
if (marketOrders.size() == 0)
{
cout << "Cannot modify: no market orders currently open\n";
return;
}
caseListOpenMarketOrders();
// === fetch the market order to modify
MarketOrder marketOrder;
// get user selection
cout << "Please enter a ticket number or place in list [0]: ";
unsigned int ticket;
cin >> ticket;
// return if the user presses enter or 0
if (ticket == 0) return;
if (ticket <= marketOrders.size())
{
// if the ticket number is low, assume it is a list position
marketOrder = marketOrders.at(ticket - 1);
ticket = marketOrder.orderNumber();
}
else
{
// otherwise, get market order via ticket number
bool foundTrade = g_account->getTradeWithId(marketOrder,
ticket);
if (!foundTrade) // Bail if the trade was not found
{
cerr << "Could not find market order #" << ticket <<
endl;
return;
}
}
// get the number of units
cout << "Number of units [100]: ";
int numUnitsInput;
cin >> numUnitsInput;
if (numUnitsInput == 0) numUnitsInput = 100; //default to 100
limitOrder.units(numUnitsInput);
// get whether it's a buy or a sell
cout << "(B)uy or (S)ell [b]: ";
string buySell;
cin >> buySell;
bool buy = true; // default to buy
if (strcmp(buySell.c_str(), "") != 0) buy = (buySell[0] == 'B');
if (!buy) limitOrder.units(-1 * limitOrder.units()); // negative units
for a sell
// get the price
double defaultQuote = buy?g_rateTable->getRate(pair).ask():
g_rateTable->getRate(pair).bid();
cout << "Quote [" << defaultQuote << "]: ";
double quote;
cin >> quote;
if (quote == 0) quote = defaultQuote;
limitOrder.price(quote);
// get the duration
cout << "Duration (in hours) [24]: ";
double hours;
cin >> hours;
if (hours == 0) hours = 24;
// since durations are stored as timestamps relative to server time, convert
the
// input hours to seconds and add it to the current server time (which is
// culled from an FXRate, since there's no direct access method)
limitOrder.duration(g_rateTable->getRate(pair).timestamp() + ((long)hours *
3600));
void caseModifyLimitOrder()
{
if (!g_fxclient.isLoggedIn()) return;
// fetch and print a list of the user's open limit orders
vector<LimitOrder> limitOrders = g_account->getOrders();
if (limitOrders.size() == 0)
{
cout << "Cannot modify: no limit orders currently in place\n";
return;
}
caseListOpenLimitOrders();
// === fetch the limit order to modify
LimitOrder limitOrder;
// get user selection
cout << "Please enter a ticket number or place in list [0]: ";
unsigned int ticket;
cin >> ticket;
// return if the user presses enter or 0
if (ticket == 0) return;
if (ticket <= limitOrders.size())
{
// if the ticket number is low, assume it is a list position
limitOrder = limitOrders.at(ticket - 1);
ticket = limitOrder.orderNumber();
}
else
{
// otherwise, get limit order via ticket number
bool foundTrade = g_account->getOrderWithId(limitOrder, ticket);
if (!foundTrade) // Bail if the trade was not found
{
cerr << "Could not find limit order #" << ticket <<
endl;
return;
}
}
void caseCancelLimitOrder()
{
if (!g_fxclient.isLoggedIn()) return;
// fetch and print a list of the users open market orders
vector<LimitOrder> limitOrders = g_account->getOrders();
if (limitOrders.size() == 0)
{
cout << "Cannot modify: no limit orders currently in place\n";
return;
}
caseListOpenLimitOrders();
// === fetch the market order to modify
LimitOrder limitOrder;
// get user selection
cout << "Please enter a ticket number or place in list [0]: ";
unsigned int ticket;
cin >> ticket;
// return if the user presses enter or 0
if (ticket == 0) return;
if (ticket <= limitOrders.size())
{
// if the ticket number is low, assume it is a list position
limitOrder = limitOrders.at(ticket - 1);
ticket = limitOrder.orderNumber();
}
else
{
// otherwise, get market order via ticket number
bool foundTrade = g_account->getOrderWithId(limitOrder, ticket);
if (!foundTrade) // Bail if the trade was not found
{
cerr << "Could not find limit order #" << ticket <<
endl;
return;
}
}
void casePrintRateHistory()
{
if (!g_fxclient.isLoggedIn()) return;
// get the currency pair
cout << endl << "Pair [EUR/USD]: ";
string pairInput;
cin >> pairInput;
FXPair pair;
if (strcmp(pairInput.c_str(), "") == 0) pair.pair("EUR/USD");
else pair.pair(pairInput.c_str());
// get the interval
cout << "Please enter the interval in seconds [5]: ";
long interval;
cin >> interval;
if (interval == 0) interval = 5;
interval *= 1000; // convert to milliseconds
// get the number of ticks
cout << "Please enter the number of ticks (max 500) [100]: ";
int ticks;
cin >> ticks;
if (ticks == 0) ticks = 100; // default to 100 ticks
if (ticks > 500) ticks = 500;
// make the history request
cout << "Requesting desired rate information...";
Please!!! Anybody that can help, I feel so lost looking at this and I really want to use Oanda's API since the spreads are much cheaper there and they don't have the requotes and restrictions about where you can put your orders in at.