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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        60 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X