CCI level zero not drawing unless ...

 

Hi;

I wrote this code (see below) that will draw in predefined levels in the window where the CCI indicator is loaded (subwindow 1).

Everything works except that the zero level (which must always be draw in) won't draw in unless I have at least one other level defined.

Any suggestions why this is happening?

Thanks

void doCCIlevels()
{

// Define the price levels where you want to draw the horizontal line
double PositiveLevel = CCI_Max;  // pre-calculated in menu settings
double NegativeLevel = CCI_Min;  // pre-calculated in menu settings
double ZeroLevel     = 0;      // this level is always drawn

// Define the subwindow where you want to draw the line (0 for the main chart, 1 for the first subwindow)
int subWindow = 1;

if (DrawLine==0) {    // previously defined to avoid duplication (1 = do not repeat)

   if (PositiveLevel > 0) {
      // Check if the object already exists (to avoid duplicating it)
      if (ObjectCreate("PositiveLine", OBJ_HLINE, subWindow, 0, 0) == 0)
      {
        // If the object already exists, delete it first
        ObjectDelete("PositiveLine");
      }

      // Set the properties of the Positive line
      ObjectSetInteger(0, "PositiveLine", OBJPROP_COLOR, openOrder);      // Line color (you can change this)
      ObjectSetInteger(0, "PositiveLine", OBJPROP_RAY_RIGHT, true);       // Extend the line to the right
      ObjectSetDouble (0, "PositiveLine", OBJPROP_PRICE1, PositiveLevel); // Price level where the line will be drawn

      // Attach the Positive line to the specified subwindow
      ObjectSetInteger(0, "PositiveLine", OBJPROP_SELECTABLE, false);     // Make it not selectable
      ObjectSetInteger(0, "PositiveLine", OBJPROP_SELECTED, false);       // Deselect the object
      ObjectSetInteger(0, "PositiveLine", OBJPROP_STYLE, CCI_Style);      // Line style (you can change this)
      ObjectSetInteger(0, "PositiveLine", OBJPROP_WIDTH, CCI_Width);      // Line width (you can change this)
   }

   if (NegativeLevel < 0) {
      // Check if the object already exists (to avoid duplicating it)
      if (ObjectCreate("NegativeLine", OBJ_HLINE, subWindow, 0, 0) == 0)
      {
         // If the object already exists, delete it first
         ObjectDelete("NegativeLine");
      }

      // Set the properties of the Negative line
      ObjectSetInteger(0, "NegativeLine", OBJPROP_COLOR, closeOrder);      // Line color (you can change this)
      ObjectSetInteger(0, "NegativeLine", OBJPROP_RAY_RIGHT, true);        // Extend the line to the right
      ObjectSetDouble(0, "NegativeLine", OBJPROP_PRICE1, NegativeLevel);   // Price level where the line will be drawn

      // Attach the Negative line to the specified subwindow
      ObjectSetInteger(0, "NegativeLine", OBJPROP_SELECTABLE, false);      // Make it not selectable
      ObjectSetInteger(0, "NegativeLine", OBJPROP_SELECTED, false);        // Deselect the object
      ObjectSetInteger(0, "NegativeLine", OBJPROP_STYLE, CCI_Style);       // Line style (you can change this)
      ObjectSetInteger(0, "NegativeLine", OBJPROP_WIDTH, CCI_Width);       // Line width (you can change this)
   }
   
   // Draw Zero level Line always: Check if the object already exists (to avoid duplicating it
   if (ObjectCreate("ZeroLine", OBJ_HLINE, subWindow, 0, 0) == 0)
   {
      // If the object already exists, delete it first
      ObjectDelete("ZeroLine");
   }

   // Set the properties of the Zero line
   ObjectSetInteger(0, "ZeroLine", OBJPROP_COLOR, clrDarkSlateGray);     // Line color (you can not change this)
   ObjectSetInteger(0, "ZeroLine", OBJPROP_RAY_RIGHT, true);             // Extend the line to the right
   ObjectSetDouble (0, "ZeroLine", OBJPROP_PRICE1, ZeroLevel);           // Price level where the line will be drawn

   // Attach the Zero line to the specified subwindow
   ObjectSetInteger(0, "ZeroLine", OBJPROP_SELECTABLE, false);           // Make it not selectable
   ObjectSetInteger(0, "ZeroLine", OBJPROP_SELECTED, false);             // Deselect the object
   ObjectSetInteger(0, "ZeroLine", OBJPROP_STYLE, CCI_Style);            // Line style (you can change this)
   ObjectSetInteger(0, "ZeroLine", OBJPROP_WIDTH, CCI_Width);            // Line width (you can change this)      

   // Refresh the chart to make the line(s) visible
   ChartRedraw();

   // reintialize drawing variable to avoid re-execution of this function when completed.
   DrawLine=1;

} // end drawline

} // end void doccilevels
 

No need to respond.  Figured it out.  Had a flag parameter backwards.

Reason: