NexusFi: Find Your Edge


Home Menu

 





Spread Order management


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one ural01 with 6 posts (0 thanks)
    2. looks_two rleplae with 4 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 vadzzim with 1 posts (1 thanks)
    1. trending_up 3,045 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread

Spread Order management

  #11 (permalink)
 vadzzim 
Belarus
 
Experience: Beginner
Platform: NinjaTrader
Trading: NQ, CL
Posts: 20 since Sep 2015
Thanks Given: 5
Thanks Received: 11

@ural01, it works for me

 
Code
#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>
    /// 
    /// </summary>
    [Description("")]
    public class VzSpread : Strategy
    {
        #region Variables
        // User defined variables (add any user defined variables below)
		private string secondaryInstrument = "TF 12-15"; // <- type here your instrument name
		private PeriodType secondaryPeriodType = PeriodType.Minute;
		private int secondaryPeriodValue = 10;
		private int quantity = 1;
		private double profit = 200;
		private double loss = 100;
		const int PRIMARY_INDEX = 0;
		const int SECONDARY_INDEX = 1;
        #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;
			
            Add(secondaryInstrument, secondaryPeriodType, secondaryPeriodValue);
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			if (!Historical) return;
			
			// enter
			if (Position.MarketPosition == MarketPosition.Flat) {
				EnterLong(PRIMARY_INDEX, quantity, "primaryInstrumentLong");
				EnterLong(SECONDARY_INDEX, quantity, "secondaryInstrumentLong");
			}
			
			// exit
			double profitLoss = Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
			if (profitLoss > profit || profitLoss < -loss) {
				ExitLong("primaryInstrumentLong");
				ExitLong("secondaryInstrumentLong");
			}
        }

        #region Properties
        #endregion
    }
}

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
What broker to use for trading palladium futures
Commodities
Better Renko Gaps
The Elite Circle
use extra computer for optimisation
NinjaTrader
 
  #12 (permalink)
 
ural01's Avatar
 ural01 
Colorado Springs, CO
 
Experience: Master
Platform: NinjaTrader
Broker: GAIN CAPITAL
Trading: Currency Futures
Posts: 24 since Mar 2010
Thanks Given: 9
Thanks Received: 0

Thank you , i find the problem
you have to point to data series if (BarsInProgress==0) or 1
in order to exit at same time

Started this thread Reply With Quote




Last Updated on November 29, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts