Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Color to change when EMAs are the same

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

    Color to change when EMAs are the same

    HI

    I want a little indicator that if sloping up it plots blue color, if sloping down it plots red and if values are the same its white.
    I think i am doing something wrong with round. It can stay and show 0 for some time because it rounds it and values are fluctuating between 0.01 - 1. How to make it right?
    And also if it displays 0 it would be displayed in border white

    I want to display slope difference in ticks between 2 emas

    Code:
    protected override void OnBarUpdate()
            {
                fastValue = EMA(Close,FastEMA)[0];
                slowValue = EMA(Close,SlowEMA)[0];
                SEMA[0] = fastValue;
                FEMA[0] = slowValue;
                diff = Math.Abs(fastValue - slowValue);
                ang = Math.Round(diff);
                //Print(diff);
                //NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 26) { Size = 50, Bold = true };
                if (slowValue == fastValue)
                Draw.TextFixed(this, "angulation", "this" + ang.ToString(), TextPosition.TopRight, ChartControl.Properties.ChartText, myFont, Brushes.White, Brushes.Transparent, 0);
    
                else if (fastValue > slowValue)
                Draw.TextFixed(this, "angulation", "" + ang.ToString(), TextPosition.TopRight, ChartControl.Properties.ChartText, myFont, Brushes.Blue, Brushes.Transparent, 0);
    
                else
                    Draw.TextFixed(this, "angulation", "" + ang.ToString(), TextPosition.TopRight, ChartControl.Properties.ChartText, myFont, Brushes.OrangeRed, Brushes.Transparent, 0);
    
    
            }​
    Click image for larger version  Name:	image.png Views:	0 Size:	21.8 KB ID:	1237513
    Last edited by tkaboris; 03-01-2023, 07:00 PM.

    #2
    Hello tkaboris,

    Thank you for your post.

    You mentioned, "It can stay and show 0 for some time because it rounds it and values are fluctuating between 0.01 - 1." though I am not sure what you are referring to. Are you referring to the text you are drawing on the chart? I see you have the following print statement commented out:
    //Print(diff);

    I suggest adding additional print statements to verify the values being used. You are not using diff in your Draw.TextFixed methods; it looks like you are using ang. This means you should print the value of ang along with the values for diff, fastValue, and slowValue. Since you want the value to be displayed in a number of ticks, you may prefer to use RoundToTickSize() or RoundDownToTickSize():



    "if it displays 0 it would be displayed in border white"
    To achieve this, you could set a condition to check if the value is 0. You currently have the following:
    Code:
     if (slowValue == fastValue)
    Draw.TextFixed(this, "angulation", "this" + ang.ToString(), TextPosition.TopRight, ChartControl.Properties.ChartText, myFont, Brushes.White, Brushes.Transparent, 0);​
    This condition is checking if slowValue is equal to fastValue. What you could check is if the value for ang is equal to 0:
    Code:
    if (ang == 0)
    Ultimately, I suspect that using print statements to verify the values used in your script will be a helpful tool to debug the behavior you are observing and modify your script so that it behaves exactly how you'd like it to. We have more information about using prints to debug your scripts here:


    Please let us know if we may be of further assistance.

    Comment


      #3
      I need to display the same value from strategy and in indicator

      In my strategy i have this lilne to calcualte difference between two emas
      double emaAngulation = fastEMA[0] - slowEMA[0];
      Print(emaAngulation);


      My Indicator is like this
      fastValue = EMA(Close,FastEMA)[0];
      slowValue = EMA(Close,SlowEMA)[0];
      diff = Math.Abs(fastValue - slowValue) ;
      ang = Math.Round(diff)* TickSize;
      Print(ang);

      Value from indicator is larger then whats from strategy.
      How can I make indicator to display the same angulation number as my strategy both for longs and shorts if its different​
      Attached Files
      Last edited by tkaboris; 03-08-2023, 12:17 PM.

      Comment


        #4
        Hello tkaboris,

        Thank you for your note.

        Do you mean that the values for emaAngulation and ang are different from each other? Based on the snippets here, it looks like they might be calculated differently. What is the difference you are seeing between the two? I am also unsure what you mean "for longs and shorts if its different" - please clarify what difference you are referring to so I may better understand.

        I look forward to your reply.

        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
        331 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
        550 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X