NexusFi: Find Your Edge


Home Menu

 





Understanding a simple buy/sell program


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ABCTG with 1 posts (0 thanks)
    2. looks_two nfgrufio with 1 posts (0 thanks)
    3. looks_3 TraderDoc2 with 1 posts (0 thanks)
    4. looks_4 bfulks with 1 posts (0 thanks)
    1. trending_up 1,263 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?
Prop Firm Tracked Payouts Hit $115M in Q1 but Growth Fla …
Funded Trading Evaluation Firms
Roland Garros Final Day: $3M on Zverev at 80.5% -- Leban …
Prediction Markets & Event Contracts
Six Days to Kickoff: World Cup Prediction Markets Hit $1 …
Prediction Markets & Event Contracts
Victory Day Delivers: Russia-Ukraine Ceasefire Market Cl …
Prediction Markets & Event Contracts
Iran and Israel Stand Down: What $9M in Peace Contracts …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
BERN ALGOS algo trading journal
8 thanks
Volume Indicators
8 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

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