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 221 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Understanding a simple buy/sell program

  #1 (permalink)
nfgrufio
Atlanta, GA
 
Posts: 14 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?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
Better Renko Gaps
The Elite Circle
Quantum physics & Trading dynamics
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

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 Twitter 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: 34 since Mar 2012
Thanks Given: 1
Thanks Received: 21


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 Twitter Reply With Quote




Last Updated on February 17, 2024


© 2024 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 - Privacy Policy - Downloads - Top
no new posts