Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A simple strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    A simple strategy

    Hi, Ninja.

    I am a fish in writting the strategy script.

    I am going to make such a simple strategy firstly, but I still feel it is very difficult for me.

    The strategy is:

    if MSFT's price hit the trigger (close>open+2), then long IBM 100shares, after that if MSFT's price hit the trigger( close<open-5), close the long position.

    Could you supply me with some main script code?

    Regards,
    Ben

    #2
    Hello Ben,

    Thank you for your post.

    To clarify, are you running this strategy on a MSFT or IBM chart?

    This will determine what second data series you will need to add, and how the orders will be managed.

    Since this is classified as a Multi-Time Frame & Instrument strategy, please take some time to read the following section of the Help Guide.
    CameronNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Cameron View Post
      Hello Ben,

      Thank you for your post.

      To clarify, are you running this strategy on a MSFT or IBM chart?

      This will determine what second data series you will need to add, and how the orders will be managed.

      Since this is classified as a Multi-Time Frame & Instrument strategy, please take some time to read the following section of the Help Guide.
      http://www.ninjatrader.com/support/h...nstruments.htm
      Hello Cameron,

      I am not running this strategy on a MSFT or IBM chart even if it is possible.

      I just want to make an easy logic here and implement the strategy in easiest way:

      1) if (MSFT today's latest price , from IB) >
      (MSFT today's open price , a constant) + (a price offset)

      then
      Buy IBM 100shares with the market order.


      2) after that

      if (MSFT today's latest price , from IB) <
      (MSFT today's open price , a constant) - (a price offset)

      then
      Sell IBM 100shares with the market order.

      that's it.

      Regards,
      Ben
      Last edited by benlau; 02-21-2012, 08:55 PM.

      Comment


        #4
        Ben,

        You will need to run this strategy with either MSFT or IBM as the primary data series.

        If you were running the strategy on MSFT, sample code for going long would be as follows:

        protected override void Initialize()
        {

        Add("IBM", PeriodType.Minute, 1); // BarsInProgress/BarsArray == 1
        }

        protected override void OnBarUpdate()
        {
        if (CurrentBars[0] < 0 && CurrentBars[1] < 0)
        return;

        if (BarsInProgress == 0)
        {
        if (Close[0] > CurrentDayOHL().CurrentOpen[0])
        EnterLong(0, 100, "Buy IBM");
        }
        }


        More information can be found at the following links:

        Entering, Exiting and Retrieving Position Information - http://www.ninjatrader.com/support/h...nstruments.htm

        Adding additional bars or data series - http://www.ninjatrader.com/support/h....html?add3.htm

        CurrentDayOHL - http://www.ninjatrader.com/support/h...nt_day_ohl.htm

        You can see additional information and examples in the SampleMultiInstrument strategy that comes with NinjaTrader by default.
        CameronNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DanielTynera, Today, 01:14 AM
        0 responses
        2 views
        0 likes
        Last Post DanielTynera  
        Started by yertle, 04-18-2024, 08:38 AM
        9 responses
        40 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by techgetgame, Yesterday, 11:42 PM
        0 responses
        12 views
        0 likes
        Last Post techgetgame  
        Started by sephichapdson, Yesterday, 11:36 PM
        0 responses
        2 views
        0 likes
        Last Post sephichapdson  
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,615 views
        0 likes
        Last Post aligator  
        Working...
        X