mmsknecht Posted October 23, 2013 Report Posted October 23, 2013 Hallo Zusammen, ich verwende beim traden auch den „SuperTrend“ Indikator und versuche einen Alarm einzubauen, wenn ein Signal wechselt: z.B. Grüne Linie zu Roter Linie oder Rote Line zu Grüner Linie. Leider bekomme ich es nicht hin dass beim Richtungswechsel einmal die „alert.wav“ ausgelöst wird. Könnt ihr mir weiterhelfen? Danke vorab //SuperTrend Indikator #property indicator_chart_window #property indicator_color1 Lime #property indicator_color2 Red #property indicator_width1 2 #property indicator_width2 2 #property indicator_buffers 2 double TrendUp[], TrendDown[]; int changeOfTrend; extern int Nbr_Periods = 10; extern double Multiplier = 3.0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexBuffer(0, TrendUp); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(0, "Trend Up"); SetIndexBuffer(1, TrendDown); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(1, "Trend Down"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, flag, flagh, trend[5000]; double up[5000], dn[5000], medianPrice, atr; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //Print(limit); //---- for (i = Bars; i >= 0; i--) { TrendUp[i] = EMPTY_VALUE; TrendDown[i] = EMPTY_VALUE; atr = iATR(NULL, 0, Nbr_Periods, i); //Print("atr: "+atr[i]); medianPrice = (High[i]+Low[i])/2; //Print("medianPrice: "+medianPrice[i]); up[i]=medianPrice+(Multiplier*atr); //Print("up: "+up[i]); dn[i]=medianPrice-(Multiplier*atr); //Print("dn: "+dn[i]); trend[i]=1; if (Close[i]>up[i+1]) { trend[i]=1; if (trend[i+1] == -1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (Close[i]<dn[i+1]) { trend[i]=-1; if (trend[i+1] == 1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (trend[i+1]==1) { trend[i]=1; changeOfTrend = 0; } else if (trend[i+1]==-1) { trend[i]=-1; changeOfTrend = 0; } if (trend[i]<0 && trend[i+1]>0) { flag=1; //Print("flag: "+flag); } else { flag=0; //Print("flagh: "+flag); } if (trend[i]>0 && trend[i+1]<0) { flagh=1; //Print("flagh: "+flagh); } else { flagh=0; //Print("flagh: "+flagh); } if (trend[i]>0 && dn[i]<dn[i+1]) dn[i]=dn[i+1]; if (trend[i]<0 && up[i]>up[i+1]) up[i]=up[i+1]; if (flag==1) up[i]=medianPrice+(Multiplier*atr); if (flagh==1) dn[i]=medianPrice-(Multiplier*atr); //-- Draw the indicator if (trend[i]==1) { TrendUp[i]=dn[i]; if (changeOfTrend == 1) { TrendUp[i+1] = TrendDown[i+1]; changeOfTrend = 0; } } else if (trend[i]==-1) { TrendDown[i]=up[i]; if (changeOfTrend == 1) { TrendDown[i+1] = TrendUp[i+1]; changeOfTrend = 0; } } } WindowRedraw(); //---- return(0); } //+------------------------------------------------------------------+
Der Wolf Posted October 23, 2013 Report Posted October 23, 2013 if (changeOfTrend == 1) { ... PlaySound("alert.wav") ... } 2
mmsknecht Posted October 23, 2013 Author Report Posted October 23, 2013 Danke Wolf, wenn ich den alert allerdings an diese Stelle einbau, klingelt er permanent!? //-- Draw the indicator if (trend[i]==1) { TrendUp[i]=dn[i]; if (changeOfTrend == 1) { TrendUp[i+1] = TrendDown[i+1]; PlaySound("alert.wav"); changeOfTrend = 0; } } else if (trend[i]==-1) { TrendDown[i]=up[i]; if (changeOfTrend == 1) { TrendDown[i+1] = TrendUp[i+1]; PlaySound("alert.wav"); changeOfTrend = 0; } } } WindowRedraw(); //---- return(0); } //+------------------------------------------------------------------+
Der Wolf Posted October 23, 2013 Report Posted October 23, 2013 Bitte, gerne. Diese Stellen werden nur bei Trendwechsel aufgerufen, der Sound sollte also nur einmalig beim Trendwechsel aufgerufen werden.Zuerst wird ja ChangeOfTrend auf 1 abgefragt und danach auf 0 gesetzt. Sollte ChangeOfTrend beim nächsten Tick wieder auf 1 gesezt werden, dann stimmt was an der Logik vom Supertrend-Indikator nicht. 1
cxalgo Posted October 23, 2013 Report Posted October 23, 2013 ist ja auch kein Wunder, weil 99% aller "SuperTrend"-Indis repainten ab H1 eventl. sinnvoll, aber der lag ist dann doch zu heftig für ein "schönes" Signal
mmsknecht Posted October 23, 2013 Author Report Posted October 23, 2013 (edited) Also wenn er z.B. im M5 ein neues Signal produziert, kommt der alert mit jedem Tick und das fünf Minuten lang? Ich weiß nicht, dass hört sich bei mir irgendwie anders an. Teste es mal auf kurz auf dem M1, bei mir brummen da nur die Boxen, aber kein alert.wav? #property indicator_chart_window #property indicator_color1 Lime #property indicator_color2 Red #property indicator_width1 2 #property indicator_width2 2 #property indicator_buffers 2 double TrendUp[], TrendDown[]; int changeOfTrend; extern int Nbr_Periods = 10; extern double Multiplier = 3.0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexBuffer(0, TrendUp); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(0, "Trend Up"); SetIndexBuffer(1, TrendDown); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(1, "Trend Down"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, flag, flagh, trend[5000]; double up[5000], dn[5000], medianPrice, atr; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //Print(limit); //---- for (i = Bars; i >= 0; i--) { TrendUp[i] = EMPTY_VALUE; TrendDown[i] = EMPTY_VALUE; atr = iATR(NULL, 0, Nbr_Periods, i); //Print("atr: "+atr[i]); medianPrice = (High[i]+Low[i])/2; //Print("medianPrice: "+medianPrice[i]); up[i]=medianPrice+(Multiplier*atr); //Print("up: "+up[i]); dn[i]=medianPrice-(Multiplier*atr); //Print("dn: "+dn[i]); trend[i]=1; if (Close[i]>up[i+1]) { trend[i]=1; if (trend[i+1] == -1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (Close[i]<dn[i+1]) { trend[i]=-1; if (trend[i+1] == 1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (trend[i+1]==1) { trend[i]=1; changeOfTrend = 0; } else if (trend[i+1]==-1) { trend[i]=-1; changeOfTrend = 0; } if (trend[i]<0 && trend[i+1]>0) { flag=1; //Print("flag: "+flag); } else { flag=0; //Print("flagh: "+flag); } if (trend[i]>0 && trend[i+1]<0) { flagh=1; //Print("flagh: "+flagh); } else { flagh=0; //Print("flagh: "+flagh); } if (trend[i]>0 && dn[i]<dn[i+1]) dn[i]=dn[i+1]; if (trend[i]<0 && up[i]>up[i+1]) up[i]=up[i+1]; if (flag==1) up[i]=medianPrice+(Multiplier*atr); if (flagh==1) dn[i]=medianPrice-(Multiplier*atr); //-- Draw the indicator if (trend[i]==1) { TrendUp[i]=dn[i]; if (changeOfTrend == 1) { TrendUp[i+1] = TrendDown[i+1]; PlaySound("alert.wav"); changeOfTrend = 0; } } else if (trend[i]==-1) { TrendDown[i]=up[i]; if (changeOfTrend == 1) { TrendDown[i+1] = TrendUp[i+1]; PlaySound("alert.wav"); changeOfTrend = 0; } } } WindowRedraw(); //---- return(0); } //+------------------------------------------------------------------+ Edited October 23, 2013 by mmsknecht
Der Wolf Posted October 23, 2013 Report Posted October 23, 2013 Die Datei "alert.wav" muss unter {Dein-Mt4-Pfad}/sounds vorhanden sein. Ich habe den Indikator noch gar nicht getestet, da ich gerade auf einer Linux-Maschine ohne MT4 arbeite.Probier ich demnächst aus, ich geb dann wieder Bescheid. 2
mmsknecht Posted October 23, 2013 Author Report Posted October 23, 2013 Die "alert.wav" ist ein Standartsound im Mt4-Pfad, deswegen sollte es eigentlich gehen? Freue mich auf deinen Test.
Vola Posted October 23, 2013 Report Posted October 23, 2013 Habe den Indi aus Post # 6 grade mal getestet.Es kommt bei jedem Tick ein PiepTon, aber der eigentliche Alarmton (Original) kommt nur in unregelmässigen Abständen, meist bei einem neuen Tief/Hoch.Schmeisse ich den Indi dann aus dem Chart, läuft der Ton und der Alarm noch ca. 20 sekunden im Chart weiter, obwohl der Indikator sich gar nicht mehr in diesem befindet.
Der Wolf Posted October 23, 2013 Report Posted October 23, 2013 On 10/23/2013 at 7:27 PM, mmsknecht said: Die "alert.wav" ist ein Standartsound im Mt4-Pfad, deswegen sollte es eigentlich gehen? Freue mich auf deinen Test.klar, der ist ein Standardsound, aber der hätte ja auch in Deiner Installation aus irgendeinem Grunde fehlen können und dann hättest Du den Effekt, das gar kein Ton kommt.Das wollte ich nur sicherheitshalber verifizieren. Ich habe jetzt die static-Variable AlertTime eingebaut und zusätzlich noch eine Abfrage auf i==0, sodaß nur beim letzten Trendwechsel "gebimmelt" wird. Habe paar Minuten gewartet, aber da war gerade kein Trendwechsel in Realtime, versuchs doch mal bitte, ob es jetzt funktioniert. #property indicator_chart_window #property indicator_color1 Lime #property indicator_color2 Red #property indicator_width1 2 #property indicator_width2 2 #property indicator_buffers 2 double TrendUp[], TrendDown[]; int changeOfTrend; extern int Nbr_Periods = 10; extern double Multiplier = 3.0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexBuffer(0, TrendUp); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(0, "Trend Up"); SetIndexBuffer(1, TrendDown); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(1, "Trend Down"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { static datetime AlertTime = 0; int limit, i, flag, flagh, trend[5000]; double up[5000], dn[5000], medianPrice, atr; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //Print(limit); //---- for (i = Bars; i >= 0; i--) { TrendUp[i] = EMPTY_VALUE; TrendDown[i] = EMPTY_VALUE; atr = iATR(NULL, 0, Nbr_Periods, i); //Print("atr: "+atr[i]); medianPrice = (High[i]+Low[i])/2; //Print("medianPrice: "+medianPrice[i]); up[i]=medianPrice+(Multiplier*atr); //Print("up: "+up[i]); dn[i]=medianPrice-(Multiplier*atr); //Print("dn: "+dn[i]); trend[i]=1; if (Close[i]>up[i+1]) { trend[i]=1; if (trend[i+1] == -1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (Close[i]<dn[i+1]) { trend[i]=-1; if (trend[i+1] == 1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (trend[i+1]==1) { trend[i]=1; changeOfTrend = 0; } else if (trend[i+1]==-1) { trend[i]=-1; changeOfTrend = 0; } if (trend[i]<0 && trend[i+1]>0) { flag=1; //Print("flag: "+flag); } else { flag=0; //Print("flagh: "+flag); } if (trend[i]>0 && trend[i+1]<0) { flagh=1; //Print("flagh: "+flagh); } else { flagh=0; //Print("flagh: "+flagh); } if (trend[i]>0 && dn[i]<dn[i+1]) dn[i]=dn[i+1]; if (trend[i]<0 && up[i]>up[i+1]) up[i]=up[i+1]; if (flag==1) up[i]=medianPrice+(Multiplier*atr); if (flagh==1) dn[i]=medianPrice-(Multiplier*atr); //-- Draw the indicator if (trend[i]==1) { TrendUp[i]=dn[i]; if (changeOfTrend == 1) { TrendUp[i+1] = TrendDown[i+1]; if (i == 0 && AlertTime != Time[0]) PlaySound("alert.wav"); changeOfTrend = 0; AlertTime = Time[0]; } } else if (trend[i]==-1) { TrendDown[i]=up[i]; if (changeOfTrend == 1) { TrendDown[i+1] = TrendUp[i+1]; if (i==0 && AlertTime != Time[0]) PlaySound("alert.wav"); changeOfTrend = 0; AlertTime = Time[0]; } } } WindowRedraw(); //---- return(0); } //+------------------------------------------------------------------+ 4
Der Wolf Posted October 23, 2013 Report Posted October 23, 2013 On 10/23/2013 at 7:55 PM, Vola said: Habe den Indi aus Post # 6 grade mal getestet.Es kommt bei jedem Tick ein PiepTon, aber der eigentliche Alarmton (Original) kommt nur in unregelmässigen Abständen, meist bei einem neuen Tief/Hoch.Schmeisse ich den Indi dann aus dem Chart, läuft der Ton und der Alarm noch ca. 20 sekunden im Chart weiter, obwohl der Indikator sich gar nicht mehr in diesem befindet.Der Piepton kommt, weil die Abfrage auf i==0, also nur auf den letzten Trendwechsel noch nicht drin war und somit die ganze Kette an Bars abgearbeitet und geklingeltwurde.Der Inidkator war halt von vornherein nicht fürs "bimmeln" vorgesehen, sondern nur für die Anzeige von otpischen Trendwechseln.
Vola Posted October 23, 2013 Report Posted October 23, 2013 Habe mal etwas auf dem Rechner gekramt, hatte da eine .doc drauf, vllt. hilft es ja weiter.Glaube zwar nicht wirklich dran, aber wer weiß: How to add alarm to any indicator http://www.forex-tsd.com/indicators-metatrader-4/87-indicators-alert-signal-12.htmlPOST # 113 Quote HiI see a lot of people here asking to add alarm when an indicator is light up. Especially when a arrow/bullet is turn on.Actually, it is very simple task. All you have to do is follow the following instructions.1) Every indicator has an indicator array that keep the values of the indicator. Values can be 0 or not 0. To find out the indicator name look for the command: SetIndexBufferIn the indicator editor it should look like thisSetIndexBuffer(0,ExtMapBuffer);SetIndexBuffer(1,ExtMapBuffer2);This lines tell us that we have 2 indicator buffers2) Look when the indicator buffer change its value.In the example above we will look to line that contains the following patter:ExtMapBuffer[number] = where number can be a figure or a name. For example: if(res!=0.0) ExtMapBuffer[shift]=res;if after the equal sign there is 0 do nothing.3) Change it to make an alarm.After finding the value setting line we will add an alarm to it.a) add { before the setting. In the example above :if(res!=0.0) {ExtMapBuffer[shift]=res;b) add the Alert command after the ;. In the example above:if(res!=0.0) { ExtMapBuffer[shift]=res;Alert("Indicator set");}Do not forget to close the }4) repeat for every buffer value settingCompile and you have an indicator with alertHope it will help you
Rumpel Posted October 23, 2013 Report Posted October 23, 2013 On 10/23/2013 at 7:02 PM, Der Wolf said: Ich habe den Indikator noch gar nicht getestet, da ich gerade auf einer Linux-Maschine ohne MT4 arbeite.
mmsknecht Posted October 25, 2013 Author Report Posted October 25, 2013 On 10/23/2013 at 8:06 PM, Der Wolf said: Der Piepton kommt, weil die Abfrage auf i==0, also nur auf den letzten Trendwechsel noch nicht drin war und somit die ganze Kette an Bars abgearbeitet und geklingeltwurde.Der Inidkator war halt von vornherein nicht fürs "bimmeln" vorgesehen, sondern nur für die Anzeige von otpischen Trendwechseln. Habe ihn jetzt 30 Minuten auf M1 und 2 Std. auf M5 getestet. Allerdings passiert nichts - kein Alertsound. Ich weiß noch nicht warum?
Der Wolf Posted October 26, 2013 Report Posted October 26, 2013 On 10/25/2013 at 8:29 AM, mmsknecht said: Habe ihn jetzt 30 Minuten auf M1 und 2 Std. auf M5 getestet. Allerdings passiert nichts - kein Alertsound. Ich weiß noch nicht warum?Ich werde das am Montag mal testen, gebe dann wieder Bescheid.
Der Wolf Posted October 28, 2013 Report Posted October 28, 2013 On 10/26/2013 at 11:30 PM, Der Wolf said: Ich werde das am Montag mal testen, gebe dann wieder Bescheid.So funktioniert es:Ich habe zusätzlich noch Print-Statements zur Kontrolle, wann gebimmelt wurde, eingebaut. Quote //-- Draw the indicator if (trend==1) { TrendUp=dn; if (changeOfTrend == 1) { TrendUp[i+1] = TrendDown[i+1]; changeOfTrend = 0; if (i==0 && trend[i+1] == -1 && AlertTime != Time[0]) { PlaySound("alert.wav"); Print("UP: playsound at " + TimeToStr(Time[0], TIME_DATE|TIME_MINUTES)); AlertTime = Time[0]; } } } else if (trend==-1) { TrendDown=up; if (changeOfTrend == 1) { TrendDown[i+1] = TrendUp[i+1]; changeOfTrend = 0; if (i==0 && trend[i+1] == 1 && AlertTime != Time[0]) { PlaySound("alert.wav"); Print("DOWN: playsound at " + TimeToStr(Time[0], TIME_DATE|TIME_MINUTES)); AlertTime = Time[0]; } } } Der vollständige Indikator: supertrend.mq4 Und der Test: Start des Indikators in einem Downtrend.Von 6:37 bis 6:45 fünf mal gebimmelt (Kurs ging über die obere rote Linie des Supertrend-Indikators) aber wegen "Repaint" des Supertrend-Indikators beibt dieser rotUm 7:21 erfolgte dann der nachhaltige Durchbruch des Downtrends.Um 7:28 und 7:29 Bruch des Uptrends, doppeltes Bimmeln wegen Indikator-Repaint. 4
cxalgo Posted October 28, 2013 Report Posted October 28, 2013 On 10/28/2013 at 12:10 PM, Der Wolf said: ...aber wegen "Repaint" des Supertrend-Indikators beibt dieser rotUm 7:21 erfolgte dann der nachhaltige Durchbruch des Downtrends.Um 7:28 und 7:29 Bruch des Uptrends, doppeltes Bimmeln wegen Indikator-Repaint. Deswegen ist dieser auch nicht für EA´s zum Empfehlen, schaut gut aus, bringt aber nix bis wenig.
mmsknecht Posted October 31, 2013 Author Report Posted October 31, 2013 (edited) Hallo Wolf, ich habe das Script jetzt getestet. Auf dem M1 (EUR/USD) Wegen dem repainting kommt es zum Fehlalarm. Im Moment ist es so, dass der Alarm ausgelöst wird, wenn die aktuelle Kerze den letzten Supertrend berührt. Schließt der ST dann z.B. im shortfall unter dem letzten ST-Signal, kommt es zum repaint. Wenn man sich das im M1 (Balken Chart) anschaut gibt es dafür aber eine Lösung. Es dürfte erst zu einem Alarm kommen, wenn die candel auch über dem letzten ST-Signal schließt. Quasi eine Periode später, wenn die letze Kerze über dem Supertrend geschlossen hat. Dann gibt’s auch kein repaint mehr!Das Signal wäre dann eindeutig. Wie das allerdings in mql aussehen muss? Edited October 31, 2013 by mmsknecht
Der Wolf Posted November 2, 2013 Report Posted November 2, 2013 On 10/31/2013 at 6:23 PM, mmsknecht said: Wie das allerdings in mql aussehen muss? http://1.1.1.4/bmi/www.tom-next.com/community//public/style_emoticons/default/cleanglasses.gif Versuchs mal in der for-Schleife mit i >= 1 anstelle von i >= 0 Quote for (i = Bars; i >= 1; i--) { . . . zur Problematik Supertrend und Repaint siehe auch: http://codebase.mql4.com/8584 2
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now