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 judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        57 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        20 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        9 views
        0 likes
        Last Post cre8able  
        Working...
        X