ToS AddLabel not working with AddOrder


Category:
0
0

Hi Pete

After watching your video on Strategy and semi-auto videos, I wanted to use it to conditionally close a sell order purchased earlier,  if  by the end of the day, the ROC < 50 or  if there was a small profit .

I have the following code. I do not get the AddOrder text on the chart. Funny thing is the AddLabels  are only displayed if the AddOrders are commented out. If I code the AddOrders are coded, the AddLabels  are not displayed.

So I think there is something wrong with my AddOrder but I cannot figure out, despite my AddLabels showing that it should work.

Below is my code and I have attached a screen shot of  the chart

Thanks … Ratilal

 

<pre>

input ROClength = 5;
def price = close;

def roc = RateOfChange(ROClength, Roclength, price);
def openCost = GetAveragePrice();
def quantity = AbsValue(GetQuantity());
def change = price – opencost;
def buyswitch = roc > 50 or change < 0;
def sellswitch = roc > 50 or change < 0;

# for debugging purpose only
# displayed when Addorders are commented ; else no ??
#
AddLabel(yes, ” BSwitch: ” + buyswitch,color.BLUE);
AddLabel(yes, ” SSwitch: ” + sellswitch,color.BLUE);
AddLabel(yes, ” Price: ” + opencost,color.GREEN);
AddLabel(yes, ” Qty: ” + quantity,color.GREEN);
AddLabel(yes, ” Change: ” + change,color.GREEN);
AddLabel(yes, Concat(” ROC=”, roc), Color.GREEN);

# stock is ENZ

#AddOrder(OrderType.BUY_TO_CLOSE, buyswitch, price, quantity, Color.ORANGE, Color.ORANGE,”Sample buy @ ” + price);
#AddOrder(OrderType.SELL_TO_OPEN, sellswitch, price, quantity, Color.ORANGE, Color.MAGENTA,”Sample sell @ ” + price);

 

 

</pre>

Attachments:
Marked as spam
Posted by (Questions: 4, Answers: 1)
Asked on March 10, 2020 6:00 am
496 views
0
Private answer

Works fine when I test it. Did you get any error messages when you tried to include the AddOrder statements? I suspect you added this as a new chart study instead of a chart strategy. The AddOrder statements are not allowed in chart studies. You can only use them in chart strategies.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 10, 2020 7:28 am
0
Hi Pete I do have it as a strategy. And there were no obvious error messages. Did the labels appear appear with AddOrder ? In my case, when AddOrder is in the code, the AddLabels don't appear to work and that's why I have it as a comment. If the AddOrder is working with the AddLabel, does the AddOrder's text "Sample buy" appear on the chart, and if so, which bar. Thanks .. Ratilal
( at March 10, 2020 2:04 pm)
0
Private answer

When I load this code into a new chart strategy and un-comment the AddOrder() statements the labels plot just fine. However there is a problem with your code that prevents the strategy from plotting theoretical orders.

The following line of code is what you are using to define the trade quantity:

def quantity = AbsValue(GetQuantity());

This statement produces a value of zero for all ticker symbols which you do not currently hold in your live open positions. Which means for each of your theoretical orders the quantity is always zero, unless the ticker symbol happens to be set to one that you currently hold in your account.

The lines of code you are using for your triggers:

def buyswitch = roc > 50 or change < 0;
def sellswitch = roc > 50 or change < 0;

Those are exactly the same. So the strategy will always enter and exit on the same bar.

The line of code you are using for the entry and exit price:

def price = close;

This is always going to produce an entry and exit price at the close of the bar that immediately precedes your trigger. Which in a live trading environment would be completely impossible to achieve.

To summarize. I would say your issue with the labels and the AddOrder statements should be the least of your concerns. You have a strategy that cannot replicate real life trades. Which is a serious error. What I would call a fatal error.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 10, 2020 3:24 pm