NexusFi: Find Your Edge


Home Menu

 





Understanding a simple buy/sell program


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one TraderDoc2 with 1 posts (0 thanks)
    2. looks_two bfulks with 1 posts (0 thanks)
    3. looks_3 ABCTG with 1 posts (0 thanks)
    4. looks_4 nfgrufio with 1 posts (0 thanks)
    1. trending_up 1,336 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
nfgrufio
Atlanta, GA
 
Posts: 19 since Apr 2023
Thanks Given: 1
Thanks Received: 0

In an effort to better understand the functionality of how buys and sells work within a strategy, I have written a very simple program.

 
Code
variable:
	mp(0);
	
mp = marketposition;

if mp = 0
	then buy("B") 1000 shares next bar at open;

if mp = 1
	then sell("S") 100 shares next bar at open;


The buy order enters me into a position as expected, but the subsequent sell orders do not work as expected, except for the first one. I cannot seem to figure out why the subsequent sell orders do not get executed.
The expectation is for 100 shares to be sold on every bar after the buy order is executed, until the position is flat.

Can anyone shed some light on why the program is behaving this way?


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Deal "In Review" at 87% on Deadline Day - …
Prediction Markets & Event Contracts
Sundays Verdict: Lebanon Locked at 99.85% as Iran June 7 …
Prediction Markets & Event Contracts
Four New E-mini Futures Launch June 29 -- Russell 3000, …
Emini and Emicro Index
Iran Fired a Missile at Israel Last Night. The $8M June …
Prediction Markets & Event Contracts
Fed Hike Odds at 57% After Warsh: England Surges 12.9%, …
Prediction Markets & Event Contracts
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

nfgrufio,

"Sell" is the reserved word for closing a long entry, or partially closing it as in your case. Exit orders do not pyramid in Tradestation i.e. they will only be applied once to a position (unless the position is modified after the exit).
Having said that, you would need ten different exit orders to accomplish what you have in mind, while making sure that they are not all applied to the entry at the same time.

Regards,

ABCTG


nfgrufio View Post
In an effort to better understand the functionality of how buys and sells work within a strategy, I have written a very simple program.

 
Code
variable:
	mp(0);
	
mp = marketposition;

if mp = 0
	then buy("B") 1000 shares next bar at open;

if mp = 1
	then sell("S") 100 shares next bar at open;


The buy order enters me into a position as expected, but the subsequent sell orders do not work as expected, except for the first one. I cannot seem to figure out why the subsequent sell orders do not get executed.
The expectation is for 100 shares to be sold on every bar after the buy order is executed, until the position is flat.

Can anyone shed some light on why the program is behaving this way?


Follow me on X Reply With Quote
  #3 (permalink)
 bfulks 
Boston MA
 
Experience: Advanced
Platform: TradeStation
Trading: Stocks and options
Posts: 24 since Aug 2022
Thanks Given: 2
Thanks Received: 4


It appears that MarketPosition is returning a zero after the first exit. Add a Print statement to print the value of MP at the end of your code.


Reply With Quote
  #4 (permalink)
 TraderDoc2 
Plainview
 
Experience: Intermediate
Platform: TradeStation
Broker: TradeStation
Trading: Futures
Posts: 37 since Mar 2012
Thanks Given: 2
Thanks Received: 22


bfulks View Post
It appears that MarketPosition is returning a zero after the first exit. Add a Print statement to print the value of MP at the end of your code.

Actually, I tried that and MarketPosition does not return a zero after the first exit.

However, the first answer posted in this thread is correct. See: https://help.tradestation.com:443/10_00/eng/tsdevhelp/elword/word/sell_reserved_word_.htm


Follow me on X Reply With Quote




Last Updated on February 17, 2024


© 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