Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Ok so I've been (very) recently teaching myself easylanguage in an attempt to make my trading efforts more efficient and I've run into a few hurdles. I'm not coding with tradestation (using a small australian broker with easylanguage compatibility), so can't debug anything properly or ask for official help from tradestation.
I know I'm asking a fair bit, but any help to point me in the right direction would be really appreciated.
1) I originally wanted to have moving average crossovers to trigger my exits, but it seems that unless the code is running in front of me the orders won't execute (even if they are marketorder function macros), is this right? If so, does the trailingstoporder function require the code to be running 24/7 to be a real trailing stop, as the marketorder function does? If not, and this is a long shot, but is there any way to make it more 'dynamic', perhaps using variables for the tailing amount inputs?
Ideally I'd like to have a trailing stop determined by the ATR of the instrument. ie: average(close,20) - (avgtruerange(14) * 3).
2) Is there any way to build a scanner with easylanguage (independent of the TradeStation scanner tool) so it would go through all the instruments in a market and show canditades that have triggered a buy signal in the last 2 days or something?
3) If 1) is correct in that I need to place stop orders the 'old' way with my broker at predetermined profit points when I enter, then is there a way to automate this process through easylanguage using the macro order functions? For instance, if I place an order after a buy signal is triggered, can it automate placing exit orders at points determined by a few simple calculations (with variables)?
Thanks!
Sean
Can you help answer these questions from other members on NexusFi?
I'm also only just starting out with EasyLanguage, so take whatever advice with a grain of salt. That said, hopefully this will be of some good, for you or someone else.
1) What do you mean by "unless the code is running in front of me the orders won't execute". What's your current code for the exits? Can you try something like:
If ( average(Close, 50) crosses under Average( Close, 200 ) ) then
Sell ("Close long pos") next bar at market;
BuyToCover("Close short pos") next bar at market;
If ( MP = 1 ) Then
Begin
// Set profit based upon Average True Range
ProfitTarget$ = ATRfactor * ATR * BigPointValue;
SetProfitTarget( ProfitTarget$ );
End;
If ( MP = 1 ) And ( NetProfit > 0 ) Then
Begin
// Set profit based upon percent profit
ProfitTarget$ = ( NetProfit * PrcntGain / 100 );
SetProfitTarget( ProfitTarget$ );
End;
For the exits, I meant that unless I'm online and connected to my broker I don't think my code can run, and therefore I believe my exits cant trigger. I'll be offline a fair bit since I'm currently traveling. The only thing I don't know is if this still applies with functions like marketorder and trailingstoporder, using the .placeorder macro to directly place orders with your broker....
Oh, and my exit code is rather similar to the example you posted, just using a triple crossover and the marketorder function instead.
Thanks for that ATR exit strategy, it's a good idea to determine if profit has been made to differentiate approaches, so I'll implement that in the code I have so far. Of course, that is unless I have to scrap my exit code and just place stops when I enter due to the above point...
You've got an awkward setup, but you can use setstoploss and setprofittarget and hold your orders on the server (at least if TradeStation is your broker).
The server will only hold the order closest to the current price. For instance, if price is closest to the target, it holds the target. If price is closest to the stoploss, it will hold the stoploss. You will need to adjust your TradeStation setting accordingly.
If you are disconnected from the server, then TradeStation will operate on the latest stop information. You will need to contact TradeStation to do anything other than the last trade transmitted.
Finally, it is not recommended that you leave your strategy unattended or disconnect from the TradeStation server with an automated strategy active. If you can't be at home, you need to look into getting logmein (or some other service) to monitor and manage your trades remotely. Unattended trading is a recipe for disaster.