Welcome to NexusFi: the best trading community on the planet, with over 200,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 -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
myvariable="Long Entry";
Buy(myvariable) PS contract next bar market;
The buy command does not seem to accept a variable no matter what I do. Tried every syntax under the sun around myvariable and spent hours doing google searches. Hope someone here knows how to do this.
Thanks
Can you help answer these questions from other members on NexusFi?
Did you define myVariable and initialize it as a String before referencing it in your code?
I will admit that the EL Essentials Guide only shows a constant value enclosed by Double Quotes and never a variable reference....perhaps that's not possible.
Mmmmm..... Not sure I'm getting what you are attempting but I may be reading too much into the question but I'll attempt to give you an answer.
The "Buy" command sends an order to purchase the default quantity of whichever symbol is open on the chart where the strategy is running. No variable for the "Buy" command is necessary.
If you are attempting to enter an order (buy or sell) for a symbol other than the one that is open on the chart, then you will need to either use Global Variables or data streams. Global variables and pass variables to other charts (i.e. the chart that is running the symbol you wish to buy). Or..... you can open the symbol you wish to buy on a second window in the same chart and direct the buy command to the data stream used by the symbol you are attempting to buy...or sell...which ever.
For example: I buy and sell options when the underlying reaches a specific strike price. I have a chart open with the underlying on it and a strategy that changes the value of a global variable when a specific strike price is reached. That global variable is read by a second chart which is a chart of the option I wish to buy or sell and I have a strategy running on that chart. The strategy running on the chart of the option reads the global variable at the open of each bar and buys or sells the option when the variable is true. I've not done this using data streams but I don't see why it wouldn't work with data streams -- the concept is the same.
Hope that helps.
PS I'm using Multichart's Power language so there is a possibility that what I do is specific to Powerlanguage -- but I don't think so. Someone else might want to chime in here.
legacy EasyLanguage in Tradestation will require a constant order name (string literal) that is set together with the order command.
You will not be able to set them with variables unfortunately.
in response to ColoradoCliff, the answer is yes, I did define the string variable and I ran some tests with it and proved I can use it in other places.
I believe ABCTG is probably correct in that it is a limitation of Tradestation that variables can't be used which is really disappointing. I have a strategy that uses a bunch of different rules for entry so I wanted to label the entry with the corresponding entry rule name so that I could tell by looking at the chart what rule was used for the entry.
I eventually found in a Google search that Multicharts had the same issue, and they came out with a new command that allows the use of variables when doing a buy order. However, the new Multicharts commands don't work in Tradestation.
I can accomplish the same thing I am trying to do with a huge case statement with a separate buy command for every entry name I want to use but it is pretty clucky to do it that way and will make my code a lot longer. Guess that is the only option I have unless someone has a bright idea to get around this limitation.
Given your test results, I would suggest having different buy instructions within each rule set to identify which rule triggered the buy event. Yes, it's not very elegant, but that should take care of your needs. Then submit an update request to the TS folks asking them to enhance that function.
just wanted to give an update. I figured out a solution to accomplish what I was trying to do. Not perfect but works pretty well in the absence of TS functionality. I had not done much with text labels in the past so this part was fairly new to me.
It is pretty simple really.
earlier in my code where all my logic is I set the variable EntryName like so:
EntryName="my custom name that changes frequently and assigned to variable";
In the section of my code where I do the order entries the following is used:
Buy("") PS contract next bar market;
value1=Text_new(D,T,low,newline+newline+EntryName);
Notice I used Buy("") instead of Buy("Entry Name") to blank out the original text from the buy command.
Then I just placed the text below the bar with the label I really want. Notice the "newline+newline+EntryName". I added this "newline+newline" to give me some consistent spacing below the bar for my entry label regardless of scaling.
I actually tried to figure out a way to get the value of the most recent text object ID on the chart of the original text created by the Buy command and then use the Text_setstring command to change the text to what I set the EntryName variable to. Not sure if this is even possible but can't even seem to easily get the object ID without using the Text_getfirst command and then looping forward with the Text_getnext until hitting the last ID on the chart which would slow my code way down.
Another update. I did more testing on the getting the object ID of the text put on the chart with the "buy" command so that I could use the "Text_setstring" command to change it to whatever I want by using a variable. I found that TradeStation does not assign text object IDs to that text the "buy" command places on the chart so the idea of changing the text the "buy" command places on the chart will not work. So I think the solution in my previous post is the best option.
Good investigative work getting to the bottom of that. This confirms a fundamental limitation in EasyLanguage -- the order name in the Buy (" ") market; syntax must be a string literal, not a variable. TradeStation won't let you pass a variable as that entry name parameter, which is why there's no object ID to grab and manipulate afterward.
Worth noting that the same restriction applies in PowerLanguage (MultiCharts) -- buy ("longentry") market; requires a hardcoded string there too, so this isn't a TradeStation-specific quirk. It's a design choice shared across both platforms.
Since you've confirmed the Buy("") + Text_new() approach works for active entry labeling, that's genuinely the right solution. The two paths traders typically land on are:
Unique hardcoded strings per rule set -- simple, but gets verbose with many entry conditions
The Buy("") + Text_new() combo -- more flexible when you need fluid labels
Given your multi-rule setup, the second approach is cleaner long-term. Dead-end confirmed, workaround validated -- that's exactly how productive debugging works.
Have a good weekend!
-- Fi
"Sometimes the fastest path forward is confirming a dead end."
Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.
Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.