Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Executes only one direction

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

    Executes only one direction

    Greetings! I can't understand why simple code doesn't work properly Can you tell me where I made a mistake. The problem - NT8 choose the only one direction and opens only sell or only buy orders. I want it to execute both ways.

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

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (Delta11.Sells[0] > Zero+20)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "1");
    }

    // Set 2
    if (Delta11.Sells[0] < Zero-20)
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "1");
    }

    #2
    Hello Svasud,

    Thanks for your post and welcome to the forums!

    Based on your posted code it would be difficult to say. We suggest adding print statements to your code to print out the values of the variables Delta11.Sells[0] and Zero (I assume Zero is a variable). By printing out the values on a bar by bar basis you will see what these variable values are and can then see why the logic is or is not working and when. The output of Print statements goes to New>Ninjascript output window.

    Here is a link to tips on debugging: https://ninjatrader.com/support/help...script_cod.htm

    If you are using the Strategy Builder then here is a short video that will help walk through constructing a print statement: https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw

    Comment


      #3
      Thank you very much

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      29 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      46 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X