Profile Picture

NewBar not triggering on FilteredDailyFrequency

Posted By alpha23 2 Years Ago
Message
Posted Monday May 18 2015
Daniel,
From the following post: http://www.rightedgesystems.com/forums/13814/BarClosing-in-Live-system-with-daily-system-frequency?Keywords=filter%20frequency%20newbar
you stated:
 "For live mode, I'd recommend using the FilteredDailyFrequency. You can specify a start time of 9:30 am and an end time of 3:59 pm (or whatever you prefer). The bar from the filtered daily frequency will only include data in that time range, and NewBar will be raised just after the end time you specify (as long as you are still receiving live data)."

However, NewBar is not being triggered after the specified end time with live data still being received.  I'm on build 54.
Also, while I haven't tested it, is it possible to specify the start time in a filtered frequency to be after the end time?  For some contracts, the extended trading hours begins the day before, e.g. 16:30, and ends the current day, e.g., 16:00.

Please advise.

Thanks, Duane


Posted Wednesday May 20 2015
Please let me know as soon as possible.

Thanks, Duane
Posted Thursday May 21 2015
Hi Duane,

Does the FilteredDailyFrequency NewBar get triggered correctly when you run a backtest?

Are you using the FilteredDailyFrequency as your "main" system frequency (ie configured in the system properties), or are you creating a new frequency in code?

FilteredDailyFrequency doesn't currently support an end time that is before the start time.  The source code is available here, so you could probably modify it to do so.  I haven't done so yet partly out of fear of breaking something- it seems like there have been a fair amount of bugs with it over the years.  I've been adding tests every time I fixed a bug in it though, so probably by now the coverage is pretty good.

Thanks,
Daniel
Posted Friday May 22 2015
FilteredDailyFrequency is set in main system.

There appears to be defect.  If the settings are changed for a FilteredDailyFrequency, in my case EndTime, via Options | Frequencies, the setting is not updated when the frequency is used in the main system unless you first switch frequencies (e.g. to 'Daily'), run with that frequency, then switch back to the FilteredDailyFrequency and rerun the system.

The above applies for changing the name of the FilteredDailyFrequency as well.

Duane

Edited: Friday May 22 2015 by alpha23
Posted Friday May 22 2015
Regarding the end time before the start time, I changed the && to || in the comparison of InRange, i.e., if (time >= _startTime || time < _endTime) but obtained the following exception:

Duplicate bars received ending on: 6/1/2005 12:00:00.If you are running a simulation, this may mean that your bar data store has multiple bars for the same date. If you want to allow duplicate bars (for a custom frequency, for example), set the SystemData.AllowDuplicateBars property to true in your system's Startup method. at RightEdge.Common.BaseSystemHistory.SimNewBar(NewBarEventArgs newBars) at RightEdge.Common.Internal.SystemRunner.UpdateObjects(FrequencyNewBarEventArgs args) at RightEdge.Common.Internal.SystemRunner.ProcessBarEvents(IEnumerable`1 eventList) at RightEdge.Common.FrequencyManager.SendPendingBars() at RightEdge.Common.FrequencyManager.UpdateTime(DateTime dateTime) at RightEdge.Common.Internal.SystemRunner._tickGenerator_NewBar(Object sender, NewBarEventArgs e) at RightEdge.Common.TickGenerator.ProcessBar(NewBarEventArgs args) at RightEdge.Common.Internal.SystemRunner.ProcessBar(NewBarEventArgs newBars) at RightEdge.Shared.SystemWrapper.RunSystem(SystemData systemData, SharedSystemRunData runData, ServiceFactory brokerFactory) at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings) at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings) at RightEdge.Shared.TradingModuleWrapper.Run(String filename) at RightEdge.Shared.TradingModuleWrapper.RunSystem(SharedSystemRunData systemRunData) at RightEdge.SystemProgress.InitAndRunSystem()

I'm not seeing where else in the code logic should be changed.  Any insight would be helpful.  Again, the start date will be the day prior to the end date.

Thanks, Duane

Posted Friday May 22 2015
Hi Duane,

Am I understanding correctly that NewBar wasn't triggering due to the issue where the settings changes weren't applied to your system?  So now you are able to correctly get new bars?

