Intraday entry on breakout of daily high
Author: dr_kin_cheung
Creation Date: 1/4/2011 4:54 PM
profile picture

dr_kin_cheung

#1
Hi,

I am trying to write a script (see my code below) to do the following:

Exit criteria:
At close of next bar or limit price less than 1% of the purchase price.

Entry criteria:
if the close of current bar is higher than the intraday high

I received the following error message when compiling my script:

"error CS02011 @ (22,6): Only assignment, call, increment, decrement, and new object expressions can be used as a statement"

"error CS0117 @ (26,34): 'Wealthlab.bars' does not contain a definition for 'HighestHighAsofBar'

Please let me know what is wrong with the code? Thank you very much!!

CODE:
Please log in to see this code.
profile picture

Cone

#2
Before we clean this up...

1. Do you only want the script to run on MSFT?
Generally, you run a script on any symbol just be clicking the symbol in the Data Tree. SetContext or GetExternalSymbol have special purposes for more advanced scripts (pairs trading, symbol rotation strategies, etc.)

2. SellAtClose should not be used in intraday scripts (except perhaps to simulate selling at the close on the last bar of the day). The difference between SellAtClose and SellAtMarket is 1 trade, and, it's impossible for a Strategy to actually SellAtClose since the bar must already be closed to process it.

3. Why would you ever want to SellAtLimit below the purchase price on the next bar? Is it intended to be a stop order, right?
profile picture

dr_kin_cheung

#3
Cone, Thanks for your response.

No, I don't want to run this script only on MSFT. I would like to have it run on many symbols eventually. If I input all the symbols in the data tree, will the script run all the symbols simultanously?

When I specified "SellAtClose(bar+1,p)", I meant to say sell at the close of the next bar not at the close of the intraday. If this is not the right command to use, then can you please tell me what the command should be for selling at the close of next bar?

Also, is this the right way to check the close of current bar greater than the intraday high ? "if (close[bar] > Intraday.HighestHighAsofBar[bar-1]) ?

Thanks,
Kin
profile picture

Eugene

#4
In the future, can you please post your WL6 questions in an appropriate forum under Wealth-Lab.NET? As you can see, neither this nor previous posts have anything with the randomly chosen "User Forums » Automated Day Trading - Futures" forum. Thanks.

1. As noted in the QuickRef entry for SetContext, RestoreContext should be called after having finished working secondary symbol.
2. SetContext isn't required in this code. Neither is GetExternalSymbol. You don't need them for this task.
3. The way you do exits is incorrect. What did you want to say by "boolean || boolean"? That's what producing the CS02011 error. A code example that correctly uses multiple exit order types, for example, may be found in the WealthScript Programming Guide, Programming Trading Strategies > Peeking > "Order of Trading Signals".
4. HighestHighAsOfBar is a function of the Position object, hence it can't be used here. You haven't created a Position yet. Furthermore, you can't use this property in a Bars object. Hence the 0117 error.

Hint: try googling those error codes as they've all been documented in MSDN.

Helpful Wiki links:

Intraday | Building blocks of Intraday trading strategies
Intraday / Multi-Time Frame | Mixing intraday and daily data
profile picture

Cone

#5
QUOTE:
If I input all the symbols in the data tree, will the script run all the symbols simultanously?
You can do a multi-symbol backtest (raw profit or portfolio simulation mode) by selecting the DataSet. The script will run on each symbol and the results are combined.

QUOTE:
When I specified "SellAtClose(bar+1,p)", I meant to say sell at the close of the next bar not at the close of the intraday.
That's correct for the close of the next bar, but the point is that you really cannot sell at the close of any bar, especially not intraday bars. Instead of selling at the close of an intraday bar, you should sell at market on the subsequent bar.

CODE:
Please log in to see this code.
profile picture

dr_kin_cheung

#6
Hi Cone,

I just tried your code above in live trading. The script was able to buy, but it did not sell after 10 minutes. It should have sold after 2 minutes (the SellAtStop did not execute as well). I know it bought the stocks because I can see the positions in my fidelity's account. I have to manually (hand trade) sell the stocks from my account to get rid of the positions that were boughts from the script.

Can you please help to fix the code above so that it knows how to sell ?
Thank you!
profile picture

Cone

#7
I have to call you out on this one. It's impossible for this script not to sell on the 3rd bar after the entry bar unless the 1% stop occurs first. Please post a picture of the chart on which you're running this script if you need me to point out the sells to you.

I want you to keep in mind that the trade will not show up on the bar that is forming, i.e., the ghost bar. You get the Alert for the time-based exit at the end of the second bar following the entry bar. The Alert means you place the order immediately, so it will execute at or near the open of the 3rd bar. When the 3rd bars complete, it's added to the chart and you'll see the trade circle.

By the way, until you figure this out, use Paper Trading for goodness sakes! This is a just a demo script!
profile picture

dr_kin_cheung

#8
Hi Cone,

I really don't mean to bother you with this, but the script really did not sell the positions. The 1% drop did not execute. Do you know what else could be wrong? Would it be possible that my fidelity's account did not set up to sell from script? If so, I will contact the fidelity rep.

I know it's costly to use live trading to test the script but I am will to bear the cost if I can witness that the script can really sell.

Please advise what else I can try to make this work? Again thanks!

profile picture

Cone

#9
Okay, even though I want you to do this with Paper Trading first, I think I know what you're up against with live accounts. I'm sure you must be seeing the trades in the chart, but the orders are not being placed. If you had told me this (in those words), I would have caught on sooner...

For a reason that we haven't been able to determine, some customers have trouble Auto Staging/Placing orders for live accounts. Since Fidelity cannot definitively determine was causes it (they cannot duplicate it), we assumed that it was due to a failure in the Portfolio Synch action, which will not stage/place exit Alerts if a matching Position doesn't exist in the live account.

Consequently, in 6.0 a Trading Option (F12) "Disable Portfolio Synch" was added to work-around Portfolio Synch. The User Guide has more info on the option: Orders > Portfolio Synch and Preferences > Trading > Trading Options: Disable Portfolio Synch. Read up on the option, and give it a try today.
profile picture

dr_kin_cheung

#10
Hi Cone,

Currently, I am running version 6.1.27.0. After pressing (F12), I placed a check marked next to "Disable Portfolio Synch" and then clicked on "Apply". Earlier this morning, I was able to get the script to buy but not able to sell. After I disabled portfolio synch option, the script did not buy for the stock that I selected when it broke a new intraday high. (I am aware that the script is for demo only).

I am wondering if there is way for me get a live support? Would it possible for you to connect to my computer and view my screen so that you are convince the script did not execute any sell orders?

If this is not possible, do you know any local consultants that you can recommend in the Boston, Massachusetts USA? Thanks!
profile picture

Cone

#11
You can call Fidelity for live support at any time.

Nonetheless, I'm very interested in see this problem "live" and would like to take you up on the offer to to connect. Please create a Support ticket (this site, upper right menu) and we'll arrange something there.
profile picture

dr_kin_cheung

#12
Cone,

I talked to a Fidelity specialist who is dedicated to wealth lab, and he couldn't figure out the issue. He said he sees the buy order that were from auto-trade but the sell orders were manual (hand trade). He has done everything he could to help. He suggested me to contact the forum which I am doing now.

I will create a ticket for this.

Thanks!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).