NexusFi: Find Your Edge


Home Menu

 





First automated order handling system


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,837 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
TahuPhoenix
Lund Sweden
 
Posts: 4 since Feb 2015
Thanks Given: 1
Thanks Received: 0

Dear Forums,

I'm currently trying to write my first automated order handling system. This appeared to be a little more difficult because of the limitations of testing it. Thus, I hope I could get some feedback from some of the more experienced PL/EL-programmers here on NexusFi (formerly BMT).

Code is intented to be used by the Portfolio Trader. My thoughts for the code is the following:

- If a buy signal is generated: Determine order size(in cash) by checking the current cash liquidity on the account. Don't place any orders if there are Open Positions already.

- Determine order size(in shares) by taking my order size(in cash) and dividing by bid/ask.

- Place a buy order between 10 and 11. First, place a bid order and a SL to this. If the order doesn't go through and the clock passes 11, take the current asked price (market order).

- Place a sell order three days after the buy order came through between 10 and 11. First, place a ask order. If the order doesn't go through and the clock passes 11, take the current bid price (market order).

- If the spread is 7 % or higher, then don't place any market orders.


Note: Data1 is minute-to-minute and Data2 is day-to-day resolution.

The Code:
 
Code
Inputs:
	minimumorder(1000),
	maximumorder(2000),
	accountIDUsed("Test123");

Vars:
	Intrabarpersist nextOrdSize(0),
	Intrabarpersist wantToBuy(false),
        Intrabarpersist nbrOfShares(1),
	Intrabarpersist buyWait(false),
	Intrabarpersist sellWait(false);
	

condition1 = EXTERNAL_BUY_SIGNAL; //Pseudo-code
condition2 = EXTERNAL_ACCOUNT_CONDITION; //Pseudo-code
condition3 = EXTERNAL_ACCOUNT_CONDITION2; //Pseudo-code


{ Account and Order Conditions }

if GetPositionTotalCost(getsymbolname(), accountIDUsed) <= 0 and GetBDCashBalance(accountIDUsed) >= minimumorder and condition1 then
begin
	wantToBuy = true;
	if condition2 then
	begin
		nextOrdSize = minimumorder;
	end
	else if condition3 then
	begin
		nextOrdSize = maximumorder;
	end;
end;

{ ======================= }

{ BUY }

if GetPositionTotalCost(getsymbolname(), accountIDUsed) <= 0 then
begin
	if wantToBuy and Time[1] >= 1000 and Time < 1100 and buyWait = false then
	begin
		nbrOfShares = nextOrdSize/CurrentBid;
		Buy (getsymbolname() + "_BuyOrder_bid") nbrOfShares shares next bar at CurrentBid Limit;
		buyWait = true;
		
		// Calculate Stop Loss
		setstopposition;
		setstoploss(nextOrdSize * 0.08);
	end;

	if buyWait and Time >= 1100 then
	begin
		nbrOfShares = nextOrdSize/CurrentAsk;
		if ((CurrentAsk - CurrentBid)/CurrentAsk)*100 < 7 then
		begin
			Buy (getsymbolname() + "_BuyOrder_Ask") nbrOfShares shares next bar at CurrentAsk Limit;
			buyWait = false;
			
			// Calculate Stop Loss
			setstopposition;
			setstoploss(nextOrdSize * 0.08);
		end;
	end;
end;

{ ======================= }

{ SELL }

if GetPositionTotalCost(getsymbolname(), accountIDUsed) > 0 and barssinceentry data2 >= 3 then
begin
	if Time[1] >= 1000 and Time < 1100 and sellWait = false then
	begin
		nbrOfShares = nextOrdSize/CurrentBid;
		Sell (getsymbolname() + "_SellOrder_Ask") nbrOfShares shares next bar at CurrentAsk Limit;
		sellWait = true;
	end;

	if sellWait and Time >= 1100 then
	begin
		nbrOfShares = nextOrdSize/CurrentAsk;
		if ((CurrentAsk - CurrentBid)/CurrentAsk)*100 < 7 then
		begin
			Sell (getsymbolname() + "_SellOrder_Bid") nbrOfShares shares next bar at CurrentBid Limit;
			buyWait = false;
		end;
	end;
end;

{ ======================= }

This is my first automated order system and feedback is very welcome

All the best,
TahuPhoenix


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
$500M Riding on World Cup 2026: France/Spain Co-Favored …
Prediction Markets & Event Contracts
ATFX Suspends Prop Trading Unit ATFunded -- Full Review …
Funded Trading Evaluation Firms
Warsh Drops Easing Bias, December Hike Now Above 50% -- …
Prediction Markets & Event Contracts
After $87M Settles NO: Irans Nuclear Redline Sets Up the …
Prediction Markets & Event Contracts
Thursday May 28: GDP + Core PCE + Jobless Claims All at …
Traders Hideout
 




Last Updated on April 14, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts