why my code not draw the trendline ?

 

hi guys  i have this code  when i switch in gold in M15  draw the trend line resistence,   if  go in M30  not draw  a trend line resistence

#property copyright "Copyright 2012."
#property link      "stfn77@gmail.com"
#property version   "1.00"
#property description "Automatic trend lines"
#property indicator_chart_window
#property indicator_plots 1
#property indicator_type1 DRAW_NONE
#property indicator_buffers 1

double dummyBuffer[];

string prefix = "AutoTrendZL_";

enum ENUM_LINE_TYPE {
   EXM_EXM,
   EXM_DELTA
};

class CPoint {
   private:
      double price;
      datetime time;
   public:
      CPoint();
      CPoint(const double p, const datetime t);
      ~CPoint() {};
      void setPoint(const double p, const datetime t);
      bool operator==(const CPoint &other) const;
      bool operator!=(const CPoint &other) const;
      void operator=(const CPoint &other);
      double getPrice() const;
      datetime getTime() const;
};

CPoint::CPoint(void) {
   price = 0;
   time = 0;
}

CPoint::CPoint(const double p, const datetime t) {
   price = p;
   time = t;
}

void CPoint::setPoint(const double p, const datetime t) {
   price = p;
   time = t;
}

bool CPoint::operator==(const CPoint &other) const {
   return price == other.price && time == other.time;
}

bool CPoint::operator!=(const CPoint &other) const {
   return !operator==(other);
}

void CPoint::operator=(const CPoint &other) {
   price = other.price;
   time = other.time;
}

double CPoint::getPrice(void) const {
   return(price);
}

datetime CPoint::getTime(void) const {
   return(time);
}

CPoint curLeftSup, curRightSup, curLeftRes, curRightRes, nullPoint;

input ENUM_LINE_TYPE InpLineType = EXM_DELTA;
input int InpLeftExmSide = 10;
input int InpRightExmSide = 3;
input int InpFromCurrent = 3;
input bool InpPrevExmBar = false;
input int InpLinesWidth = 2;
input color InpSupColor = clrOrange;
input color InpResColor = clrMagenta;
input double InpMinPipsDistance = 5.0;
double minPipDistance = InpMinPipsDistance * _Point;
input int MaxSearchDepth = 400;

int minRequiredBars;

int OnInit() {
   minRequiredBars = InpLeftExmSide * 2 + MathMax(InpRightExmSide, InpFromCurrent) * 2;
   SetIndexBuffer(0, dummyBuffer, INDICATOR_DATA);
   return(0);
}

void OnDeinit(const int reason) {
   int totalObjects = ObjectsTotal(0);
   for(int i = totalObjects - 1; i >= 0; i--) {
      string objName = ObjectName(0, i);
      if(StringFind(objName, prefix) == 0) {
         ObjectDelete(0, objName);
      }
   }
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {

   int leftIndex, rightIndex;
   double delta, tmpDelta;

   if (rates_total < minRequiredBars) {
      Print("Not enough data to calculate");
      return(0);
   }

   if (prev_calculated != rates_total) {
      switch (InpLineType) {
         case EXM_DELTA:
         {
            int maxSearchSteps = MaxSearchDepth;
            int searchStep = 0;
            int tempLeftIndex;

            rightIndex = rates_total - InpFromCurrent - 2;
            leftIndex = rates_total - InpLeftExmSide - 2;
            tempLeftIndex = leftIndex;

            Print("--- Inizio ricerca minimo supporto sinistro ---");
            while (searchStep < maxSearchSteps && leftIndex > minRequiredBars) {
               if (isLowestLow(leftIndex, InpLeftExmSide, low)) {
                  double priceDiff = MathAbs(low[leftIndex] - low[rightIndex]);
                  if (low[leftIndex] <= low[rightIndex] && priceDiff >= minPipDistance) {
                     break;
                  }
               }
               leftIndex--;
               searchStep++;
            }
            if (leftIndex <= minRequiredBars || searchStep == maxSearchSteps) {
               leftIndex = tempLeftIndex;
            }

            curLeftSup.setPoint(low[leftIndex], time[leftIndex]);
            curRightSup.setPoint(low[rightIndex], time[rightIndex]);

            //--- Resistance Left Point con MaxSearchDepth
int searchResStep = 0;
leftIndex = rates_total - InpLeftExmSide - 2;
int tempLeftResIndex = leftIndex;

            
while (searchResStep < maxSearchSteps && leftIndex > minRequiredBars) {
    if (isHighestHigh(leftIndex, InpLeftExmSide, high)) {
        break;
    }
    leftIndex--;
    searchResStep++;
}

// fallback: massimo assoluto se massimo locale non trovato
if (leftIndex <= minRequiredBars || searchResStep == maxSearchSteps) {
    Print("Nessun massimo locale trovato, cerco massimo assoluto come fallback");

    double maxHigh = -DBL_MAX;
    int maxIndex = -1;

    for (int i = rates_total - MaxSearchDepth; i > minRequiredBars; i--) {
        if (high[i] > maxHigh) {
            maxHigh = high[i];
            maxIndex = i;
        }
    }
Print(" MaxHigh scelto: ", maxHigh, " @ index ", maxIndex, " time ", TimeToString(time[maxIndex]));

    if (maxIndex != -1) {
        leftIndex = maxIndex;
        Print("Usato massimo assoluto a index ", leftIndex, " con high = ", maxHigh);
    } else {
        leftIndex = tempLeftResIndex;
        Print("Fallback fallito, uso valore iniziale come default");
    }
}

            
            
            curLeftRes.setPoint(high[leftIndex], time[leftIndex]);

Print("CurLeftRes set: prezzo=", high[leftIndex], " time=", TimeToString(time[leftIndex], TIME_DATE | TIME_MINUTES));

            //--- Resistance Right Point con MaxSearchDepth
            rightIndex = rates_total - InpFromCurrent - 2;
            int tmpRightResIndex = rightIndex;
            searchStep = 0;
            delta = (high[leftIndex] - high[rightIndex]) / (rightIndex - leftIndex);
            if (!InpPrevExmBar) leftIndex += 1;
            for (int tmpIndex = rightIndex - 1; tmpIndex > leftIndex && searchStep < maxSearchSteps; tmpIndex--) {
               tmpDelta = (curLeftRes.getPrice() - high[tmpIndex]) / (tmpIndex - leftIndex);
               if (tmpDelta < delta) {
                  delta = tmpDelta;
                  tmpRightResIndex = tmpIndex;
               }
               searchStep++;
            }
            curRightRes.setPoint(high[tmpRightResIndex], time[tmpRightResIndex]);
            Print("CurRightRes set: prezzo=", high[tmpRightResIndex], " time=", TimeToString(time[tmpRightResIndex], TIME_DATE | TIME_MINUTES));
         }
         break;

         case EXM_EXM:
         default:
            rightIndex = rates_total - InpRightExmSide - 2;
            for (; !isLowestLow(rightIndex, InpRightExmSide, low) && rightIndex > minRequiredBars; rightIndex--);
            curRightSup.setPoint(low[rightIndex], time[rightIndex]);

            leftIndex = rightIndex - InpRightExmSide;
            for (; !isLowestLow(leftIndex, InpLeftExmSide, low) && leftIndex > minRequiredBars; leftIndex--);
            curLeftSup.setPoint(low[leftIndex], time[leftIndex]);

            rightIndex = rates_total - InpRightExmSide - 2;
            for (; !isHighestHigh(rightIndex, InpRightExmSide, high) && rightIndex > minRequiredBars; rightIndex--);
            curRightRes.setPoint(high[rightIndex], time[rightIndex]);

            leftIndex = rightIndex - InpRightExmSide;
            for (; !isHighestHigh(leftIndex, InpLeftExmSide, high) && leftIndex > minRequiredBars; leftIndex--);
            curLeftRes.setPoint(high[leftIndex], time[leftIndex]);
         break;
      }

      DeleteObjects(prefix);

      double pipDistance = MathAbs(curRightSup.getPrice() - curLeftSup.getPrice()) / _Point;
      if (curRightSup.getPrice() >= curLeftSup.getPrice() && pipDistance >= minPipDistance) {
         ObjectCreate(0, prefix + "Support", OBJ_TREND, 0,
                      curLeftSup.getTime(), curLeftSup.getPrice(),
                      curRightSup.getTime(), curRightSup.getPrice());
         ObjectSetInteger(0, prefix + "Support", OBJPROP_COLOR, InpSupColor);
         ObjectSetInteger(0, prefix + "Support", OBJPROP_WIDTH, InpLinesWidth);
         ObjectSetInteger(0, prefix + "Support", OBJPROP_RAY_RIGHT, true);
         ObjectSetInteger(0, prefix + "Support", OBJPROP_SELECTABLE, true);
         ObjectSetInteger(0, prefix + "Support", OBJPROP_SELECTED, false);
      }

      double pipDistanceRes = MathAbs(curLeftRes.getPrice() - curRightRes.getPrice()) / _Point;
      
      Print("Controllo disegno resistenza: LeftRes=", curLeftRes.getPrice(),
      " RightRes=", curRightRes.getPrice(),
      " pipDistanceRes=", pipDistanceRes,
      " minPipDistance=", minPipDistance);

      
      if (curLeftRes.getPrice() >= curRightRes.getPrice() && pipDistanceRes >= minPipDistance) {
         ObjectCreate(0, prefix + "Resistance", OBJ_TREND, 0,
                      curLeftRes.getTime(), curLeftRes.getPrice(),
                      curRightRes.getTime(), curRightRes.getPrice());
         ObjectSetInteger(0, prefix + "Resistance", OBJPROP_COLOR, InpResColor);
         ObjectSetInteger(0, prefix + "Resistance", OBJPROP_WIDTH, InpLinesWidth);
         ObjectSetInteger(0, prefix + "Resistance", OBJPROP_RAY_RIGHT, true);
         ObjectSetInteger(0, prefix + "Resistance", OBJPROP_SELECTABLE, true);
         ObjectSetInteger(0, prefix + "Resistance", OBJPROP_SELECTED, false);
      } else {
   Print(" Condizione NON soddisfatta per la resistenza. Non viene disegnata.");
}

      datetime currentTime = time[0];
      double alertRange = 5 * _Point;

      double supportPriceNow = GetTrendlinePriceAt(
         curLeftSup.getTime(), curLeftSup.getPrice(),
         curRightSup.getTime(), curRightSup.getPrice(),
         currentTime);

      double resistancePriceNow = GetTrendlinePriceAt(
         curLeftRes.getTime(), curLeftRes.getPrice(),
         curRightRes.getTime(), curRightRes.getPrice(),
         currentTime);

      if (close[0] <= supportPriceNow + alertRange) {
         Alert("[ALERT] Prezzo vicino o sotto al supporto. Close: ", DoubleToString(close[0], _Digits), " Support: ", DoubleToString(supportPriceNow, _Digits));
      }

      if (close[0] >= resistancePriceNow - alertRange) {
         Alert("[ALERT] Prezzo vicino o sopra alla resistenza. Close: ", DoubleToString(close[0], _Digits), " Resistance: ", DoubleToString(resistancePriceNow, _Digits));
      }
   }
   return(rates_total);
}

bool isLowestLow(int index, int sideBars, const double &low[]) {
   double currentLow = low[index];
   for (int i = index - sideBars; i <= index + sideBars; i++) {
      if (i < 0 || i >= ArraySize(low)) continue;
      if (i == index) continue;
      if (low[i] <= currentLow) {
         return false;
      }
   }
   return true;
}

bool isHighestHigh(int index, int sideBars, const double &high[]) {
   double currentHigh = high[index];
   for (int i = index - sideBars; i <= index + sideBars; i++) {
      if (i < 0 || i >= ArraySize(high)) continue;
      if (i == index) continue;
      if (high[i] >= currentHigh) {
         return false;
      }
   }
   return true;
}

void DeleteObjects(string prefix) {
   int total = ObjectsTotal(0);
   for (int i = total - 1; i >= 0; i--) {
      string objName = ObjectName(0, i);
      if (StringFind(objName, prefix) == 0) {
         ObjectDelete(0, objName);
      }
   }
}

double GetTrendlinePriceAt(datetime t1, double p1, datetime t2, double p2, datetime t) {
   if (t2 == t1) return p2;
   double slope = (p2 - p1) / (t2 - t1);
   return p1 + slope * (t - t1);
}
Files:
Untitled.jpg  98 kb
2.jpg  103 kb