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

having trouble with variables

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

    having trouble with variables

    can anyone tell me what I'm doing wrong here? if I remove the line of code that changes HigherHigh1 to the current swing price (bold) it works and the strategy goes long. However as it stands it will not go long the way its written.



    HigherHigh1 = 999;

    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    Swing1 = Swing(Close, 5);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((Swing1.SwingHigh[0] > 0)
    && (HigherHigh1 == 999))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    HigherHigh1 = Swing1.SwingHigh[0];
    }


    #2
    Hello cglancy,

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.
    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    I am happy to assist you with analyzing the output from the output window.

    Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a forum post that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.
    https://ninjatrader.com/support/foru...121#post791121


    Your condition is:
    if ((Swing1.SwingHigh[0] > 0) && (HigherHigh1 == 999))

    Make a print for this.

    Print(string.Format("{0} | Swing1.SwingHigh[0]: {1} > 0 && HigherHigh1: {2} == 999", Time[0], Swing1.SwingHigh[0], HigherHigh1));

    Save the output to a text file and attach this to your next post.

    If you are using the Strategy Builder, add the prints in the strategy builder. See the 'Debugging using prints with the Strategy Builder' video in the forum post linked above.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Graci117, Today, 09:02 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by ETFVoyageur, Today, 07:55 PM
    0 responses
    7 views
    0 likes
    Last Post ETFVoyageur  
    Started by janio973, Today, 07:24 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by aligator, 01-06-2022, 12:14 PM
    4 responses
    246 views
    0 likes
    Last Post john_44573  
    Started by reynoldsn, Today, 05:56 PM
    0 responses
    14 views
    0 likes
    Last Post reynoldsn  
    Working...
    X