Hi
I have the following code in a system. I will run it with updated data (I check the data is updated to yesterday's close) and it sometimes shows orders and sometimes doesn't of course. But what is perplexing is that frequently (about 2x per week) I will see in the positions log the next day that positions were exited or entered the prior day for WHICH I RECEIVED NO SIGNAL. Any ideas, please?
I have the following code in a system. I will run it with updated data (I check the data is updated to yesterday's close) and it sometimes shows orders and sometimes doesn't of course. But what is perplexing is that frequently (about 2x per week) I will see in the positions log the next day that positions were exited or entered the prior day for WHICH I RECEIVED NO SIGNAL. Any ideas, please?
CODE:
public override void Execute(BarHistory bars, int idx) { if (idx == bars.Count - 1) return; //note - buys/sells at close on idx + 1 if (!HasOpenPosition(bars, PositionType.Long)) { //code entry logic here if (maFast[idx] > maSlow[idx]) if (macd[idx] > 0) PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx], "TP"); } else { //code exit conditions here Position p = LastPosition; int barsopen = (idx - p.EntryBar); bool cond2 = false; if (maFast[idx] < maSlow[idx]) { cond2 = true; } bool cond3 = false; { if (atr[idx] < 0.25 * atr[idx - barsopen]) { cond3 = true; //just using EMA exit now 19/04/22 } } bool cond4 = false; { if (atr[idx] > 4 * atr[idx - barsopen]) { cond4 = true; //just using EMA exit now 19/04/22 } } if (cond2 || cond3 || cond4) { PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, bars.Close[idx], "TP"); } } }
Rename
CODE:
if (idx == bars.Count - 1) return;
So you added a condition to SKIP signal generation (on bar - 1) altogether and wonder why the code isn't showing orders? 😉
It looks like this strategy originally was buying at the close? That would have been the reason for skipping the last bar. Strategies that peek ahead and trade at close can’t produce signals. Since this strategy uses limit orders and doesn't look ahead you can remove those lines that Eugene indicated.
Ah thanks, will try. All a bit different than WL6. Blessings
Eugene and Glitch
I really need to exit at Close for many of my strategies as I have to ensure an exit (so not Limit), and Close is much better than Market because it is a more liquid and managed auction process by the exchanges. I am going through my strategies and realise, from your comments above, that unlike with WL6 I will not be able to get my orders in WL8 for about half my systems.
This is a fairly significant problem.
How can I have strategies that execute at the Close, for which WL8 will provide signals when I run the code pre-market? Otherwise, I can't use buying and selling AtClose in my systems, which is not good.
Thanks!
I really need to exit at Close for many of my strategies as I have to ensure an exit (so not Limit), and Close is much better than Market because it is a more liquid and managed auction process by the exchanges. I am going through my strategies and realise, from your comments above, that unlike with WL6 I will not be able to get my orders in WL8 for about half my systems.
This is a fairly significant problem.
How can I have strategies that execute at the Close, for which WL8 will provide signals when I run the code pre-market? Otherwise, I can't use buying and selling AtClose in my systems, which is not good.
Thanks!
WL isn’t a time machine. It can’t produce a signal for orders at market close when you’re basing the logic of the signal on data based on the closing price of that bar.
QUOTE:Can you explain how your strategy works with a concrete example? Reading this sounds like you want to use the AtClose signals the next day during premarket. How does that work?
How can I have strategies that execute at the Close, for which WL8 will provide signals when I run the code pre-market?
If the idea is to always exit at close if your Sell at Limit does not trigger, we could help you with that.
Thank you both.
I realise the main problem is strategies which close at the last trading day of the month (of which I have 3). My current code looks to see if next day is the last trading day, then if so it closes at that close (i.e. the next day's close).
Perhaps a solution is a way to see if the current bar is one day BEFORE the last trading day of the month. Then I don't need to look ahead:). Is that possible, and how would I code that please?
Thank you and best regards
Rod
PS: When I see premarket I just mean before the current trading day begins, like 7am US EST (I live in New Zealand and I put on my trades at night before the market opens around 1am my time).
I realise the main problem is strategies which close at the last trading day of the month (of which I have 3). My current code looks to see if next day is the last trading day, then if so it closes at that close (i.e. the next day's close).
Perhaps a solution is a way to see if the current bar is one day BEFORE the last trading day of the month. Then I don't need to look ahead:). Is that possible, and how would I code that please?
Thank you and best regards
Rod
PS: When I see premarket I just mean before the current trading day begins, like 7am US EST (I live in New Zealand and I put on my trades at night before the market opens around 1am my time).
Here's how you can tell in advance the last trading day of the week or month is.
This snippet highlights the "signal bar" - the one before the last day of the week/month.
This snippet highlights the "signal bar" - the one before the last day of the week/month.
CODE:
public override void Execute(BarHistory bars, int idx) { if (bars.GetNextTradingDate(idx).IsLastTradingDayOfWeek(bars)) { //tomorrow is the last trading day this week SetBackgroundColor(bars, idx, WLColor.Blue); } if (bars.GetNextTradingDate(idx).IsLastTradingDayOfMonth(bars)) { //tomorrow is the last trading day of the month SetBackgroundColor(bars, idx, WLColor.Red); } if (bars.IsLastTradingDayOfMonth(idx)) { //today is last trading day of month } }
Awesome. I will try it. Thanks!
Your Response
Post
Edit Post
Login is required