NexusFi: Find Your Edge


Home Menu

 





Strategy is mysteriously crashing TradeStation


Discussion in EasyLanguage Programming

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




 
Search this Thread

Strategy is mysteriously crashing TradeStation

  #1 (permalink)
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;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Increase in trading performance by 75%
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
17 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
My NQ Trading Journal
12 thanks
  #2 (permalink)
 
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 Reply With Quote
  #3 (permalink)
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

Reply With Quote
  #4 (permalink)
 
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.

Reply With Quote




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