Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Multi-Time Frame Higher High code Help needed

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

    Multi-Time Frame Higher High code Help needed

    /Error 204870
    Last edited by wallsteetking; 02-23-2013, 12:25 AM.

    #2
    Wallstreetking,

    I am happy to assist you.

    High is an array and expects integers, its not a function and won't work with dataseries.

    Have you added 3 data series to your strategy? BarsArray starts with BarsArray[0] for the default instrument, BarsArray[1] for the second, etc.

    For more information on multi-timeframe indicators/strategies, please see the following link.



    NinjaTrader also comes with a helpful reference sample of a strategy using multiple time frames. You can find it by going to Tools > Edit NinjaScript > Strategy > SampleMultiTimeFrame
    Last edited by NinjaTrader_AdamP; 10-31-2011, 07:07 AM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Here is the Code can you please clean it up for me

      Code:
      // 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 EXAMPLE : Strategy
          {
              #region Variables
      		private int stoplossticks = 25;
              #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()
              {
      			// Add a 5 minute Bars object to the strategy
      			SetProfitTarget("", CalculationMode.Ticks, 150);
                              Add(PeriodType.Minute, 5);
                              
                              // Add a 60 minute Bars object to the strategy
                              Add(PeriodType.Minute, 30);
                              
                              // Note: Bars are added to the BarsArray and can be accessed via an index value
                              // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
                           
                              // Add simple moving averages to the chart for display
                              // This only displays the SMA's for the primary Bars object on the chart
                          
                  CalculateOnBarClose = true;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      		// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
                              // We only want to process events on our primary Bars object (index = 0) which is set when adding
                              // the strategy to a chart
                              if (BarsInProgress != 0)
                                      return;
                              
                              // Checks  if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
                              if  (EMA(BarsArray[2], 50)[0] > EMA(BarsArray[2],200)[0])
      						if (
      						
                              {
                      	if Stochastics(7, 14, 3).D[0] <= 30)
      						)
      						
      					
                      	
      					
      					 
                      )
                  {
                      BarColor = Color.Black;
                      EnterLong(DefaultQuantity, "");
                              }	
      						}
                  // Condition set 1
               
      			// Condition set 2
      			
      			// Resets the stop loss to the original value when all positions are closed
      			if (Position.MarketPosition == MarketPosition.Flat)
      			{
      				SetStopLoss(CalculationMode.Ticks, stoplossticks);
      			}
      			
      			// If a long position is open, allow for stop loss modification to breakeven
      			else if (Position.MarketPosition == MarketPosition.Long)
      			{
      				Print("Position Long");
      				// Once the price is greater than entry price+15 ticks, set stop loss to breakeven
      				if (Close[0] > Position.AvgPrice + 24 * TickSize)
      				{
      					Print("Set stop loss to: " + Position.AvgPrice +0.0022);
      					SetStopLoss(CalculationMode.Price, Position.AvgPrice+0.0022);
      				}
      			}
      			else if (Position.MarketPosition == MarketPosition.Short)
      			{
      				// Once the price is greater than entry price+15 ticks, set stop loss to breakeven
      				if (Close[0] < Position.AvgPrice + -15 * TickSize)
      				{
      					SetStopLoss(CalculationMode.Price, Position.AvgPrice);
      				} 
              	}
      		}
      Last edited by wallsteetking; 02-23-2013, 12:26 AM.

      Comment


        #4
        WallstreetKing :

        The problem is with this : High[int barsAgo]

        You are using High as a function that takes a dataseries where it actually is an array and expects an integer.

        You want to use the function HighestBar() : http://www.ninjatrader.com/support/h...highestbar.htm

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        0 responses
        3 views
        0 likes
        Last Post helpwanted  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X