NexusFi: Find Your Edge


Home Menu

 





Referencing Yesterday's High/Extended market trading/Avoiding Multiple trades in Day


Discussion in EasyLanguage Programming

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




 
Search this Thread

Referencing Yesterday's High/Extended market trading/Avoiding Multiple trades in Day

  #1 (permalink)
maxv
Seattle, USA
 
Posts: 2 since Sep 2022
Thanks Given: 0
Thanks Received: 0

Hello all,

I am a newbie trying to code in EasyLanguage for trade automation in TradeStation for stocks. I would appreciate any help you can offer. First, I must apologize for the poor coding skills, and the long post.
I have worked on the code below for some time now and am having weird results in the back test. For example, entries when I do not expect them, no entries when I do expect them, and some entries as predicted.
The idea behind the code is simple, and most have to do basic algebra, but I feel like I am having some unwanted results because I need to enable IBOG and EasyLanguage has some specific definitions for certain things.
Are my goals possible in EasyLanguage? Do you have any suggestions as to how I can do this?

Here are the challenges:
1- The code should reference Yesterday’s High (Regular Session) for entry and other functions.
2- It must not open a new trade if the target is met (same day, or next day)
3- Since Order automation for a symbol is initiated after market close (EOD data) and are placed based on Close of the Daily Bar (Day 0), I would like the Post market of day 0, following day’s premarket (day 1), and following day’s regular session (day 1 market hours) to be considered as Next day (day 1). So if I pick a stock to run the automation on and initiate automation after market, next day pre market, or during the market hours, it should all reference to day 0.
4- It seems like in order to be able to do extended market trading, I would need to use a smaller time frame than Daily. That produces wild results in my backtesting so I suspect IBOG is the cause of that. I have no idea how to solve this and accomplish the other goals in the code.
5- I can’t seem to reference cash in the account to make sure only a portion of the account balance is available for automated trading. Might only be in backtesting that it fails?

Thank you,

Attached Files
Elite Membership required to download: TEST1.ELD
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Option : Call and Put increase at same time ?
The Elite Circle
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #2 (permalink)
SunTrader
Boca Raton, FL
 
Posts: 260 since Nov 2018
Thanks Given: 81
Thanks Received: 182

If you want a better chance at getting assistance post code as a text attachment. Many, I include myself in that group, are leery of opening code from a internet stranger.

Reply With Quote
  #3 (permalink)
abev
seattle washington
 
Posts: 75 since Feb 2019
Thanks Given: 11
Thanks Received: 29



maxv View Post
Hello all,

I am a newbie trying to code in EasyLanguage for trade automation in TradeStation for stocks. I would appreciate any help you can offer. First, I must apologize for the poor coding skills, and the long post.
I have worked on the code below for some time now and am having weird results in the back test. For example, entries when I do not expect them, no entries when I do expect them, and some entries as predicted.
The idea behind the code is simple, and most have to do basic algebra, but I feel like I am having some unwanted results because I need to enable IBOG and EasyLanguage has some specific definitions for certain things.
Are my goals possible in EasyLanguage? Do you have any suggestions as to how I can do this?

Here are the challenges:
1- The code should reference Yesterday’s High (Regular Session) for entry and other functions.
2- It must not open a new trade if the target is met (same day, or next day)
3- Since Order automation for a symbol is initiated after market close (EOD data) and are placed based on Close of the Daily Bar (Day 0), I would like the Post market of day 0, following day’s premarket (day 1), and following day’s regular session (day 1 market hours) to be considered as Next day (day 1). So if I pick a stock to run the automation on and initiate automation after market, next day pre market, or during the market hours, it should all reference to day 0.
4- It seems like in order to be able to do extended market trading, I would need to use a smaller time frame than Daily. That produces wild results in my backtesting so I suspect IBOG is the cause of that. I have no idea how to solve this and accomplish the other goals in the code.
5- I can’t seem to reference cash in the account to make sure only a portion of the account balance is available for automated trading. Might only be in backtesting that it fails?

Thank you,

I use Multicharts to compile my EL code and your compiler looks at the code a bit differently. I'm looking at your code and the If-Then-Else-End statements in particular may be treated diffently. And since I do not use Tradestation to create or run my EL code, some of what I mention below may not be available to you -- I bet it is though.

1. Yesterday's RTH high. A couple of ways you could do it but I would go with simply High(1) which should return yesterday's high when the chart is using a => daily <= time frame! You may want to get familiar with using multiple data streams on the same chart -- i.e. insert a new instrument (which can be the same symbol) using the daily time frame and reference yesterday's high in your signal with the code "High(1) data2".

2. Only one trade in the same direction. This is likely a configuration of the strategy -- i.e. in Multicharts I go to "Format signals/Properties/Position limits/Allow up to [x] entry oders in the same direction as the currently held position"

3. Mmmmmm. Not clear what you want to have happen here. Regardless, I'm rather sure you are defining hours that are not pre-defined in the "Instrument Properties" so you will need to create your own set of trading hours. I.e. in EL code you would say "time > 1600 and time < 2000" to define today's post market. To combine yesterday's post market with today's pre market will take four or five lines of code but it can be done.

