﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.ru/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.ru/css/bbeditor.css'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Не выполняется Once() для своих правил стратегий</title>
  <id>~/topic/2255/ne-vypolnyaetsya-once()-dlya-svoih-pravil-strategii/</id>
  <rights type="text">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  <updated>2026-06-14T21:53:49Z</updated>
  <logo>https://stocksharp.ru/images/logo.png</logo>
  <link href="https://stocksharp.ru/handlers/atom.ashx?category=topic&amp;id=2255" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.ru/posts/m/15054/</id>
    <title type="text">Упс) Невнимательность моя. Спасибо большое! </title>
    <published>2011-12-22T05:07:25Z</published>
    <updated>2011-12-22T05:07:25Z</updated>
    <author>
      <name>Supervisor</name>
      <uri>https://stocksharp.ru/users/27975/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">&lt;p&gt;Упс) Невнимательность моя. Спасибо большое!&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.ru/posts/m/15044/</id>
    <title type="text">статик поле сделайте. у вас каждый раз возвращает новое правило </title>
    <published>2011-12-21T13:23:31Z</published>
    <updated>2011-12-21T13:23:31Z</updated>
    <author>
      <name>Alexander</name>
      <uri>https://stocksharp.ru/users/2826/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">&lt;p&gt;статик поле сделайте.
у вас каждый раз возвращает новое правило&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.ru/posts/m/15040/</id>
    <title type="text">Со стандартным аналогичным правилом CandlesStarted() - .Once() работает нормально </title>
    <published>2011-12-21T12:48:47Z</published>
    <updated>2011-12-21T12:48:47Z</updated>
    <author>
      <name>Supervisor</name>
      <uri>https://stocksharp.ru/users/27975/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">&lt;p&gt;Со стандартным аналогичным правилом CandlesStarted() - .Once() работает нормально&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.ru/posts/m/15036/</id>
    <title type="text">S# 4.0.10 (пробовал и на 4.0.8, 4.0.6) this .When(NewBar()) .Do(a =&amp;gt; Message(&amp;quot;whooops&amp;quot;)) .Once(); .....</title>
    <published>2011-12-21T12:40:37Z</published>
    <updated>2011-12-21T12:40:37Z</updated>
    <author>
      <name>Supervisor</name>
      <uri>https://stocksharp.ru/users/27975/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">&lt;p&gt;S# 4.0.10 (пробовал и на 4.0.8, 4.0.6)&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-plain"&gt;
this
	.When(NewBar())
	.Do(a =&amp;gt; Message(&amp;quot;whooops&amp;quot;))
	.Once();

...

protected StrategyRule NewBar() { return new NewBarStrategyRule(this); }

&lt;/code&gt;&lt;/pre&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.ru/posts/m/15034/</id>
    <title type="text">Вот например правило (дублирует по фукциональности одно из стандартных): private sealed class NewBar...</title>
    <published>2011-12-21T12:33:12Z</published>
    <updated>2011-12-21T12:37:43Z</updated>
    <author>
      <name>Supervisor</name>
      <uri>https://stocksharp.ru/users/27975/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">&lt;p&gt;Вот например правило (дублирует по фукциональности одно из стандартных):&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-plain"&gt;
private sealed class NewBarStrategyRule : StrategyRule
{
	// СВОЙСТВА
	private Security Security { get; set; }
	private TimeSpan TimeFrame { get; set; }

	// КОНСТРУКТОР
	public NewBarStrategyRule(MyStrategy baseStrategy)
	{
		Security = baseStrategy.Security;
		TimeFrame = baseStrategy.Graph.TimeFrame;
				
		Core.CandleManager.CandlesStarted += OnNewCandles;
	}

	// МЕТОДЫ
	private void OnNewCandles(CandleToken token, IEnumerable&amp;lt;Candle&amp;gt; candles)
	{
		if (token.Security == Security &amp;amp;&amp;amp; (TimeSpan)token.Arg == TimeFrame) // Если пришла наша свеча
			Activate();
	}

	// ДЕСТРУКТОР
	protected override void DisposeManaged()
	{
		Core.CandleManager.CandlesFinished -= OnNewCandles;
		base.DisposeManaged();
	}
}

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Проблема: действие .Once() по такому правилу продолжает выполняться бесконечно. Вроде все делал по инструкции [confused]&lt;/p&gt;
&lt;p&gt;S# 4.0.10 (пробовал и на 4.0.8, 4.0.6)&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.ru/posts/m/15035/</id>
    <title type="text">S# версия покажите как добавляете правило </title>
    <published>2011-12-21T12:35:17Z</published>
    <updated>2011-12-21T12:35:17Z</updated>
    <author>
      <name>Alexander</name>
      <uri>https://stocksharp.ru/users/2826/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">&lt;ol&gt;
&lt;li&gt;S# версия&lt;/li&gt;
&lt;li&gt;покажите как добавляете правило&lt;/li&gt;
&lt;/ol&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
</feed>