AMi to Telegram repeated messages

Hi All.
How to avoid repeated messages continuously to Telegram (restrict the same message to 1 or 2 times). I have a code which sends 1000+ messages when Buy or short is triggered.

DT = LastValue(DateNum(),1);
TT = LastValue(TimeNum(),1);
BuyVar = StaticVarGetText(Name()+"-Buy");
BuyVar1 = Name()+"-Buy-"+NumToStr(DT,1)+"-"+NumToStr(TT,1)+"-"+NumToStr(GetChartID(),1);
BuyL = LastValue(Buy);
ShortVar = StaticVarGetText(Name()+"-Short");
ShortVar1 = Name()+"-Short-"+NumToStr(DT,1)+"-"+NumToStr(TT,1)+"-"+NumToStr(GetChartID(),1);
ShortL = LastValue(Short);

if (BuyL AND BuyVar != BuyVar1 AND bcount<3)

if (LastValue(ValueWhen(Ref(Buy,0),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"buyAlert")==0 )
Text= ""+LastBuyDateTime+"Pinbar_"+TImeframe+"Buy"+FULLName()+"@"+Buyprice+" SL"+BUYSL;
StaticVarSet(Name()+ GetChartID() + "BuyAlertBar", LastValue(TimeNum()));

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"buyAlertBar"))

StaticVarSet(Name()+GetChartID()+"buyAlert",1); //alert was triggered, no more alerts on this bar
StaticVarSet(Name()+GetChartID()+"buyAlert",0); // new bar formed, and alerts can be trigered.

1 Like