TouchMedia

 

Hi guys, I did this function "TouchMedia ()" I would like it to work in the following way:

1) Buy Condition: when the average "touches" the lower shadow of the candle "n" and therefore at the candle "n + 1" should recall the function “AllertForBuy” then draw a green line ONLY on the candle " n + 1 ";

2)Sell Condition: when the average "touches" the upper shadow of the candle "n" and therefore to the candle "n + 1" should recall the function "AllertForSell " then draw a red line ONLY on the candle" n + 1 ";

 

and not how it works now because it makes a series of red and green lines (see the photos in attachment).

int Toccomedia()
{
   
   double Ima = iMA(NULL, 0, mediaPeriod, 0, typeMA, PRICE_CLOSE, 0);
   
   if (Low[1] < Ima && Open[1] > Ima &&  Low[0] > Ima && Open[0] > Ima)
   {
      AllertForBuy();
      return +1;
   }

   if (Low[1] < Ima && Open[1] > Ima &&  Low[0] < Ima && Open[0] < Ima)
   {
      AllertForSell();
      return -1;
   }
   
   return 0;
}   
     
void AllertForBuy()
{
 ObjectCreate(ChartID(),IntegerToString(Time[0],0,0),OBJ_VLINE,0,Time[0],0);
 ObjectSetInteger(ChartID(),IntegerToString(Time[0],0,0),OBJPROP_COLOR,clrDarkGreen);
// Alert("Teo_CI rialzista su "+Symbol()+" a TF "+IntegerToString(Period(),0,0));
}

void AllertForSell()
{
 ObjectCreate(ChartID(),IntegerToString(Time[0],0,0),OBJ_VLINE,0,Time[0],0);
 ObjectSetInteger(ChartID(),IntegerToString(Time[0],0,0),OBJPROP_COLOR,clrDarkRed);
 //Alert("Teo_CI ribassista su "+Symbol()+" a TF "+IntegerToString(Period(),0,0));
}
 

Hello friend,

Maybe use ObjectDelete()

 
GrumpyDuckMan:

Hello friend,

Maybe use ObjectDelete()

I've seen your solution, the problem is not so much that I draw the lines, but that draws them continuously, in fact, it should draw the red line ONLY when the sell condition happens, and the green line ONLY when the buy condition occurs, NOT always continuously at every tick.

Reason: