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

Strategy creating exit order on next bar after Entry, conditions not met

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

    Strategy creating exit order on next bar after Entry, conditions not met

    Hi,
    I have strategy that works well in Thinkorswim but is not working in Ninjatrader. I have attached my two indicators and the strategy. It seems to enter the long but it immediately closes the long despite the fact that the conditions to exit are not there. So if a rally is going on it keeps entering and exiting.
    Any ideas would be appreciated.

    Here is order code:

    if (BarsInProgress != 0)
    return;
    if (CurrentBars[0] < 2)
    return;
    C1 = Close[0];
    C2 = Close[1];
    t1 = WaddahAttarExplosion1.Histogram1[0];
    t1Prev = WaddahAttarExplosion1.Histogram1[1];
    t1dn = WaddahAttarExplosion1.Histogram2[0];
    ex = WaddahAttarExplosion1.Line1[0];
    Print("T1dn: " + t1dn);
    Print("T1: " + t1);
    Print("EX: " + ex);

    if (t1 > 0 && t1 > ex && t1Prev > 0)
    {
    TrendUp = 1;
    }

    else
    TrendUp = 0;

    if (t1dn > 0 )
    {
    TrendDown = 1;

    }

    else if (t1dn == 0)
    {
    TrendDown = 0;
    }


    if (C1 < (C2*.99962))
    {
    trailStopLoss = 1;
    }

    // BullPower Signal
    BullPower1 = RayBullPower1.Histogram1[0];
    BearPower1 = RayBullPower1.Histogram2[0];

    if (BullPower1 > 1.0)
    {
    BullPowerBuy = 1;
    }
    if (BearPower1 < 0 )
    {
    BullPowerSell = 1;

    }


    if (MACD1.Diff[1] < MACD1.Diff[2] && Close[1] < Close[2] && Close[0] > High[1])
    {
    MacdLow = 1;
    Draw.ArrowUp(this, "BULL", true, 0, Low[0] - TickSize, Brushes.Green);
    }
    if (MACD1.Diff[1] > MACD1.Diff[2] && Close[1] > Close[2] && Close[0] > Low[1])
    {
    MacdHighBear = 1;
    Draw.ArrowDown(this, "BEAR", true, 0, Low[0] - TickSize, Brushes.Red);
    }


    if (TrendUp == 1 && BullPowerBuy == 1 && MacdLow == 1 && TrendDown == 0)
    {
    EnterLong(DefaultQuantity, "@Long");
    }

    if (TrendDown == 1 || BullPowerSell == 1 ||MacdHighBear == 1) //|| (trailStopLoss == 1))
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), @"CloseLong", "");
    }
    Attached Files

    #2
    Hello set2win,

    Thanks for the post.

    In this situation comparing against the other strategy is not going to be super helpful unless you are comparing how the logic in both platforms is executing. From the given information I could suggest to add some Print statements into your logic in both strategies to compare if the logic is actually working similar.

    I am not certain if Thinkorswim has some kind of debugging window that you can use but that would be ideal for this type of question. NinjaScript has an output window that can be used:


    A potential way to debug this further would be to print your exit condition variables to see why thats allowing an exit.

    Code:
    Print(Time[0] + " TrendDown: " + TrendDown + " BullPowerSell: " +BullPowerSell); // for any variables you may use. 
    
    if (TrendDown == 1 || BullPowerSell == 1 ||MacdHighBear == 1) //|| (trailStopLoss == 1))
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), @"CloseLong", "");
    }
    This will help to find out why the exit happened and also if your other logic is similar to what you already have in thinkorswim.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse, I added that and right now the MacdHighBear shows 1 every bar. I removed that condition and it does not exit the next bar. I will have to investigate further as the P/L for this strategy is significantly less than TOS version. I just located an error in the MacdHighBear computation, should have been:
      if (MACD1.Diff[1] > MACD1.Diff[2] && Close[1] > Close[2] && Close[0] < Low[1]) , I had Close[0] > Low[1]
      now we are looking much better. I will revise the zip file if anyone cares to try it out. I m currently testing NQ on Renko bars and 25 tick range. Also this works great in TOS with charting Options in particular but unfortunately Ninjatrader does not chart options at this time.
      Last edited by set2win; 08-25-2020, 01:50 PM.

      Comment


        #4
        Hello set2win,

        Yes checking the logic against the TOS version will be the next step. While you could likely go through with a print and fully debug the NinjaScript code I believe it would be more beneficial to stop here and double check that the way TOS executes your code is identical to what you have going on in NinjaTrader now. I would suggest to avoid comparing the P/L results at this time as there could be other differences between platforms that control that such as how each platform fills orders in simulation or data.

        As long as you know code in NinjaScript is running for the most part the same that will help to move forward though other more specific items like pnl. You could then drill down to each execution to see what is different such as fill prices or placement.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by set2win View Post
          I will revise the zip file if anyone cares to try it out. I m currently testing NQ on Renko bars and 25 tick range.
          Yes, please, I would like to try your updated version.

          Beware back-testing with Renko bars, there be many dragons down that path.

          For Renko, much better testing occurs in real-time using Sim101, or w/Market Replay.

          Comment


            #6
            Originally posted by bltdavid View Post

            Yes, please, I would like to try your updated version.

            Beware back-testing with Renko bars, there be many dragons down that path.

            For Renko, much better testing occurs in real-time using Sim101, or w/Market Replay.
            I have updated the original zip file but you would need to unzip and add the strategy and indicators manually as it does not seem to be working as an assembly.Thanks for the heads up on Renko and backtesting, I did not know. I'm testing in Sim real mode and still seeing good results.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-18-2024, 08:16 AM
            4 responses
            18 views
            0 likes
            Last Post trilliantrader  
            Started by mgco4you, Today, 09:46 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by wzgy0920, Today, 09:53 PM
            0 responses
            9 views
            0 likes
            Last Post wzgy0920  
            Started by Rapine Heihei, Today, 08:19 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 08:25 PM
            0 responses
            10 views
            0 likes
            Last Post Rapine Heihei  
            Working...
            X