♥ 0 |
Hi Pete, hope you can guide me on this I am sure this is a simple one. I thought my label is correct but I get a error. Here is the code. input length = 10; def N = reference ATR(length = length); def trailStopPrice = close + (2*N); #def trailStopPrice = price + trailStop * mult; addOrder(OrderType.BUY_TO_CLOSE, high >= trailStopPrice, tickColor = GetColor(9), arrowColor = GetColor(9), “Out”); When I add the “Out” I get the following error Parameter already defined: tickcolor It is the same as this which works fine.
AddOrder(OrderType.BUY_TO_CLOSE, ShortExit, open, tradeSize, tickColor = GetColor(7), arrowcolor = GetColor(7), “TSClose”);
Marked as spam
|
Private answer
Well that original question title had to go. Please make sure the question title accurately reveals the context of the question so other visitors can search for a find solutions. By the way, this is a great question. I love it when folks include their code. Because it prompts me to take extra time to explain things in detail and teach everyone what went right and what when wrong. You can get all the details for the AddOrder() statement here: http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder.html The AddOrder StatementOk, the add order statement takes 7 arguments (or parameters). If you place them all in the correct order you do not need to label them. Such as “tickColor = GetColor(7)”. If you enter all 7 parameters and list them all in the correct order you only need to provide the values. Very Important LessonThis is very important so pay attention. For SOME statements, there are optional parameters. Let’s make an example using Ok, got it? Make sure to read that paragraph again if this next section leaves you scratching your head. Back to the AddOrder StatementSo, let’s count the number of parameters passed in this statement:
Seven, I count 7 parameters. And since they are all present and listed in order we can shorten it to:
Ok, that was the statement that was working fine. Know let’s take a look at the statement that is generating the error:
So, how many parameters do we have in this one? Five, I count only 5 parameters in this one. We have two missing. Which ones are missing? Parameters 4 and 5 are missing. (entry price and trade size). Both of those two parameters are optional. You can leave them out and the system will provide default values. Your issue begins right there. Remember that labels are not required when all parameters are listed and they are all listed in the correct order. But once you leave out one or more optional parameters, everything that follows must be labeled. The CorrectionWe can correct this in one of two ways. We can provide those other two parameters as they have been done in your previous AddOrder statement. We can use the variable names open and tradeSize to do the job. Like this:
Please take note of the [-1] after the entry price parameter. This is absolutely essential for strategy orders unless you have previously shifted the test for entry bar. Which is an advanced method and requires very careful attention to detail. Your code does not shift the entry bar, so make sure you use open[-1] for your entry price. Otherwise your strategy will create theoretical orders that are completely impossible to achieve in live trading. This is another lesson entirely and if you are interested you can get the mind-blowing details here: https://www.hahn-tech.com/ans/parablic-sar-signal-not-firing-in-tos-strategy/ Ok, on to the second way to correct this. We can leave those optional parameters out, but we must apply a label to every single parameter that follows. Like this:
Simple eh? Now I could have simply typed that out as the answer and hit the submit button. But because you took the time to provide your source code I decided to turn this into a lesson. I hope I covered all the nooks and crannies. Writing Strategies is a very challenging endeavor. There are many ways to screw things up, and create back-test results that are completely impossible to achieve. Marked as spam
|
Please log in to post questions.