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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      63 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      35 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      54 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      61 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      48 views
      0 likes
      Last Post CarlTrading  
      Working...
      X