Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reference to colors

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

    Reference to colors

    Hi all,
    I try to develop script, that will sort "peaks" to different levels. Idea is like "small peak Level 1", "biger peak Level 2". Peaks in levels will be connected by lines with different colors. Level 1 red, Level 2 blue, .... I use for this purpose loop FOR and condition IF. It works perfect, but I would like to make it a little bit simple...
    This is example of current solution:

    for(int m = 1; m<10 ; m++)
    {
    if(Test_A <= Test_B && Test_B > Test_C)
    {
    vrcholy[Test_B_ID,3] = m+1;
    if(m==1)
    {
    vrcholy_urovne[0,4] = vrcholy_urovne[0,6];
    vrcholy_urovne[0,5] = vrcholy_urovne[0,7];
    vrcholy_urovne[0,6] = vrcholy[Test_B_ID,1];
    vrcholy_urovne[0,7] = Test_B;

    Draw.Line(this,"lineM" + vrchol_B_ID, false, CurrentBar - Convert.ToInt32(vrcholy_urovne[0,4]),vrcholy_urovne[0,5], CurrentBar - Convert.ToInt32(vrcholy_urovne[0,6]), vrcholy_urovne[0,7], Brushes.Orange, DashStyleHelper.Dot, 2);
    Draw.Dot(this, "X"+CurrentBar+BTAdjust+ m, false,CurrentBar-Convert.ToInt32(vrcholy[Test_B_ID,1]), vrcholy[Test_B_ID,2]+ 5* TickSize , Brushes.Orange);
    }
    if(m==2)
    {
    vrcholy_urovne[0,8] = vrcholy_urovne[0,10];
    vrcholy_urovne[0,9] = vrcholy_urovne[0,11];
    vrcholy_urovne[0,10] = vrcholy[Test_B_ID,1];
    vrcholy_urovne[0,11] = Test_B;

    Draw.Line(this,"lineM2" + vrchol_B_ID, false, CurrentBar - Convert.ToInt32(vrcholy_urovne[0,8]),vrcholy_urovne[0,9], CurrentBar - Convert.ToInt32(vrcholy_urovne[0,10]), vrcholy_urovne[0,11], Brushes.Lime, DashStyleHelper.Dot, 2);
    Draw.Dot(this, "Y"+CurrentBar+BTAdjust+ n, false,CurrentBar-Convert.ToInt32(vrcholy[Test_B_ID,1]), vrcholy[Test_B_ID,2]+ 7 * TickSize , Brushes.Lime);
    }
    if(m==3)
    .....

    What I would like to do . To create public array with ten standard colors:
    Colors [0] = Brushes.Red
    Colors [1] = Brushes.Blue

    ...

    And loop will be changed this way:

    for(int m = 1; m<10 ; m++)
    {
    if(Test_A <= Test_B && Test_B > Test_C)
    {
    vrcholy[Test_B_ID,3] = m+1;

    vrcholy_urovne[0,m*4] = vrcholy_urovne[0,m*4+2];
    vrcholy_urovne[0,m*4+1] = vrcholy_urovne[0,m*4+3];
    vrcholy_urovne[0,m*4+2] = vrcholy[Test_B_ID,1];
    vrcholy_urovne[0,m*4+3] = Test_B;​​
    ​​​​
    Draw.Line(this,"lineM2" + vrchol_B_ID, false, CurrentBar - Convert.ToInt32(vrcholy_urovne[0,8]),vrcholy_urovne[0,9], CurrentBar - Convert.ToInt32(vrcholy_urovne[0,10]), vrcholy_urovne[0,11], Colors [m], DashStyleHelper.Dot, 2);

    Problem is, that I did not find any post or documentation if is it possible to store colors in array, what type of array it should it be,... And if I try to use array Colors in object Draw.Line, I receive error... (Argument 8: cannot convert from "string" to "System.Windows,Media.Brush" ).

    Thanks for your advise and help.
    TOM

    #2
    Hello TOM,

    This would be general C# and not specific to NinjaScript.

    A array of System.Windows.Media.Brush would appear as:

    private System.Windows.Media.Brush[] PeakColors = {
    Brushes.Red,
    Brushes.Blue
    };

    And accessed as an array:

    Print(PeakColors[1].ToString());

    The error you have is stating you are supplying a string. Your code does not show how Colors is declared, but I would guess this not a Brush[] array but is probably a string[] array.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X