Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Porgramming a dataseries for a flag in a strategy

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

    Porgramming a dataseries for a flag in a strategy

    Hello all,

    Background: I am coding a strategy with multiplpe "flags". Basically dataseries with values of 0, 1, or -1 indicating if a condition is true false.

    The strategy is coded with onbarupdate method. however i want the dataseries flags to base their calculations on the value of indicators at the close of the previous bar, and that calculation should occur on the first tick of the current bar.

    any example i have been playing with is my macd flag. see below:
    (FlagMACDMACD dataseries is set up and working)

    if (FirstTickOfBar)
    {
    //if (Rising(MACD(Median,3,10,16).Avg))
    if (MACD(Median,3,10,16).Avg[1] > MACD(Median,3,10,16).Avg[2])
    {
    //if (Rising(MACD(Median,3,10,16).Default))
    if (MACD(Median,3,10,16).Default[1] > MACD(Median,3,10,16).Default[2])
    {
    FlagMACDMACD.Set(1);
    }
    else
    {
    FlagMACDMACD.Set(0.5);
    }
    }
    }

    if (FirstTickOfBar)
    {
    //if (Falling(MACD(Median,3,10,16).Avg))
    if (MACD(Median,3,10,16).Avg[1] < MACD(Median,3,10,16).Avg[2])
    {
    //if (Falling(MACD(Median,3,10,16).Default))
    if (MACD(Median,3,10,16).Default[1] < MACD(Median,3,10,16).Default[2])
    {
    FlagMACDMACD.Set(-1);
    }
    else
    {
    FlagMACDMACD.Set(-0.5);
    }
    }
    }

    In above example I want a dataseries to have a value of 1 if both the avg and default plots of the macd are rising over the previous bar and minus 1 if falling.

    Now my problem is with this code is that the value (as displayed in the output window by a print(FlagMACDMACD) statement shows the value updating more than on the open of each bar. I have played for hours trying to work this out so would sincerely appreciate the help of one of the gurus.

    Thanks again guys. What a night on the markets eh!
    Last edited by raz0rback; 09-29-2008, 07:45 PM.

    #2
    I think i have solved this problem with using a combo of the barsinprogress and firsttickofbar functions.

    Comment


      #3
      Hello,

      OK, repost if you find it is not resolved.
      DenNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X