Ninjya Traderの最近のブログ記事

ウィザードで1番最初に生成 されるのは、次のようなコード。
以下、ウィザードの指示に従って、変数を追加したり、条件を追加していくと、ソースコードにも変更が反映される。

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class MyCustomStrategy : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        }

        #region Properties
        [Description("")]
        [Category("Parameters")]
        public int MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }
}

#region Wizard settings, neither change nor remove
/*@
<?xml version="1.0" encoding="utf-16"?>
<NinjaTrader>
  <Name>MyCustomStrategy</Name>
  <CalculateOnBarClose>True</CalculateOnBarClose>
  <Description>Enter the description of your strategy here</Description>
  <Parameters>
    <Parameter>
      <Default1>
      </Default1>
      <Default2>1</Default2>
      <Default3>
      </Default3>
      <Description>
      </Description>
      <Minimum>1</Minimum>
      <Name>MyInput0</Name>
      <Type>int</Type>
    </Parameter>
  </Parameters>
  <State>
    <CurrentState>
      <StrategyWizardState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <Name>Flat</Name>
        <Sets />
        <StopTargets />
      </StrategyWizardState>
    </CurrentState>
  </State>
</NinjaTrader>
@*/
#endregion

プログラムのブロック構造


特徴

  • Microsoft C# に準拠
  • カプセル型
  • 入れ子構造

#region Using declarations

namespace NinjaTrader.Strategy
{
[Description("Multi-Instrument sample strategy.")]
    public class SampleMultiInstrument : Strategy
    {
#region Variables
  • 変数の宣言(型・名 前・初期値

protected override void Initialize()
        {
  • 指標描画の設定
  • ストップロス・利益目標・トレーリングストップロスの設定
        }
protected override void OnBarUpdate()
        {
  • 内部変数の計算
  • トレードの条件      
        }
     }
}




マニュアルのチュートリアルを眺めたところ、プログラムの作成手順は、
  1. ウィザードでソースを自動生成した後
  2. エディタで以下の3箇所のセクションを編集する流れか?
    • Variables
    • Initialize()
    • OnBarUpdate()

「ニンジャトレーダー入門」は、 Ninja Traderのアウトラインを掴むため、最初に読むにはいい本だ。

しかし、ストラテジーを開発しようとなると解説不足だ。

 Ninja Traderのサポートセンターで解説ビデオを観る。

http://www.ninjatrader.com/webnew/support.htm

Strategy Wizard (NinjaScript)

Strategy Wizard

Overview of the Strategy Wizard

Condition Builder

Construction conditions and actions in the Strategy Wizard

その後もいろいろ調べた結果、サポートセンターからPDFマニュアル(全627頁)を入手。

ヘルプファイルと同じ内容。

http://www.ninjatrader.com/webnew/support.htm

言語(NinjaScript)についての解説部分(262頁~487頁)を印刷して読むことにした。

サンプルストラテジーを眺めたところ、役割ごとにブロック化されていて、xmlの記述に似ている気もした。

 

まだ使い方がよくわからないまま、「ニンジャトレーダー入門」を片手にインポートした225ミニのチャート表示まで完了。

NT_Chart20090313.JPG


今後の課題として、次回からは

  1.  Ninja Trader用に、簡単にデータのフォーマット変換をする手段を考える
  2. Ninja Traderでつなぎ足作成
  3.  Ninja TraderScriptで戦略作成
といったところ。


「ニンジャトレーダー入門」が本日発売だったので、早速購入。
Ninja Traderは以前にダウンロードし、インストールだけ済ませておいたのだが、使い方がわからず、そのまま放置状態でした。

バックテストだけだと、 ニンジャトレーダーは無料。
下記のような作業を行った。

  1. 分足のデータをトレードシグナルからテキストファイルに落とす
  2. データのフォーマットをニンジャトレーダー用に変換
  3.  Ninja Traderのインポート用の指定フォルダに移動
  4. インポート
何度か、エラーが発生!
ログで確認。

Format error in line 3607: 入力文字列の形式が正しくありません。: '20081003 15:11;10990.0000;10990.0000;10990.0000;10990.0000;n/a'


NT_Log20090313.JPG


エディタでデータを開き確認すると、3607行のvolumeがn/aとなっていた。

(データの一部欠落)

ダミーの数字(999)を入れ、問題解決。


アイテム

  • PIC008.JPG
  • PIC007.JPG
  • PIC003.JPG
  • PIC001.JPG
  • pic3.JPG
  • pic2.JPG
  • pic1.JPG
  • NT_Chart20090313.JPG
  • NT_Log20090313.JPG

タグクラウド