Thanks,
Daniel
Posted Tuesday May 26 2015
NewBar and BarClosing is triggered in simulations but not for live.  For live, RightEdge just stops processing ticks.

I realize that BarClosing was designed for simulations but it would be helpful for Live so that the system does not have to be redesigned.  It would be great to have the ability to set the minimum time prior to closing to make it easier to submit MOCs, for example.  I currently do this in NewTick and while the additional code to check for time is not onerous, I must use different code paths for simulations and live.

Please advise as to how I can fix NewBar not being triggered in Live.  Also, setting end time before start time per my previous post.  Both are important for the system that I'm trading.

Thanks,  Duane
Posted Wednesday May 27 2015
As I understand it, BarClosing is generally used to trade at the close of the bar.  In real trading, this means you need to submit an order shortly before the close.  However, the appropriate value for "shortly before the close" depends on a lot of things - the liquidity and volatility of the instrument, and the balance between trading as close to the close as possible and the risk that the order won't be filled.  RightEdge can't take those factors into account.

So to trade on the close for live trading, I recommend using FilteredDailyFrequency with the bar close an appropriate amount of time before the real close.  IE if you want to submit your trade 1 minute before the daily close at 4:00 pm, use a FilteredDailyFrequency with an end time of 3:59 pm.  If you have 1 minute bar data for simulation, you could use this same logic in simulations.

For the FilteredDailyFrequency NewBar not being triggered during live trading, you said that live data is still being received, but that RightEdge stops processing the ticks.  Where do you see the data being received?  Are you seeing trade ticks as well as bid and ask ticks?  What are you observing when you say that RightEdge stops processing the ticks?  Do you have "Ignore live data outside exchange hours" enabled in the "Live" tab of the RightEdge options?  In your symbol setup, what is "Construct Bars From" set to?

Thanks,
Daniel
Posted Wednesday May 27 2015
Daniel,

    The requirements for the timing of MOC or different for different markets, e.g.,  NYSE requires the orders received by 15:45 ET.  Setting the FilteredDailyFrequency to before the actual market close will not work because in the case of NYSE, there is still 15 minutes of market activity (and potential trades) after an MOC order must be submitted.  For simulations, in some cases I do not have granularity to 15 minutes (and the trigger to trade may be based on this price at 15:45), so I make the assumption that the price at 15:45 is the same as 16:00 (which is why BarClosing is important).   This may or may not be the case but given the data it is the best that can be approximated for the system short of not trading MOC orders at all.  MOC orders should always be executed for small volume trades (relative to orders placed by larger players) for liquid instruments.

When coding the live and simulation code, it is always error prone to use two different code paths.  Having BarClosing being able to be triggered X minutes prior to the close time would help in consolidating simulation and live code.

Regarding the FilteredDailyFrequency and live data, I tested by setting the FilteredDailyFrequency end time to a time in the middle of the trading session.  NewTick is hit prior to this end time but not after.  I believe data still appears in the live data window.  I do not have the "Ignore live data outside of exchange hours" checked in the Options | Live tab.  Construct Bars From is set to Default.

Please let me know.

Thanks, Duane
Posted Friday May 29 2015
Hi Duane,

You won't get any ticks from the FilteredDailyFrequency outside of its trading hours, but you should still get the new bar event from it in live trading.  I tried it out with the following simple test system and the random data service and that's what I observed.


public class MySymbolScript : MySymbolScriptBase
{
  public override void Startup()
  {
   // Perform initialization here.
   FilteredDailyFrequency fdf = new FilteredDailyFrequency();
   fdf.StartTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromMinutes(1));
   fdf.EndTime = fdf.StartTime.Add(TimeSpan.FromMinutes(1));

   OutputMessage("Filtered Daily Frequency start time: " + fdf.StartTime);
   OutputMessage("Filtered Daily Frequency end time: " + fdf.EndTime);

   SystemData.BarFrequency = fdf;
  }

  public override void NewBar()
  {
   // Put your trading code here
   OutputMessage("New Bar");

  }

  public override void NewTick(BarData partialBar, TickData tick)
  {
   OutputMessage("New Tick: " + tick.ToString());
  }
}


Can you try this code and let me know what happens?

Thanks,
Daniel



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems