Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 18:47:29 +0000



[User Discussion] - Heikin-Ashi Custom Colors via ASCIL

View Count: 292

[2024-02-16 15:18:09]
User366743 - Posts: 14
I'm attempting to custom color of Heikin-Ashi bars based on T3-5 and T3-8 cross and their angles being both positive or negative.
Got it about 50% done but struggling when trying to apply the logic of changing the candlesticks drawing style to DRAWSTYLE_COLOR_BAR_HOLLOW.
Any tips will be appreciate (the code compiles but has no effect on the candles). The desired effect of coloring is shown on the picture.

#include "sierrachart.h"
SCDLLName("HA_colors")

SCSFExport scsf_MyStudyHA(SCStudyInterfaceRef sc)
{
  //logging object
  SCString msg;
  //SCInputRef i_T3 = sc.Input[0];
  SCSubgraphRef Subgraph_Open = sc.Subgraph[0]; //OPEN
  SCSubgraphRef Subgraph_High = sc.Subgraph[1]; //HIGH
  SCSubgraphRef Subgraph_Low = sc.Subgraph[2]; //LOW
  SCSubgraphRef Subgraph_Last = sc.Subgraph[3]; // CLOSE
      
  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    sc.GraphName = "HK_Colors";
    //i_T3.Name = "Select T3 Study on main price graph";
    //i_T3.SetChartStudyValues(sc.ChartNumber, 0);

    //sc.GraphDrawType = GDT_CANDLESTICK;
    sc.GraphRegion = 1;
    sc.ValueFormat = VALUEFORMAT_INHERITED;
        
    sc.AutoLoop = 1;
    return;
  }

  
//sc.GetChartArray()
  //get main price graph open and close
  SCFloatArray ORef;
  SCFloatArray CRef;
  sc.GetChartArray(1, SC_OPEN, ORef);
  sc.GetChartArray(1, SC_LAST, CRef);
  int oSize = ORef.GetArraySize();
  int cSize = CRef.GetArraySize();

  //SCFloatArray T3Ref;
  //Study ID as obtained via Input or Study Int# shown in the Studies view ID:16 T3-8, Subgraph array starts with 0 -SG1 has index 0
  //sc.GetStudyArrayUsingID(i_T3.GetStudyID(), 0, T3Ref);
  //sc.GetStudyArrayUsingID(16, 0, T3Ref);

  SCFloatArray T35Ref; //13
  SCFloatArray T38Ref; //16
  sc.GetStudyArrayUsingID(13, 0, T35Ref); //T3-5
  sc.GetStudyArrayUsingID(16, 0, T38Ref); //T3-8


  SCFloatArray T35aRef; //40
  SCFloatArray T38aRef; //39
  sc.GetStudyArrayUsingID(40, 0, T35aRef); //angle of T3-5
  sc.GetStudyArrayUsingID(39, 0, T38aRef); //angle of T3-8


  //get a sudy's supbgraph's values - all values show in log as expected

  if (sc.Index == oSize - 1) {
    msg.Format("Open=%f, Close=%f, T35=%f, T35a=%f, T38=%f, T38a=%f", ORef[sc.Index], CRef[sc.Index], T35Ref[sc.Index], T35aRef[sc.Index], T38Ref[sc.Index], T38aRef[sc.Index]);
    sc.AddMessageToLog(msg, 1);
  }

  //This part does not work yet..
  //process coloring of Heikin-Ashi bars based on T3-5 and T3-8 cross and their angles being both positive or negative

  if (sc.Index <= oSize - 1)
  {
    if(ORef[sc.Index] > CRef[sc.Index]) //open > close
    {
      if (T35Ref[sc.Index] > T38Ref[sc.Index] && T35aRef[sc.Index] > 1 && T38aRef[sc.Index] > 1)
      {
        sc.GraphDrawType = GDT_CANDLESTICK;
        Subgraph_Open.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_Open.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Last.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_Last.PrimaryColor = RGB(0, 255, 0);
        Subgraph_High.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_High.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Low.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_Low.PrimaryColor = RGB(0, 255, 0);

      }
      else
      {
        sc.GraphDrawType = GDT_CANDLESTICK_HOLLOW;
        Subgraph_Open.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_Open.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Last.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_Last.PrimaryColor = RGB(0, 255, 0);
        Subgraph_High.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_High.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Low.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_Low.PrimaryColor = RGB(0, 255, 0);

      }
      
    
    }
    else if (ORef[sc.Index] <= CRef[sc.Index]) // open <= close
    {
      if (T35Ref[sc.Index] < T38Ref[sc.Index] && T35aRef[sc.Index] < -1 && T38aRef[sc.Index] < -1)
      {
        sc.GraphDrawType = GDT_CANDLESTICK;
        Subgraph_Open.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_Open.PrimaryColor = RGB(255, 0, 0);
        Subgraph_Last.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_Last.PrimaryColor = RGB(255, 0, 0);
        Subgraph_High.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_High.PrimaryColor = RGB(255, 0, 0);
        Subgraph_Low.DrawStyle = DRAWSTYLE_COLOR_BAR;
        Subgraph_Low.PrimaryColor = RGB(255, 0, 0);

      } else
      {
        sc.GraphDrawType = GDT_CANDLESTICK_HOLLOW;
        Subgraph_Open.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_Open.PrimaryColor = RGB(255, 0, 0);
        Subgraph_Last.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_Last.PrimaryColor = RGB(255, 0, 0);
        Subgraph_High.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_High.PrimaryColor = RGB(255, 0, 0);
        Subgraph_Low.DrawStyle = DRAWSTYLE_COLOR_BAR_HOLLOW;
        Subgraph_Low.PrimaryColor = RGB(255, 0, 0);
      }


    }



    
  }
  
  


}
imageHA_Coloring.jpg / V - Attached On 2024-02-16 15:15:58 UTC - Size: 96.75 KB - 52 views
[2024-02-18 17:47:15]
User366743 - Posts: 14
OK, I think I have figured this out. It was not very easy or straightforward for me - so I hope this will make it easier for you.
See the attached code..
imageHA_Colors_2.jpg / V - Attached On 2024-02-18 17:43:10 UTC - Size: 418.38 KB - 59 views
Attachment Deleted.
attachmentHA_hcandles.cpp - Attached On 2024-02-18 17:46:19 UTC - Size: 8.17 KB - 271 views

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account