You need to enable JavaScript in order to visit our site!
 
Logo PTMC
NAVIGATION
CANCEL
 
or via PTMC account
Restore password
or via PTMC account
Logo PTMC
NAVIGATION
or via PTMC account
Restore password
or via PTMC account
or via PTMC account
Restore password
or via PTMC account
Mac Mac 28.01 2014

Automated Trading Operations in Protrader (C#)

Introduction

Trading operations in Protrader can be separated into the following three operations:

1. Formation of a request

2. Sending of a request

3. Receiving information about a result: opening of a position or an error message

Before performing any of these operations on an account you should check to make sure that the platform is connected to the server and receiving actual market information.

You can check the status of your connection to the broker’s server with the following piece of code:

//This checks whether the platform is connected to the broker server
//if there is no connection a message is logged
if(IsConnected()==false)
{
Print("Check Connection!");
return;
}

You can check the presence of quotes for a given instrument with the following piece of code:

//here we make the object lastQuote
Quote lastQuote = Instruments.Current.LastQuote;
//here we check whether there are quotes coming in for this instrument
//if there are no quotes a message is logged
if (lastQuote==null)
{
Print("No price available!");
return;
}

When you form a request you need to specify your operation parameters. For example, if you want to buy one lot of the current instrument Forming a requerst:

request = new NewOrderRequest();
//instrument
request.Instrument = Instruments.Current;
//account
request.Account = Accounts.Current;
//volume
request.Amount = 1;
//side
request.Side = Operation.Buy;
//stop loss in ticks or pips relative to opening order price
request.StopLossOffset = 400.0;
//take profit in ticks or pips relative to opening order price
request.TakeProfitOffset = 1000.0;
//maximum slippage
request.MarketRange = 10;
//order type
request.Type = OrdersType.Market;

This is a completed request and now you can send it to a server with the method Orders.Send(...):

Orders.Send(NewOrderRequest request);

Here you can use the prepared request as a method parameter:

//send the request and save the order identifier
//in the orderId field for future use
string orderId = Orders.Send(request);
//the identifier is entered into the log;
//if there is an error in the trading operation the orderId will be -1;
Print(orderId);

You can get the full code here: SimpleBuy.cs. After starting the trading system SimpleBuy a long position will be opened for the current instrument. Systems SimpleSell.cs , SimpleBuyStop.cs , SimpleBuyLimit.cs work similarly. The code in these files are provided with detailed commentary. Download and try this and if there are any questions ask them below or on the forum.

The system SimpleCloseAll.cs closes all open positions for the current account:

//this closes all opened positions for the current account
allPosClosed = Positions.CloseAllByAccount( Accounts.Current );
if(allPosClosed == true)
{
Print("All Position Closed");
}

Upon successful completion the type bool allPosClosed is assigned the value true. In the examples there we showed the functions OnQuote() и Complete(). The function OnQuote() launches each time there is a new quote. If you system doesn’t require analysis of Level2 or trades, you can rely entirely on this function. For example I built the Regression Trader system in this way. The function Complete() is called before at the end-point of the system.

Conclusion

Of course, in real life a system that simply buys and sells orders after we press the button is not very useful to us. Algorithmic systems should ideally receive and analyze market information, open and close positions based on this information, and then modify orders based on conditions or react accordingly based on the market situation.

The methods for receiving information in Protrader (real time quotes and historical data) will be our next topic.

SimpleBuy.cs , SimpleSell.cs , SimpleBuyStop.cs , SimpleBuyLimit.cs , SimpleCloseAll.cs , Regression Trader

Discussion
Join PTMC community to post your comments
No comments yet. Be the first.
PTMC 是一個專業的交易平台,結合了強大的圖表和分析工具,並可在不同的金融市場進行交易。 它是由 PFSOFT UK LTD 開發的,該公司是全球銀行和經紀商交易技術提供商
© 2024. PTMC 為基於 Protrader 技術的專業交易平台
地址
臺北市大安區羅斯福路3段273號5樓
聯絡我們
電話: +886-2-2367-8583
E-mail: service@kcdatanet.com
社群
© 2024. PTMC 為基於 Protrader 技術的專業交易平台