4. IBOG -- Oh boy...... IBOG is difficult to work with and I can't locate the thread helped me understand how it works, but be aware that backtesting with IBOG can produce odd results. That being said, I get the impression that you could get your strategy working by using a smaller timeframe than "Daily" and forget about using IBOG.

5. Sounds like you are attempting to use a percentage of your current buying power. It could be done. I've never done it so I hesitate to point you in a direction. However, it may be that simply using the properties of the signal might serve -- in Multicharts I use "Format Signal/Properties/" and use "Init Capital" and "Trade size".

I took a look at your code and perhaps you are missing key words for the If-Then-Else-End statements that confuses the compiler. I suspect that Tradestation is seeing a series of commands quite differently that you expect.

A few suggestions:
- Indent your code -- I've included an example
- Create variables for "Value1,2,3 ..." with the same type of descriptive names you have given your inputs.


 
Code
//Determines the Entry Price based on AmountAboveLastHigh Input and the Price of the Stock
If CurrentBid < PriceOfStockCutOff1 Then
	Value1 = High of Yesterday + ( AmountAboveLastHigh / 2 )
Else 
	If CurrentBid > PriceOfStockCutOff2 Then
		Value1 = High of Yesterday + ( AmountAboveLastHigh * 2 )
	Else
		Value1 = High of Yesterday + AmountAboveLastHigh ;
		Value2 = PositionSize$/CurrentBid ;					//Position Size in # of Shares
		If (AvgTrueRange(14)/Close of yesterday *100/2) < PrcntGain Then 	//Set Target% based upon the smaller of PrcentGain Input or ATR(90)%
			Value3 = (AvgTrueRange(14)/Close of Yesterday *100 / 2)
		Else
			Value3 = PrcntGain ;
			//Designating Account ID 
			//Value4 = Getbdovernightbuyingpower (GetAccountID)
			// Value4 > value2 * EntryPrice ;
			//Session Type to Dictate Type of Orders (Entry, Stop and Target)
			Value5 = CurrentSession(0);
			//Value 6: Calculates the Percent of Acceptable Gap Up based on ATR%, then Picks the Larger Value between that Value OR MaxGapUpPrcntAllowed Input
			If Value3 * RatioGapUpFromPrcntATR > MaxGapUpPrcntAllowed Then
				Value6 = Value3 * RatioGapUpFromPrcntATR
			Else
				Value6 = MaxGapUpPrcntAllowed;
				//Value 7: Cauculates the percent of Acceptable Gap Down based on ATR%, then Picks the Smaller Value between that Value OR MaxGapUpPrcntAllowed Input
				If value3 * RatioGapDownFromPrcntATR > MaxGapUpPrcntAllowed Then
					Value7 = Value3 * RatioGapUpFromPrcntATR
				Else
					Value7 = MaxGapDownPrcntAllowed;
					//Conditions to Enter Market with a Market Order--Consider Beginning of Day Overnight Buying Power amount--Do not Buy If Stock Gapped Down More than 2% Overnight
					If value5 = 1 And Value4 > value2 * EntryPrice And
						currentBid>= Value1 AND ((currentBid-Value1) * 100 /Value1 ) < Value6 AND (( Value1 - Open) *100 / Value1 ) < Value7 then 
						buy Value2 share next bar at Market 
					Else
						If value5 <> 1 And Value4 > value2 * EntryPrice And
							currentBid>= Value1 AND ((currentBid-Value1) * 100 /Value1 ) < Value6 AND (( Value1 - Open) *100 / Value1 ) < Value7 then
							buy value2 share next bar at (value1 * (1+ (ExtendedMarketLimitOffsetPrcntEntry/100))) Limit ;
							// Set StopLoss based upon percent Loss Per Share
							If ( CurrentBid < Entryprice * (1- (prcntloss/100)) ) then Begin
								If Value5<>1 AND ( MP = 1 ) Then
									Sell all shares next bar at (CurrentBid - (ExtendedMarketLimitOffsetPrcntStopLoss/100 * CurrentBid)) limit
								Else
									If Time > 0930 AND time < 1600 AND Value5 = 1 AND ( MP = 1 ) Then 
										Setstopshare;
										SetStopLoss ( EntryPrice - (Entryprice * (1- (prcntloss/100))) ); 
								End;
							// Sell at Profit Target based upon Value3
							If ( CurrentBid > (EntryPrice * ( ( Value3 - ( ( (Entryprice-Value1) /Value1) + 1) ) / 100 )  ) ) Then Begin
								If Value5 <> 1 AND ( MP = 1 ) Then
									Sell all shares next bar at (CurrentBid - (ExtendedMarketLimitOffsetPrcntTarget/100 * CurrentBid)) limit
								 Else
									If time > 0930 and time < 1600 AND Value5 = 1 AND ( MP = 1 ) Then
										Setstopshare ;
									 	Setprofittarget ( (EntryPrice * ( ( Value3 - ( ( (Entryprice-Value1) /Value1) + 1) ) / 100 )  ) ) ; 
								 	End ;

Reply With Quote
Thanked by:




Last Updated on September 18, 2022


© 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