MQL4: DRAW TRIANGLE between ZigZag Points

 

Hello,

I want to draw a triangle between 3 ZigZag points. I already have the ZigZag Points. How can I draw the triangle between them?

This is what I got so far:

int start()
   { int n, i;
     double p0, p1, p2, p3, p4, p5;
      i=0;
      while(n<5)
      {
      if(p0>0) {p5=p4; p4=p3; p3=p2; p2=p1; p1=p0; }
      p0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
      if(p0>0) {n+=1; }
      i++;
      }
      
//------------------------------------------------------------------- Drawing Begin
      ObjectDelete("Res");
      ObjectCreate("Res",OBJ_HLINE,0,0,p0);
      ObjectSet("Res",OBJPROP_COLOR,Blue);
      ObjectSet("Res",OBJPROP_WIDTH,4);
      ObjectSet("Res",OBJPROP_RAY,false);
      ObjectSetText("Res","Up & Price_0 "+p0,10,"Times New Roman",Green);

      ObjectDelete("Sup");
      ObjectCreate("Sup",OBJ_HLINE,0,0,p1);
      ObjectSet("Sup",OBJPROP_COLOR,Blue);
      ObjectSet("Sup",OBJPROP_WIDTH,4);
      ObjectSet("Sup",OBJPROP_RAY,false);
      ObjectSetText("Sup","Down & Price_1 "+p1,10,"Times New Roman",Green);
      
      /* MEIN ZEUGS BEGINNT */
      ObjectDelete("Foobar");
      ObjectCreate(0,"Foobar",OBJ_TRIANGLE,0,Time[0],p2,Time[25],p3); // looks like a ball, not a triangle?
      ObjectSetInteger(0,"Foobar",OBJPROP_COLOR,Green);
      ObjectSetInteger(0,"Foobar",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,"Foobar",OBJPROP_WIDTH,400);
      ObjectSetInteger(0,"Foobar",OBJPROP_RAY,false);
     // ObjectSetInteger(0,"Foobar",OBJPROP_FIBOLEVELS,2,6);
     
      /* MEIN ZEUGS ENDEEEE */
     
//------------------------------------------------------------------- Drawing End
   // Comment("Price 0 : "p0,", Price 1 : ",p1," Price 2 : ",p2);
 /*  printf("Price D : "+p0);
   printf("Price C : "+p1);
   printf("Price B : "+p2);
   printf("Price A : "+p3);
   printf("Price X : "+p4);
 */  
   return(0);
  }
//+-------------------------------------------------------------------- expert end function
 
David Vieira Kurz: I want to draw a triangle between 3 ZigZag points. I already have the ZigZag Points. How can I draw the triangle between them?

This is what I got so far:

ObjectCreate(0,"Foobar",OBJ_TRIANGLE,0,Time[0],p2,Time[25],p3); // looks like a ball, not a triangle?
You need three coordinates (price and time.) You save the prices in your p0 .. p5 variables but don't save the corresponding time.
  1. Your first coordinate is (Time[0], p2.) Bogus time.
  2. Your second coordinate is (Time[25],p3.) Bogus time.
  3. Where is your third? Bogus call.
 

Thanks for your answer, @whroeder1.

I could solve the problem by doing following:

static int xxo       =  0;
static int xxo_p0    =  0;
static int xxo_p1    =  0;
...
for (xxo=0;xxo<100;xxo++)
           {
             OHLC = Open[xxo]+","+High[xxo]+","+Low[xxo]+","+Close[xxo]; 
             Foobar = TimeToString(Time[xxo]);
              
                 if(Low[xxo]==p0){
                  xxo_p0 = xxo;
               }
               
                if(High[xxo]==p1)
               { xxo_p1 = xxo;
               }
...
 ObjectDelete("Foobar");
      ObjectCreate(0,"Foobar",OBJ_TRIANGLE,0,Time[xxo_p4],p4,Time[xxo_p3],p3,Time[xxo_p2],p2); // Looks okay now
      ObjectSetInteger(0,"Foobar",OBJPROP_COLOR,Green);
...

Have a nice day,

David

 
Why are you looking for the high/low. You already know the bar index, thus the bar time.
    p0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
 

@whroeder1:

1) "i" is always 0 in my case.

2) I need the High/Low, because I want to draw the triangles on the extremes on the candles. Please apologize if I understand you wrong. 

In the end it shall be a simple way to find Gartley Patterns.

This is how it looks right now:

Looks_right_now

Best Regards,

David

 

David Vieira Kurz: "i" is always 0 in my case.

      i=0;
      while(n<5){
        :
        p0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
        :
        i++;
Absolutely not.
 
You're totally right, @whroeder1. My fault. Sorry.