Multiple Criteria Orders


Category:
0
0

I have two criteria that are part of the same strategy. They are similar but different enough that I have defined two separate ‘def’ in my strategy code. One entry is often “better” than the other (‘A’ is better than ‘B’), but in the right circumstances, it’s the other way around.

EXAMPLE:

def EntryA = a + b + c…;

def EntryB = x + y + z…;

 

My question is then broken into two parts:

1. Can I customize the AddOrder code to look for EntryA first and then only enter EntryB as a secondary criteria (i.e. when EntryA criteria is not met)?

Not sure if the standard ‘If’ statement does this prioritization by default, based on the order it is written.

 

2. Can I customize the text shown on the chart when the order is opened (to call out EntryA or EntryB?

I want to distinguish which entry “fired” so I can make a decision.

 

As always – thank you!

Marked as spam
Posted by (Questions: 4, Answers: 6)
Asked on August 19, 2021 9:19 am
151 views
0
Private answer

You did not provide a fully functional section of code so I had to build one of my own. Which means I had to make several assumptions as to what you are trying to accomplish. The following is a section of code that fully functions as a chart strategy. There are two conditions that can generate an entry. Each one is assigned to it's own AddOrder() statement. Each AddOrder() statement is set to display the name of the condition that generated the entry on the chart. The exit is 2% below the entry price. Which means this chart strategy can only loose money, it is useless for trading but it demonstrates one method you might employ to accomplish your stated goals.

def conditionOne = Average(close, 8) crosses above Average(close, 21);
def conditionTwo = Average(close, 21) crosses above Average(close, 50);
AddOrder(OrderType.BUY_TO_OPEN, conditionOne, open, name = "Condition One");
AddOrder(OrderType.BUY_TO_OPEN, conditionTwo, open, name = "Condition Two");
AddOrder(OrderType.SELL_TO_CLOSE, low[-1] < EntryPrice() * 0.98, EntryPrice() * 0.98, name = "Exit");

I have included a screenshot below showing how this looks on the chart.

Edit: I forgot to include a link to the language reference for the AddOrder() statement provided by Thinkorswim:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on August 19, 2021 11:27 am
0
Sometimes I feel so dumb lol. But thank you so much for this response. Two things I takeaway from this: 1) It seems I can indeed have more than one criteria for opening the order AND they can "share" the Exit/Sell order. That is awesome. 2) It seems that I can customize the text on the order on the actual chart, which is great. As always, thank you so much.
( at August 19, 2021 12:25 pm)
0
I just updated my answer to include a link to the language reference for the AddOrder() statement. That webpage will explain each of the parameters that you can set.
( at August 19, 2021 1:20 pm)