Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit code does not work for some unknown reason

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

    Exit code does not work for some unknown reason

    I have multiply exit 'if' statements if price crosses certain points and i'm trying to add a volume trigger as well but for some reason the following code has no affect on my backtesting.


    if (Volume[0] > volumenumber
    && Volume[1] > volumenumber
    && GetCurrentAsk() < MIN (Low, 2)[0])


    {
    ExitLong();
    }
    volumenumber is an interger. As you can see, it should exit my long posiiton if volume over the last 2 bars is higher than a certain level and the ask drops below the lowest low over the last 2 bars. For some reason this has no affect unless I remove the last line. Any ideas?

    Thanks

    Mark

    #2
    Hello Mark,

    In a backtest, Close is used in place of ask price. This may be contributing to what you're seeing.

    To identify what's happening here you will have to debug your strategy to track the variables values.

    Print ("Volume: " + Volume[0] + " VolumeNumber " + volumenumber);
    Print ("Volume1: " + Volume[1] + " VolumeNumber " + volumenumber);

    You may also need to print the current ask and your Min statement as well.

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan - Thanks but where do I put the print instructions in my code and what do they do?

      Comment


        #4
        The link posted at the bottom of my reply can help with the specific approach needed for debugging code.

        Print statements tell you what the values are for variables. It's the first thing you want to do when code isn't behaving the way you expect. You may also consider adding CurrentBar to any print statement so that you can see how the values change per bar.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        649 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        576 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X