NexusFi: Find Your Edge


Home Menu

 





Use variable for "Entry Name" in buy - tradestation


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ttinkham with 4 posts (1 thanks)
    2. looks_two ColoradoCliff with 2 posts (2 thanks)
    3. looks_3 abev with 2 posts (1 thanks)
    4. looks_4 ABCTG with 1 posts (2 thanks)
      Best Posters
    1. looks_one ABCTG with 2 thanks per post
    2. looks_two ColoradoCliff with 1 thanks per post
    3. looks_3 abev with 0.5 thanks per post
    4. looks_4 ttinkham with 0.3 thanks per post
    1. trending_up 2,070 views
    2. thumb_up 6 thanks given
    3. group 4 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread

Use variable for "Entry Name" in buy - tradestation

  #1 (permalink)
 ttinkham 
Charlotte, NC
 
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation, IB
Trading: Futures
Posts: 5 since Jun 2012
Thanks Given: 4
Thanks Received: 3

I have the following statement that works:

Buy("Long Entry") PS contract next bar market;

I want to do the following:

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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
Quantum physics & Trading dynamics
The Elite Circle
Better Renko Gaps
The Elite Circle
 
  #2 (permalink)
ColoradoCliff
Parker CO/USA
 
Posts: 22 since Jun 2017
Thanks Given: 0
Thanks Received: 5

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.


ttinkham View Post
I have the following statement that works:

Buy("Long Entry") PS contract next bar market;

I want to do the following:

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


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


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.

Reply With Quote
Thanked by:
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

ttinkham,

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.

Regards,

ABCTG


ttinkham View Post
I have the following statement that works:

Buy("Long Entry") PS contract next bar market;

I want to do the following:

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


Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
 ttinkham 
Charlotte, NC
 
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation, IB
Trading: Futures
Posts: 5 since Jun 2012
Thanks Given: 4
Thanks Received: 3

Thanks guys,

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.

Started this thread Reply With Quote
  #6 (permalink)
ColoradoCliff
Parker CO/USA
 
Posts: 22 since Jun 2017
Thanks Given: 0
Thanks Received: 5

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.


ttinkham View Post
Thanks guys,

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.


Reply With Quote
Thanked by:
  #7 (permalink)
 ttinkham 
Charlotte, NC
 
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation, IB
Trading: Futures
Posts: 5 since Jun 2012
Thanks Given: 4
Thanks Received: 3

Hey folks,

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.

Happy Trading

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

Nice solution! I think I may have a place in my Options trading algo to try that.

Reply With Quote
  #9 (permalink)
 ttinkham 
Charlotte, NC
 
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation, IB
Trading: Futures
Posts: 5 since Jun 2012
Thanks Given: 4
Thanks Received: 3


ttinkham View Post

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.

Started this thread Reply With Quote
Thanked by:




Last Updated on November 23, 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