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

Orders entered using Calculated Bands do not enter correctly.

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

    Orders entered using Calculated Bands do not enter correctly.

    This is the strategy that does not work correctly. I think it has something to do with the using the variables as conditions to enter orders. I have used print statements to be sure that the bands calculate correctly and they do. I think maybe I'm not using the correct type of variable or something. Can someone see the flaw?

    Thanks.


    protected override void Initialize()

    {

    CalculateOnBarClose = true;
    }

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

    {

    {
    // Use this code to setup the upper and lower bands
    // Offset
    double offset = ATR(14)[0] * bandFactor;
    // Lower Band
    double Variable6 = SMA(14)[0] - offset;
    // Upper Band
    double Variable7 = SMA(14)[0] + offset;

    Print("offset = " + offset.ToString());

    }



    {


    {
    if (BarsInProgress == 0)
    {


    // Condition set 1 (Long Entries)
    if (Close[0] >= Open[0]
    && Close[0] >= Variable6
    && Low[1] <= Variable6)

    {
    EnterLong(DefaultQuantity, "");

    }

    #2
    If you mean that EnterLong() never issues a market order then it is likely since it is never called...your code never reaches it. Print out the data in the condition required to call the EnterLong() method to see what values are contained in the variables and work back from there.
    RayNinjaTrader Customer Service

    Comment


      #3
      In my opinion, you should put your band calculation logic into an indicator and do an Add( ) in your Initialize, you'd be able to see the bands on the chart and it would be obvious to you what is happening. If you don't want to do that, for the time being you can just do:

      DrawDot("var6"+CurrentBar, 0, Variable6, Color.Blue);
      DrawDot("var7"+CurrentBar, 0, Variable7, Color.Yellow);

      right after your calculations and again, it should make it easy for you to figure out.

      Comment


        #4
        I performed the print and confirm that the calcs work. I'll keep trying Ray.

        Pete,

        Thanks for the code! I will try to do an indicator. I tried to do the draw statements but they locked my NT up 2 times.

        Thanks Again.

        dendy.

        Comment


          #5
          Thanks again Pete,

          Your suggestion works great. Make the indicator and then use the add command to see what's happening. The orders also work correctly now.

          Have a good one...........

          dendy.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Conceptzx, 10-11-2022, 06:38 AM
          3 responses
          60 views
          0 likes
          Last Post NinjaTrader_SeanH  
          Started by f.saeidi, Today, 01:32 PM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by mmckinnm, Today, 01:34 PM
          0 responses
          3 views
          0 likes
          Last Post mmckinnm  
          Started by traderqz, Today, 12:06 AM
          9 responses
          16 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by kevinenergy, 02-17-2023, 12:42 PM
          117 responses
          2,766 views
          1 like
          Last Post jculp
          by jculp
           
          Working...
          X