Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strange behaviour inside a Startegy

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

    Strange behaviour inside a Startegy

    Hi All,

    I'm developing an MACD strategy for ES and have strange results.
    When I did some printing for some how the MACD takes the numbers from the ES data.
    Here is the code and the output window prints:

    Code:
    protected override void Initialize()
            {
                macd = MACD(fastLength, slowLength);
                Add(macd);
                  
                CalculateOnBarClose = true;
                SetProfitTarget(profitTarget);
                SetStopLoss(stopLossTarget);
                ClearOutputWindow();
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (CurrentBar < SlowLength)
                    return;
                
                //Calculate only once.
                if (BarsInProgress != 0)
                    return; 
                
                //Output Printing
                    Print("Current Bar:" + CurrentBar.ToString());
                    Print("macd[2]: " + macd[2].ToString("0.00"));
                    Print("macd[1]: " + macd[1].ToString("0.00"));
                    Print("macd[0]: " + macd[0].ToString("0.00"));
                    Print("-------------------------");
    
                //Enter Long position
                if (Math.Abs(macd[2]) > Math.Abs(macd[1]) && Math.Abs(macd[0]) > Math.Abs(macd[1]))
                {
                    EnterLong(1,"");
                }
    And here is the strange output data:
    Current Bar:43
    macd[2]: 2.60
    macd[1]: 2.72
    macd[0]: 2.74
    -------------------------
    Current Bar:44
    macd[2]: 2.72
    macd[1]: 2.74
    macd[0]: 1220.25
    -------------------------
    Current Bar:45
    macd[2]: 2.74
    macd[1]: 1220.25
    macd[0]: 1220.50

    -------------------------
    You get the point?

    Do you know what I'm doing wrong? this bug killing me for hours :-(

    Thanks in advance for any suggestions!

    #2
    Freewind, I tried to write an indicator using your code to test this out, but unfortunately the MACD() initializer did not contain enough parameters to compile. Both the NT6.5 and NT7 help guide list MACD() methods that need a fast value, slow value, and a smooth value - I'm not sure how your script compiled. Can you please export the script via the File -> Utilities -> Export NinjaScript wizard and attach it here so I can test out your version?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin,

      I use a custom indicator, the code I attached is just a sample of the idea but the indicator works fine when it is displayed on the strategy analyzer or on a chart.
      Just when I do the printing and the strategy logic I'm getting the strange data.

      Have you encounter such thing?

      Thanks in advance.

      Comment


        #4
        freewind, I have not encountered such a thing but I would like to test it out and see what could be going on. Will you export your script so we can see this for ourselves?
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

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