Stop-Alert at first bar (End-Of-Day-Data)
Author: Gamba
Creation Date: 1/8/2013 2:51 AM
profile picture

Gamba

#1
Hi,

I want to set an initial worst case stop at the first bar of a new entry.
The following code works in backtest, but no Stop-Alert is generated in Live-Trading
only the Entry-Alert.

I guess that there is no new position object at the time of generating the Buy-Alert.
I'm using EndOfDay-Data only and want the Stop-Alert be generated at the first bar, right
after the entry, so I can add it to my order.

Is this possible?


CODE:
Please log in to see this code.


Holger
profile picture

Eugene

#2
Hi,

It's called the "most subtle" peeking error to order the code like that, testing a Position's active status after executing a trading signal. For more, please check out the WealthScript Programming Guide > Programming Trading Strategies > Peeking > Trading based on Position Active Status.

At any rate, prefacing an entry with RiskStopLevel should do the job, assigning the initial stop loss value for a newly created Position (although it doesn't exist yet).

This will do it:
CODE:
Please log in to see this code.
profile picture

Gamba

#3
Hi Eugene,

I know about the peeking issues, the stop is only an initial one to protect the position
far away from entry, e.g. in crash situations.

As you can see in my code above I already set the RiskStopLevel before entering a position.
But no alert is generated.

Keep in mind, I want to generate alerts for LIVE-TRADING. During backtesting it works fine.
My question is: Is it possible to generate a stop-order-alert for live trading in strategy monitor
at the same time the BuyAtMarket (bar+1, "Entry") alert is generated?

The RiskStopLevel is not working with RawProfitMode.

profile picture

Eugene

#4
QUOTE:
The RiskStopLevel is not working with RawProfitMode.

You're clearly doing something incorrect as RiskStopLevel is undoubtedly working in both Raw Profit and Portfolio Simulation modes.
QUOTE:
My question is: Is it possible to generate a stop-order-alert for live trading in strategy monitor at the same time the BuyAtMarket (bar+1, "Entry") alert is generated?

Sure. Check out this helpful thread for comments and code examples:

Same Bar Exit
profile picture

Gamba

#5
Eugene, this is your preferred code:

CODE:
Please log in to see this code.


When I run this code till today 08.01.2013, "last 2 years" there is only one entry alert.
In strategy monitor there is only one alert too.

What about the metnioned stop-alert? I thought, I could get e SellMarket-Alert in addition
with the entry and RiskStopLevel. The link you mention above says the same, or did I understand something wrong?

Same Bar Exit is activiated, but I'm using EOD-data, so I guess this causes the behaviour ...?
profile picture

Eugene

#6
Please carefully digest the thread linked above.
profile picture

Gamba

#7
Please give me a hint. Fact is, that there is no alert for the sell-market-order.
Is this generally possible?
profile picture

Eugene

#8
Fact is, "my preferred code" was sent before I realize what your task is -- after you made the clarification.

So carefully read the forum thread, it's important to understand the theory. There also is a code snippet in a posting by Cone dated 3/22/2012 5:25 PM with a design pattern for your task.
profile picture

Gamba

#9
Ok, Eugene, I read the thread carefully: I guess that is the main point.

"In backtesting the only proper same bar exit is an AtStop or AtLimit and/or AtClose order that follows an AtMarket entry. If you don't start with an AtMarket entry, no other combinations will produce realistic results. Just execute the same-bar exit logic following the AtMarket entry, on the same bar of course."

Plus code from Cone in the next posting.

I tried the code-snippet but it doesn't work in my case. The only way with EndOfDay-Data for me to set
the Initial-Stop right at the first bar, to get an Alert is to use ShortAtStop(..) ? Is this correct?
But then, the ShareSize is another as for the initial position.


For your information: I only need the alerts, no automatic routing or something else. The alerts
will be entered manually in my order tool.


profile picture

Eugene

#10
The "next posting" is 2/27/2012 3:27 AM whereas I'm trying to point you at the post from 3/22/2012 5:25 PM.

I don't know what "didn't work" for you, because I don't see how you incorporated the code into your strategy.
profile picture

Gamba

#11
Eugene, I try to ask more simple, but please try to execute the code above.
You see only an entry signal per symbol, no exit alert.
It doesn't matter if I try it with Cone's code (I read the full article)
instead of the BuyAtMarkt (..) snippet.

CODE:
Please log in to see this code.

Because for Live-Trading the Next bar doesn't exists. Am I right?
(I execute the strategy in strategy monitor, before market open)


Please answer my very simple questions:

1.) The only way with EndOfDay-Data for me to set the Initial-Stop right at the first bar and getting an ALERT is to use ShortAtStop(..) ? Is this correct?
2.) I it possible to create Alerts by my own and to add it in the AlertList?

profile picture

Eugene

#12
Holger,
QUOTE:
Because for Live-Trading the Next bar doesn't exists. Am I right?

You are right.
QUOTE:
You see only an entry signal per symbol, no exit alert.

Correct. You can't get an exit alert, because the entry alert hasn't triggered yet! The idea here is to follow Cone's advice on assigning a non-zero RiskStopLevel and/or an AutoProfitLevel, and engaging the "Allow Same Bar Exits" checkbox so that the Orders tool could do its magic.
QUOTE:
1.) The only way with EndOfDay-Data for me to set the Initial-Stop right at the first bar and getting an ALERT is to use ShortAtStop(..) ?

What does ShortAtStop have to do with it all?
QUOTE:
2.) I it possible to create Alerts by my own and to add it in the AlertList?

Yes, by entering a Position. ;) No, I don't think you'll be able to add an Alert() to the Alerts() collection.
profile picture

Gamba

#13
Ok, thank you for the detailed answer. That does it make more clear for me.

To cut this long story short:

QUOTE:
What does ShortAtStop have to do with it all?


With directly putting a ShortAtStop-Order after my BuyAtMarket I get an exit alert,
but with wrong share-size. This technique is used by the user from the thread you linked me to.

Thank you for your patience
Holger
profile picture

Eugene

#14
This is a technique of reversing a Position on the same bar (a different thing).
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).