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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      55 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      142 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      160 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      96 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      276 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X