Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry doesn't seem to be working

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

    BarsSinceEntry doesn't seem to be working

    I'm trying to enter Long1 if Close is > EMA20 then
    I want to check every 5 bars from Last Entry and if position is above EMA20, if position is in profit, and EMA200 is 6.5% > EMA20, I add another Long position. I'm using
    BarsSinceEntry("LastSignalName") > 5 but it is not working.

    From the screenshot, I have position Long3 &Long4 entering before Long2 and only 1 bar after Long1.

    Here is my code:

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if ((BarsSinceExit() > 2 || BarsSinceExit() == -1)
    && Close[BarsAgo0] >= EMA(EMA200)[BarsAgo0]
    && Close[BarsAgo0] >= EMA(EMA20)[BarsAgo0]
    && Variable1 == 0
    && (EMA(EMA200)[BarsAgo0]) * (1 + 6.5) > EMA(EMA20)[BarsAgo0])
    {
    EnterLong(Quantity1, "Long1");
    SetStopLoss("Long1", CalculationMode.Percent, StopPerc, false);
    Variable1 = 1;
    }

    // Condition set 2
    if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0
    && BarsSinceEntry("Long1") > 5
    && Close[BarsAgo0] > EMA(EMA20)[BarsAgo0]
    && (EMA(EMA200)[BarsAgo0]) * (1 + 6.5) > EMA(EMA20)[BarsAgo0]
    && Variable2 == 0)
    {
    EnterLong(Quantity2, "Long2");
    SetStopLoss("Long2", CalculationMode.Percent, StopPerc, false);
    Variable2 = 1;
    }

    // Condition set 3
    if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0
    && BarsSinceEntry("Long2") > 5
    && Close[BarsAgo0] > EMA(EMA20)[BarsAgo0]
    && (EMA(EMA200)[BarsAgo0]) * (1 + 6.5) > EMA(EMA20)[BarsAgo0]
    && Variable3 == 0)
    {
    EnterLong(Quantity2, "Long3");
    SetStopLoss("Long3", CalculationMode.Percent, StopPerc, false);
    Variable3 = 1;
    }

    // Condition set 4
    if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0
    && BarsSinceEntry("Long3") > 5
    && Close[BarsAgo0] > EMA(EMA20)[BarsAgo0]
    && (EMA(EMA200)[BarsAgo0]) * (1 + 6.5) > EMA(EMA20)[BarsAgo0]
    && Variable4 == 0)
    {
    EnterLong(Quantity2, "Long4");
    SetStopLoss("Long5", CalculationMode.Percent, StopPerc, false);
    Variable4 = 1;
    }
    Attached Files

    #2
    Hi John, from the screenshot it seems to be working as per the code, you get the Long2 definitely only when you conditions are valid and you are 5 bars past the Long1 you check for? You might want to introduce additional bool flags / variables to ensure the entries could only occur in your expected sequence?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      But why long3 and long4 are entering before long2?
      I have it: barssinceentry(last signal) set so that
      It will enter only after previous long entry.
      Any thoughts on why this is happening?

      Comment


        #4
        I would expect the BarsSinceEntry to be still valid, i.e. > 5 in that case since it counts since your last Long3/Long4 signal.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        942 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        4 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        28 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        33 views
        0 likes
        Last Post wzgy0920  
        Working...
        X