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

Limit orders are only trading one side of the market

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

    Limit orders are only trading one side of the market

    Hi,
    If I code my strategy as follows:

    if (Position.MarketPosition == MarketPosition.Flat && Open[0] <=r2)
    {
    EnterShortLimit(r2);
    }

    if (Position.MarketPosition == MarketPosition.Flat && Open[0] >=s2)
    {
    EnterLongLimit(s2);

    }

    I will ony get short trades. If I flip them as follows:
    if (Position.MarketPosition == MarketPosition.Flat && Open[0]>=s2)
    {
    EnterLongLimit(s2);
    }

    if (Position.MarketPosition == MarketPosition.Flat && Open[0] <=r2)
    {
    EnterShortLimit(r2);


    }
    I only get long trades. How can I get it to trade both sides of the market? Is there a setting I am missing?

    Thank you,
    Dave

    #2
    You need to post your entire strategy, as we cannot see what else you have coded.

    Comment


      #3
      This feature is only available in Unmanaged Approach. See User-Guide for more instructions.

      Comment


        #4
        Hi Cowpux,

        Thank you for posting.

        Yes, this is only available using the unmanaged approach with NinjaScript in which you can have it set to send trades individually.

        Here is a link on the unmanaged approach from our online help guide.
        http://www.ninjatrader.com/support/h...d_approach.htm

        Let me know if I can be of further assistance
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by DarthTraderson View Post
          This feature is only available in Unmanaged Approach. See User-Guide for more instructions.
          #region Using declarations
          using System;
          using System.Collections;
          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 GaryWeeklyPivot : 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()
          {

          //ClearOutputWindow();
          /// Add a 5 minute Bars object to the strategy
          //Add(PeriodType.Minute, 5);

          // Add aweekly object to the strategy
          Add(PeriodType.Day,1);

          SetStopLoss(600, true);
          SetProfitTarget(1200);

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

          //double Piv,s1,s2,s3,r1,r2,r3;
          if (BarsInProgress != 0)
          return;



          double Piv=(Highs[1][1]+Lows[1][1]+Closes[1][1])/3;
          double s1=(2*Piv-Highs[1][1]);
          double s2=Piv-(r1-s1);

          double r1=(2*Piv-Lows[1][1])/3;
          double r2=(Piv-s1)-r1;


          //Print(DateTime.);

          //Print( Time[0]+" "+Highs[1][1]+" " +Lows[1][1]+" "+Closes[1][1]);

          if (Position.MarketPosition == MarketPosition.Flat && Open[0] <=r2)
          {
          EnterShortLimit(r2);
          }
          // end;
          if (Position.MarketPosition == MarketPosition.Flat && Open[0] >=s2)
          {
          EnterLongLimit(s2);

          }


          if(Position.MarketPosition == MarketPosition.Long )
          {
          if(ToTime(Time[0]) == 151500)
          ExitLong();


          }


          // end;

          else if(Position.MarketPosition == MarketPosition.Short )
          {
          if(ToTime(Time[0]) == 151500)
          ExitShort();


          }

          }

          }

          Comment


            #6
            In an Unmanaged Approach you are not able to use EnterShort / EnterLong.
            You have to use SubmitOrder(...) for all Entries and Exit-Orders.

            Comment


              #7
              Cowpux,

              Correct, you cannot use Enter Orders from the managed approach in the un-managed approach, only SubmitOrder().
              Cal H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Shansen, 08-30-2019, 10:18 PM
              24 responses
              942 views
              0 likes
              Last Post spwizard  
              Started by Max238, Today, 01:28 AM
              0 responses
              9 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by rocketman7, Today, 01:00 AM
              0 responses
              4 views
              0 likes
              Last Post rocketman7  
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              28 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              33 views
              0 likes
              Last Post wzgy0920  
              Working...
              X