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

BarsSinceExitExecution Problem Live

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

    BarsSinceExitExecution Problem Live

    Hi!

    I have a problem with barssinceexitexecution when trading live. If the last trade was negative and the last exit was a stop loss, I want the strategy to do nothing for the next X bars.

    When doing this in the strategy analyzer, it works perfectly fine in the backtest and it skips the next X bars. However, when trading live the strategy seems to ignore that rule. So the strategy enters a long position immediately after a Stop loss exit because the entry CONDITION is true even though it shouldn't do anything for the next X bars. Can anyone help me here?

    Here is the simplified code:

    {

    /// STOPLOSS

    SetStopLoss(CalculationMode.Percent, Stop);

    if (IsFlat)
    {

    //// LONG TRADES

    if (CONDITION)
    {

    if (SystemPerformance.AllTrades.Count <= 0)
    EnterLong(size, "Buy");

    else if (SystemPerformance.AllTrades.Count > 0)
    {
    Trade LastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];

    if (LastTrade.ProfitCurrency < 0 && BarsSinceExitExecution("Stop loss") <= BarsSinceStopLoss)
    return;
    else
    EnterLong(size, "Buy");
    }
    }
    }

    //// EXIT TRADES

    if (CONDITION)
    ExitLong();

    }

    Thanks in advance!

    #2
    Hello KirkHammett,

    I would recommend you use prints to find what is causing the condition to evaluate as true.

    Below is a public link to a forum post that discusses using prints to understand behavior.
    http://ninjatrader.com/support/forum...979#post510979

    What is the time?
    What is the value of LastTrade.ProfitCurrency?
    What is the value of BarsSinceExitExecution("Stop loss")?
    What is the value of BarsSinceStopLoss?


    Your description sounds like you are expecting the condition to be false for long order to be submitted:
    So the strategy enters a long position immediately after a Stop loss exit because the entry CONDITION is true even though it shouldn't do anything for the next X bars.
    If the condition is false the long order will be submitted. If the condition is true, the script will do nothing..

    Which are you wanting to happen when the condition is true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your response!

      I used prints when backtesting and everything worked well. Using Print Statement when trading live would take me probably some weeks to wait for a real trade to occur. I thought maybe there is someone who had these kind of problems and can help me out.

      When my CONDITION 1 (let's say a simple crossover condition) is true I want it to check what was the last trade: If the last trade was a Stop loss, dont do anything for X bars. If the last trade was not a Stop loss, go long. This works perfectly fine when backtesting.

      But when trading live, it seems like the strategy doesn't recognize the last Stop loss trade. So the strategy exits somewhere within a 15min Bar and on the Close of the same Bar the strategy just enters long again (I have Calculate on Bar Close). Possible explanation: When the strategy calculates on BarClose (and therefore enters long) it doesn't recognize the Stop loss trade because it occured within that Bar and not at least one Bar before?

      Please see my simplified code in my first post. Maybe it gets a bit clearer then.

      Thanks in advance!

      Comment


        #4
        Hello KirkHammett,

        Unfortunately, I am not able to see what the values of the variables are from the provided code.

        The values evaluating will be why the condition is true or false and this information is not included with your posts.

        I've tested printing BarsSinceExitExecution("Stop loss") after an order is closed with SetStopLoss() on my end and I am finding this is returning a proper value.


        Are you unable to use Playback at a fast speed to test the script?
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Aviram Y, Today, 05:29 AM
        0 responses
        1 view
        0 likes
        Last Post Aviram Y  
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        6 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        216 views
        1 like
        Last Post PaulMohn  
        Working...
        X