Could someone help me write the following ATR based Exit strategy?
Exit Strategy
If EntryPrice + ATR*3 then sell with a trailing stop of 0.5%
For example, Entry Price = 50; ATR = $.25 then input a sell order at $50.75 and sell at $50.49 or higher (depending on how the price moves up)
If EntryPrice - ATR*3 then sell
For example, Entry Price = 50; ATR = $.25 then input a sell order at $40.25 and sell at $40.75
Size:
Color:
CODE:
Please log in to see this code.
Size:
Color:
Thank you for a prompt response.
Could you please explain # 5 in the following:
DataSeries atr = ATR.Series(Bars, 5);
PlotStops();
Could you please explain # 20 in the following:
for(int bar = 20; bar < Bars.Count; bar++
Size:
Color:
Also,
How can we adjust scale in the code?
For example, when backtesting, I can select a scale of daily, weekly, 60 minutes, 30 minutes etc. When backtesting, say at 60 min scale, I would like to calculate ATR at a daily scale, how can I do that.
Moreover, I would like to exit my positions while checking for exit conditions on a "tick" scale.
Please advise.
Size:
Color:
QUOTE:
Could you please explain # 5 in the following:
Welcome to the Wealth-Lab Wiki > Standard Indicators >
ATR. There you'll see each indicator with their parameters documented.
QUOTE:
Could you please explain # 20 in the following:
* WealthScript Guide > Programming Trading Strategies > Trading Loop
* Wiki Knowledge Base >
Bars, Loops, and Bar + 1QUOTE:
How can we adjust scale in the code?
* WealthScript Guide > Multi-Time Frame Analysis
* QuickRef (hit F11) > Time Frames.
QUOTE:
Moreover, I would like to exit my positions while checking for exit conditions on a "tick" scale.
Neither Fidelity provides tick-based static data, nor it makes great sense to exit on a tick/second scale:
Wiki FAQ >
Is it necessary to have access to intra-bar tick data to daytrade with Wealth-Lab?
Size:
Color:
I will run the strategy at a 60 min scale. But I would like to exit by checking "forming bars"... not check prices at the end of 60 min but check it as frequently as I can. You earlier suggested, I can't do it at every tick (is that right?). If not every tick, could I check it every 1 min.
Please help with the code.
Size:
Color:
Use 1-minute data as the basis scale, make the necessary calculations after SetScaleCompressed( 60 ), then trade on the basis time scale after RestoreScale(). See more code examples in the WealthScript Programming Guide > Multi-Time Frame Analysis.
Size:
Color:
I have the following code. I cut and pasted from different strategies..so I am sure there are some inconsistencies. Please help.
Strategy is:
*************
Entry:
If MACD and Bollinger and Stoch conditions are true then
Buy
Exit:
If EntryPrice + ATR*3 then sell with a trailing stop of 0.5%
else if EntryPrice - ATR*3 then sell
else if the price goes up by 3% then sell with a trailing stop of 0.25%
else if the price goes down by 2.75% then sell if price goes down another 0.25%
*************
I think I have most of the code in place but few things are missing. Could you also explain the items that are underlined? I also want to check my exit conditions every 1 min but entry is based on 60 min. You have given me some information previously..but I am not sure how to integrate that.
Please review the code below... Thanks a million.
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
You have given me some information previously..but I am not sure how to integrate that.
Yes I did but have you experimented with the code examples there? I couldn't see a single attempt to integrate them in your code. If you "
also want to check my exit conditions every 1 min but entry is based on 60 min", then I also couldn't find it in your exit rules. As you understand, clear and unambiguous rules are required before coding anything. Please review your rules and expand them; for example, does it mean that the ATR is from 60-minute scale but the indicators are calculated on 1-min scale?
QUOTE:
GetTradingLoopStartBar
You could find the answer in the QuickRef, the function is documented there.
QUOTE:
Group2
This is a FAQ:
After generating strategy code with "View Strategy Code", there are strings like "Group1" and "Group1|". What do they mean?QUOTE:
>>>>>>>>>>>>>>>>>>>>>
Hint: Just use the CODE button to wrap your code blocks in between a pair of CODE tags (next to Bold,Italic...
CODE,IMG).
Size:
Color:
I have made another attempt to write my logic.. Please review.
I would like to
- check entry conditions BB, Stoch, MACD at 60 min bar;
- check ATR at daily interval and
- exit at 1 min bar or every tick.
I ran the back-test at 1 min bar.
CODE:
Please log in to see this code.
Size:
Color:
Good attempt. A few notes:
1. The compressed DataSeries have to be synchronized before e.g. plotting.
2. Move the Daily ATR code block out of the trading loop.
3. Same for PlotStops.
4. Placement of AtMarket orders above AtStop orders is suggested.
5. No need to use AtClose orders with 1-min intraday data.
CODE:
Please log in to see this code.
Size:
Color:
Thanks.
When I ran this strategy, I see only "ATR Stop" show up under Exit Name under Trades tab. There are other trades with Exit Name blank, although I have put in a description for every exit.
Moreover, when I changed aATR and bATR values to 100, a scenario a position is EXTREMELY unlikely to hit, I still see a lot of "ATR Stop" trades.
Size:
Color:
Just a couple of hints to aid in your debugging:
1. the compressed daily ATR is OK (not to blame)
2. I see other exits e.g. "Sell Trailing Stop" (try other DataSets)
Size:
Color:
How do I debug? Insert PrintDebug statements??? I tried that... I ended up having no trades
CODE:
Please log in to see this code.
Size:
Color:
Size:
Color:
I have been getting these errors when I run the strategy.
Could you please explain?
CODE:
Please log in to see this code.
Size:
Color:
Size:
Color:
I read through the Wiki... what am I doing wrong in the code?
I am currently using the strategy to back-test. But once I finalize a strategy I would like to turn on Auto-Trading. I am already set up for that. Would I need to make any changes at that time? Ex. would the following for loop still valid?
CODE:
Please log in to see this code.
Is Index was out of range error caused by this for loop statement?
Size:
Color:
QUOTE:
Ex. would the following for loop still valid?
Of course.
QUOTE:
I read through the Wiki... what am I doing wrong in the code?
Firstly, I do not know what you are doing in the code.
Regarding my code (see above # 3/10/2011 4:57 AM), then suggestion #2 may apply:
QUOTE:
* accessing the data that does not exist. Example: your DataSet contains the price data for a symbol that stopped trading, and you select the data range that goes beyond that date, and do not account for this fact in your Strategy.
I think this is your next step at debugging.
Size:
Color:
I am running back-test on 1 min bar.
CODE:
Please log in to see this code.
In the if statement above, in atr[bar], I think the barInterval is 1 min..but I want to check the condition against daily ATR.
Please advise, how I can do that?
-------
Also I would write a function that I can call from any strategy? Could I create my own class MyClass and incorporate that into WealthLab code?
Size:
Color:
Size:
Color:
I want to use earnings date in my strategy.
Please refer to: http://www2.wealth-lab.com/WIKI/EarningsDate.ashx
The write up suggests the following:
...With a "using" reference to Community.Components, access EarningsDate methods (below) by direct calls as showing in the Example...
But when I include the reference ..
Using Community.Components
the program doesn't recognize Community and doesn't compile.
Size:
Color:
Install the Community Components library (Extensions section of this site) and restart WL6.
Size:
Color:
How can I check Ask and Bid before taking a position?
Size:
Color:
Size:
Color:
How do you cancel an order?
Is there any way you can change (cancel and place) a live (cover) order?
Size:
Color:
More specifically, is it possible to change setTrailingStop parameters (like pullback etc) after a cover order is placed?
Size:
Color:
QUOTE:
How do you cancel an order?
Don't execute it on the next bar.
QUOTE:
Is there any way you can change (cancel and place) a live (cover) order?
If the strategy changes the stop or limit price on a subsequent bar, then the previous order is canceled and replaced with the new order.
Manually, you can select the order and click "Cancel/Replace Seleted" in the toolbar.
Size:
Color:
just confirming...talking about auto-trading only...(not manual)...
If a setTrailingStop is placed with a pullback of 5%
then price moves up or down and now we want to change the pullback to 6%.
All we have to do is place the order again...Right?
Size:
Color:
Cone, Please refer to your response dated 3/17/2011 6:30 PM
How do you "Don't execute it on the next bar"?
Size:
Color:
CODE:
Please log in to see this code.
Just see almost any strategy ever published. You execute a signal (BuyAt, ExitAt, etc.) based on conditional logic. If the condition is false, the signal is not executed.
Look, just like you stated,
"If a setTrailingStop is placed with... then price moves up or down and now we want...". That's exactly how code operates - if (check something) [then] do something [else] do something else.
Size:
Color:
After I run a back test, in the Trades report... can I add/delete more columns...specifically some "comments" or "description" columns
Size:
Color:
No.
Size:
Color:
how do you capture unrealized gains/loss in an active position?
Size:
Color:
See QuickRef (F11) > Position Object
> MAEAsOfBarPercent
> MFEAsOfBarPercent
> NetProfitAsOfBarPercent
Don't use "non" Percent measures in the trading script since dollar amounts will be based on a 1-share Position there. Those dollar-based properties are there to be used by Visualizers, PosSizers, etc.
That said, an exception is using the "WealthScript Override (SetShareSize)" option. By performing the sizing operation in the script itself, the dollar-based MAE/MFE/NetProfit values should be accurate in the trading script - though I don't think it includes commission costs.
Size:
Color:
How do I determine number of shares in my position? I think position.shares also always returns 1.
Size:
Color:
how do you use WealthScript Override (SetShareSize) in the code?
Size:
Color:
The thread has got too far away from "Trading Strategies" (i.e. discussing trading techniques) with these various questions on WL6 features, daytrading and WealthScript. Please consider posting them in a new thread (or if you come up with non-related questions, in new threads) that we would then move to a proper subforum. Thanks.
Size:
Color: