Sell at 3% stop or at EOD in live trading
Author: wstock
Creation Date: 6/16/2009 5:59 PM
profile picture

wstock

#1
I built a simple code with 5 minutes data for day trading,
if SMA 7 cross 21, then buy in
The position stops at 3% loss or gets out at the end of the day.

The buy part is ok, it will have the alert and stage the order
to the order tool, and then place the order and I see the order get filled.

The sell part works on the backtesting, but in the real time, when the condition met,
it does not generate the alert and no order staged. Neither 3% stop loss or at closing time.

Can anyone help look at the script and help me solve the problem? thanks.


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

Eugene

#2
1. Please use the CODE tags when posting. Thank you.
2. The main loop should start here at bar 21 because of the use of SMA(21).
3. At tradetime >= 1558, it's already late to imitate a market on close order on 5 minute bar scale. Try entering the penultimate bar's time on 5 minute scale instead.
CODE:
Please log in to see this code.

4. What did you intend to do with StopLossLow: exiting when the price breaks below $10?
profile picture

Cone

#3
And to make it independent of the bar interval used, try this function -
CODE:
Please log in to see this code.
profile picture

wstock

#4
Thanks, The StopLossLow was desiged to be a mental stop point.
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).