NexusFi: Find Your Edge


Home Menu

 





help with automated exits


Discussion in TradeStation

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




 
Search this Thread
  #1 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40

hello there.


i have been using an automated strategy for tradestation for a couple of weeks now. it does ok, but i would like to improve the exits i have as of now. i will post these questions in the tradestation community forums too, but i could get some pointers here as there are accomplished easylanguage programmers in bmt too, and the ts forum is down as of now.


i would like my strategy to go with the trend; buy a stock when the price is above a simple moving average and other indicators are pointing upwards, and sell it when it is below the sma.


my code for long positions looks like this now:



if Price >= AverageFC( Price, Length ) and -another condition- then begin


Buy PSize Shares next bar at market ;


Avg = AverageFC( Price, Length ) ;


if Price < Avg then


Sell all shares next bar at market ;

end;



entries work ok, but i don't like how the exits behave right now. let's say it buys, it is all well, but it should drop the position as soon as the price is below the sma, yet i have seen my strategy hold onto positions that have crossed the sma down and only close them when it is opening a reverse position. it only closes a long position when it opens a short position and viceversa. i would like the strategy to hold positions only when they are outside the sma. how would code look like to achieve this?



and a second question, if i wanted a strategy to exit as soon as two consecutive bars have gone against my position, how would code look like to achieve this?


i tried:


If ( Price [2] > Price [1] and Price [1] > Price ) then

Sell all shares next bar at market ;


but seemingly it won't work.


any guidance will be appreciated, thanks, regards.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Help re translation of ninjascript to EL
NinjaTrader
Quantum physics & Trading dynamics
The Elite Circle
Brendt Skorupinsky
Trading Reviews and Vendors
Has anyone taken The Confident Trader course from aheadc …
Trading Reviews and Vendors
STRATEGY on MC crossEMA
The Elite Circle
 
  #2 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,668 since Jul 2012
Thanks Given: 1,893
Thanks Received: 7,377


maggtrading View Post

and a second question, if i wanted a strategy to exit as soon as two consecutive bars have gone against my position, how would code look like to achieve this?


i tried:


If ( Price [2] > Price [1] and Price [1] > Price ) then

Sell all shares next bar at market ;


but seemingly it won't work.


any guidance will be appreciated, thanks, regards.


If close<close[1] and close[1]<close[2] then sell all shares next bar at market;


should work for 2 consecutive lower closes.

Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40



kevinkdog View Post
If close<close[1] and close[1]<close[2] then sell all shares next bar at market;


should work for 2 consecutive lower closes.




thanks. let me try it out, in inputs i'm already using price on close but will check out your code.

Reply With Quote
  #4 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40

solved.



removing the begin and end cycle, leaving the entries and exits like this:


if Price >= AverageFC( Price, Length ) and -another condition- then


Buy PSize Shares next bar at market ;


Avg = AverageFC( Price, Length ) ;


if Price < Avg then


Sell all shares next bar at market ;




the strategy now drops positions when the exit conditions are met. and, with these changes, the two consecutive lows also work.

Reply With Quote
Thanked by:




Last Updated on July 2, 2013


© 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