• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting the VMA difference

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

    Plotting the VMA difference

    I have a simple indicator by which I am trying to plot the difference between two VMAs. It compiles perfectly well, but I do not see anything on the chart. I have checked and re-checked the code, but have no clue what is wrong here. Can someone help please?

    All I want to do is to backcolor the chart when the differences between two VMAs is greater than 2.

    protected override void OnBarUpdate()
    {VmaDifference.Set(VMA(34,34)[0]-VMA(500,14)[0]);
    if (VmaDifference[1]<2
    && VmaDifference[0]>=2)
    {
    BackColorAll = Color.Green;
    }
    else if
    (VmaDifference[1]>-2
    && VmaDifference[0]<=-2)
    {
    BackColorAll = Color.Green;
    }
    else
    {
    BackColorAll = Color.Blue;
    }

    #2
    To identify the problem, you would need to post the entire code.

    One possible explanation for the bug is that you try to access VMADifference[1] for the first bar, which is CurrentBar == 0. For this bar VMADifference[1] is not yet defined. You would need to change the code to

    Code:
    protected override void OnBarUpdate()
            {VmaDifference.Set(VMA(34,34)[0]-VMA(500,14)[0]);
    if (CurrentBar < 1)  // line added
       return;   // line added
    if        (VmaDifference[1]<2
                    && VmaDifference[0]>=2)
                {
                    BackColorAll = Color.Green;
                 }
                else if                 
                    (VmaDifference[1]>-2
                    && VmaDifference[0]<=-2)
                {        
                    BackColorAll = Color.Green;
                }
                else 
                {
                   BackColorAll = Color.Blue;
                }
    }
    Also you should not compare the VMADifference to an absolute value such as 2. Such a value maybe correct for a specific instrument and a specific timeframe. But you would need to recode your indicator for use with every different instrument or timeframe. Best compare the VMADifference with the multiple of the average true range.

    Comment


      #3
      pandyav, were you able to resolve with Harry's kind pointer?
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Yes, I was. Thank you for checking in.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rouillard, Today, 03:34 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Tyler  
        Started by mquinteroj, Today, 02:41 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by JPPoulin, Today, 01:32 PM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by bltdavid, Today, 01:09 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by pstrusi, Today, 12:50 PM
        2 responses
        8 views
        0 likes
        Last Post pstrusi
        by pstrusi
         
        Working...
        X