NexusFi: Find Your Edge


Home Menu

 





Strategy is mysteriously crashing TradeStation


Discussion in EasyLanguage Programming

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




 
 

Strategy is mysteriously crashing TradeStation

 
EzPz
Puyallup
 
Posts: 8 since Oct 2020
Thanks Given: 2
Thanks Received: 4

I have a strategy that I am testing in multiple different markets to see which market it works best in. Unfortunately after about 6 - 12 hours I get a message from TradeStation that it needs to shut down. One of the pop up windows at this time informs me that an invalid argument was supplied. I will include a slightly modified version of the code because I suspect that I must be doing something wrong even though the code compiles okay.

 
Code
// Long Entry
If MarketPosition = 0 And MagicHappens() Then
	Buy ("Entry_L") PositionSize Contracts Next Bar Open;

// Stop and Target
If MarketPosition <> 0 Then
Begin
	SetStopPosition;
	SetPercentTrailing(PercentTrailFloor, PercentTrailPerc);
	Setstoploss(StopLoss);
End;

Does anyone know what I am doing wrong? I suspect it might have something to do with the way that I am exiting the trade.

Some hours later...

So I thought that I might need to call SetStopPosition for each Set statement so I modified the code thusly and it is still failing as before. Please see below.

 
Code
// Long Entry
If MarketPosition = 0 And MagicHappens() Then
	Buy ("Entry_L") PositionSize Contracts Next Bar Open;


// Stop 
If MarketPosition <> 0 Then
Begin
	SetStopPosition;
	Setstoploss(StopLoss);
End;

// Target
If MarketPosition <> 0 Then
Begin
	SetStopPosition;
	SetPercentTrailing(PercentTrailFloor, PercentTrailPerc);
End;


Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
REcommedations for programming help
Sierra Chart
About a successful futures trader who didnt know anythin …
Psychology and Money Management
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
 
 
 
ShadowFox's Avatar
 ShadowFox 
CO/USA
 
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
Posts: 129 since Jun 2020
Thanks Given: 70
Thanks Received: 157

You actually don't need to check for a marketposition before setting your stop conditions that you have. You can just do the below without the if statement.

 
Code
// Long Entry
If MarketPosition = 0 And MagicHappens() Then
	Buy ("Entry_L") PositionSize Contracts Next Bar Open;

SetStopPosition;
SetPercentTrailing(PercentTrailFloor, PercentTrailPerc);
Setstoploss(StopLoss);
No need to SetStopPosition before each statement though.

You can also use SetProfitTarget if you do not like the performance of your Percent trail. Or use the percent trail as a way to lock profits if your target is not reached.

I don't see anything in the original post though that should throw an error. My guess is something funky is happening in "MagicHappens()".

Visit my NexusFi Trade Journal
 
EzPz
Puyallup
 
Posts: 8 since Oct 2020
Thanks Given: 2
Thanks Received: 4



ShadowFox View Post
You actually don't need to check for a marketposition before setting your stop conditions that you have. You can just do the below without the if statement.

 
Code
// Long Entry
If MarketPosition = 0 And MagicHappens() Then
	Buy ("Entry_L") PositionSize Contracts Next Bar Open;

SetStopPosition;
SetPercentTrailing(PercentTrailFloor, PercentTrailPerc);
Setstoploss(StopLoss);
No need to SetStopPosition before each statement though.

You can also use SetProfitTarget if you do not like the performance of your Percent trail. Or use the percent trail as a way to lock profits if your target is not reached.

I don't see anything in the original post though that should throw an error. My guess is something funky is happening in "MagicHappens()".

I took the MagicHappens() function out and just made it a simple closing price crossover, because I thought the same thing but it is still failing. I will try all your recommendations and post the entire code here if that does not solve it.

Thanks,
-Ez

 
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146

Try replacing SETSTOPPOSITION to SETSTOPCONTRACT......just for testing purposes.
Also, you should be tracing the code using the PRINT statement.
Send the Traces to a file.


 



Last Updated on April 20, 2021


© 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