本文整理汇总了C#中Bar类的典型用法代码示例。如果您正苦于以下问题:C# Bar类的具体用法?C# Bar怎么用?C# Bar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bar类属于命名空间,在下文中一共展示了Bar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnBar
public override void OnBar(Bar bar)
{
// if we don't have a position and we have some bars
// in the bollinger series, try to enter a new trade
if (!HasPosition)
{
if (bbl.Count > 0)
{
// if the current bar is below the lower bollinger band
// buy long to close the gap
if (Bars.Crosses(bbl, bar) == Cross.Below)
{
buyOrder = MarketOrder(OrderSide.Buy, Qty, "Entry");
buyOrder.Send();
}
}
}
else
{
// else if we DO have an existing position, and if
// today's bar is above our entry price (profitable),
// then close the position with a market order
if (entryPrice < bar.Close)
{
barsFromEntry = 0;
Sell(Qty, "Exit (Take Profit)");
}
else
barsFromEntry++;
}
}
示例2: LoadMusicData
void LoadMusicData(string jsonText)
{
JsonData data = JsonMapper.ToObject(jsonText);
JsonData bars = data["bars"];
_bars = new Bar[bars.Count];
for (int i = 0; i < bars.Count; i++) {
_bars[i] = new Bar(confidence: (double)(bars[i]["confidence"]),
start: (double)(bars[i]["start"]),
duration: (double)(bars[i]["duration"]));
}
JsonData beats = data["beats"];
_beats = new Bar[beats.Count];
for (int i = 0; i < beats.Count; i++) {
_beats[i] = new Bar(confidence: (double)(beats[i]["confidence"]),
start: (double)(beats[i]["start"]),
duration: (double)(beats[i]["duration"]));
}
JsonData tatums = data["tatums"];
_tatums = new Bar[tatums.Count];
for (int i = 0; i < tatums.Count; i++) {
_tatums[i] = new Bar(confidence: (double)(tatums[i]["confidence"]),
start: (double)(tatums[i]["start"]),
duration: (double)(tatums[i]["duration"]));
}
JsonData segments = data["segments"];
_segments = new Bar[segments.Count];
for (int i = 0; i < segments.Count; i++) {
_segments[i] = new Bar(confidence: (double)(segments[i]["confidence"]),
start: (double)(segments[i]["start"]),
duration: (double)(segments[i]["duration"]));
}
}
示例3: ExitAlertCreate
public Alert ExitAlertCreate(Bar exitBar, Position position, double stopOrLimitPrice, string signalName,
Direction direction, MarketLimitStop exitMarketLimitStop) {
this.checkThrowEntryBarIsValid(exitBar);
this.checkThrowPositionToCloseIsValid(position);
double priceScriptOrStreaming = stopOrLimitPrice;
OrderSpreadSide orderSpreadSide = OrderSpreadSide.Unknown;
if (exitMarketLimitStop == MarketLimitStop.Market) {
priceScriptOrStreaming = this.getStreamingPriceForMarketOrder(exitMarketLimitStop, direction, out orderSpreadSide);
}
PositionLongShort longShortFromDirection = MarketConverter.LongShortFromDirection(direction);
double exitPriceScript = exitBar.ParentBars.SymbolInfo.RoundAlertPriceToPriceLevel(
priceScriptOrStreaming, true, longShortFromDirection, exitMarketLimitStop);
Alert alert = new Alert(exitBar, position.Shares, exitPriceScript, signalName,
direction, exitMarketLimitStop, orderSpreadSide,
//this.executor.Script,
this.executor.Strategy);
alert.AbsorbFromExecutor(executor);
alert.PositionAffected = position;
// moved to CallbackAlertFilled - we can exit by TP or SL - and position has no clue which Alert was filled!!!
//position.ExitCopyFromAlert(alert);
alert.PositionAffected.ExitAlertAttach(alert);
return alert;
}
示例4: ShouldWork
public void ShouldWork()
{
using (var store = NewDocumentStore())
{
store.Conventions.IdentityTypeConvertors.Add(new UInt32Converter());
using (var session = store.OpenSession())
{
var foo = new Foo() { Id = uint.MaxValue };
foo.Related.Add(uint.MaxValue);
session.Store(foo);
var bar = new Bar { Id = uint.MaxValue };
session.Store(bar);
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var foo = session.Query<Foo>()
.Customize(x=>x.WaitForNonStaleResults())
.ToList();
var bar = session.Query<Bar>().ToList();
//This line blows up
var foobar = session.Query<Foo>().Include<Foo, Bar>(f => f.Related).ToList();
}
}
}
示例5: RunTest
static void RunTest (int expected)
{
IFoo a = (IFoo) new Bar ();
Assert.AreEqual (expected, a.Execute (), "#A1");
Assert.AreEqual (expected, a.Count, "#A2");
Bar b = new Bar ();
Assert.AreEqual (expected, b.Execute (), "#B1");
Assert.AreEqual (expected, b.Count, "#B2");
Foo c = new Foo ();
Assert.AreEqual (1, c.Execute (), "#C1");
Assert.AreEqual (1, c.Count, "#C2");
Assert.AreEqual (expected, ((IFoo) new Bar ()).Execute (), "#D1");
Assert.AreEqual (expected, ((IFoo) new Bar ()).Count, "#D2");
Assert.AreEqual (1, new Bar ().Execute (), "#E1");
Assert.AreEqual (1, new Bar ().Count, "#E2");
Assert.AreEqual (1, new Foo ().Execute (), "#F1");
Assert.AreEqual (1, new Foo ().Count, "#F2");
Assert.AreEqual (expected, CreateBar ().Execute (), "#G1");
Assert.AreEqual (expected, CreateBar ().Count, "#G2");
}
示例6: OnBar
/*
按照股指的时间要求,时间划分是这样的
9:15
9:45
10:15
10:45
11:15-11:30 13:00-13:15 两个15分钟被午休隔开了
13:45
14:15
14:45
15:15 交割日时只到15:00,已经到最后一天了,少15分钟也没什么
*/
public override void OnBar(Bar bar)
{
//只处理15分钟的
if (900 == bar.Size)
{
if (bars == null)
bars = new BarSeries();
bars.Add(bar);
//在处理11:15-11:30 13:00-13:15这两个15分钟时会合并成一个
if (bars.Count == 2) // 2 * 15min = 30 min
{
// get OHLC values for 30min bar
double open = bars[0].Open;
double high = bars.HighestHigh();
double low = bars.LowestLow();
double close = bars[1].Close;
long volume = bars[0].Volume + bars[1].Volume;
// todo something
Bar b = new Bar(bars[0].DateTime, open, high, low, close, volume, 900 * 2);
bars30min.Add(b);
Console.WriteLine(b);
// reset 15min bar series
bars = null;
}
}
}
示例7: Add
public void Add(Bar bar)
{
var barsWithInstrumentId = this.bars[bar.InstrumentId] = this.bars[bar.InstrumentId] ?? new IdArray<IdArray<BarSeries>>(8);
var barsWithInstrumentIdAndType = barsWithInstrumentId[(int)bar.Type] = barsWithInstrumentId[(int)bar.Type] ?? new IdArray<BarSeries>();
var barsWithInstrumentIdAndTypeAndSize = barsWithInstrumentIdAndType[(int)bar.Size] = barsWithInstrumentIdAndType[(int)bar.Size] ?? new BarSeries("", "", -1, -1);
barsWithInstrumentIdAndTypeAndSize.Add(bar);
}
示例8: BoolVariable
/// <summary>
/// Creates a new boolean variable in a given bar.
/// </summary>
/// <param name="bar">The bar to create the boolean variable in.</param>
/// <param name="initialValue">The initial value of the variable.</param>
/// <param name="def">An optional definition string for the new variable.</param>
public BoolVariable(Bar bar, Boolean initialValue = false, String def = null)
: base(bar, InitBoolVariable, def)
{
Validating += (s, e) => { e.Valid = true; };
ValidateAndSet(initialValue);
}
示例9: run
void run()
{
Bar b = new Bar();
Foo f = b.create();
FooBar fb = new FooBar();
FooBar2 fb2 = new FooBar2();
String s;
s = fb.used();
if ( s != ("Foo::pang();Bar::pong();Foo::pong();FooBar::ping();"))
throw new Exception("bad FooBar::used" + " - " + s);
s = fb2.used();
if ( s != ("FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();"))
throw new Exception("bad FooBar2::used");
s = b.pong();
if ( s != ("Bar::pong();Foo::pong();Bar::ping();"))
throw new Exception("bad Bar::pong");
s = f.pong();
if ( s != ("Bar::pong();Foo::pong();Bar::ping();"))
throw new Exception("bad Foo::pong");
s = fb.pong();
if ( s != ("Bar::pong();Foo::pong();FooBar::ping();"))
throw new Exception("bad FooBar::pong");
}
开发者ID:abhishekgahlot,项目名称:Python-Fingerprint-Attendance-System,代码行数:28,代码来源:director_protected_runme.cs
示例10: Foo
public void Foo()
{
var bar = new Bar { List = new RxList<string>() };
bar.List.Add("foobar");
var json = JsonConvert.SerializeObject(bar);
var deserializedBar = JsonConvert.DeserializeObject<Bar>(json);
}
示例11: BuildItem
/// <summary>
/// 构建插件单元
/// </summary>
/// <param name="caller">调用者</param>
/// <param name="context">上下文,用于存放在构建时需要的组件</param>
/// <param name="element">插件单元</param>
/// <param name="subItems">被构建的子对象列表</param>
/// <returns>构建好的插件单元</returns>
public object BuildItem(object caller, WorkItem context, AddInElement element, ArrayList subItems)
{
if (element.Configuration.Attributes["label"] == null)
throw new AddInException(String.Format("没有为类型为 \"{0}\" 的插件单元{1}提供label属性。",
element.ClassName, element.Id));
string label = element.Configuration.Attributes["label"];
BarManager barManager = context.Items.Get<BarManager>(UIExtensionSiteNames.Shell_Bar_Manager);
if (barManager == null)
throw new UniframeworkException("未定义框架外壳的工具条管理器。");
Bar item = new Bar(barManager, label);
item.BarName = element.Name;
item.DockStyle = BarDockStyle.Top; // 默认停靠在顶部
if (element.Configuration.Attributes["dockstyle"] != null) {
string dockStyle = element.Configuration.Attributes["dockstyle"];
item.DockStyle = (BarDockStyle)Enum.Parse(typeof(BarDockStyle), dockStyle);
}
// 是否让工具栏显示整行
if (element.Configuration.Attributes["wholerow"] != null)
item.OptionsBar.UseWholeRow = bool.Parse(element.Configuration.Attributes["wholerow"]);
if (element.Configuration.Attributes["allowcustomization"] != null)
item.OptionsBar.AllowQuickCustomization = bool.Parse(element.Configuration.Attributes["allowcustomization"]);
if (element.Configuration.Attributes["register"] != null) {
bool register = bool.Parse(element.Configuration.Attributes["register"]);
if (register)
context.UIExtensionSites.RegisterSite(BuilderUtility.CombinPath(element.Path, element.Id), item); // 此处可能抛出异常
}
return item;
}
示例12: Aggregate
public Aggregate(Service1 one, Service2 two, Foo foo, Bar bar)
{
this.one = one;
this.two = two;
this.foo = foo;
this.bar = bar;
}
示例13: Adapter
public void Adapter(Bar barTarget)
{
m_BarItems = new List<BarItem>();
BandItemLinks2(barTarget.ItemLinks, ref m_BarItems);
System.Windows.Forms.Application.Idle += new EventHandler(Application_Idle);
}
示例14: FloatVariable
/// <summary>
/// Creates a new single-precision floating-point variable in a given bar.
/// </summary>
/// <param name="bar">The bar to create the floating-point variable in.</param>
/// <param name="initialValue">The initial value of the variable.</param>
/// <param name="def">An optional definition string for the new variable.</param>
public FloatVariable(Bar bar, Single initialValue = 0, String def = null)
: base(bar, InitFloatVariable, def)
{
Validating += (s, e) => { e.Valid = (Min <= e.Value) && (e.Value <= Max); };
ValidateAndSet(initialValue);
}
示例15: OnNewBar
private void OnNewBar(object sender, BarEventArgs args)
{
if (NewBar != null)
{
CThostFtdcDepthMarketDataField DepthMarket;
Instrument inst = InstrumentManager.Instruments[args.Instrument.Symbol];
string altSymbol = inst.GetSymbol(Name);
Bar bar = args.Bar;
if (_dictDepthMarketData.TryGetValue(altSymbol, out DepthMarket))
{
bar = new Bar(args.Bar);
bar.OpenInt = (long)DepthMarket.OpenInterest;
}
if (null != MarketDataFilter)
{
Bar b = MarketDataFilter.FilterBar(bar, args.Instrument.Symbol);
if (null != b)
{
NewBar(this, new BarEventArgs(b, args.Instrument, this));
}
}
else
{
NewBar(this, new BarEventArgs(bar, args.Instrument, this));
}
}
}