|
Programmierung MQL4 Hier gehts rund ums Programmieren in MQL4. |
|
Themen-Optionen | Thema durchsuchen | Ansicht |
|
|||
Probleme bei der Bufferauswertung
Moin Moin,
hab nen Indikator wo ich den Buffer nicht korrekt auslesen kann. Mir werden die Standartwerte für EMPTY_VALUE wiedergegeben. Was Graphiken angeht bin ich kompletter Laie , hab noch nie was mit ObjectCreate gemacht. Hab nur in den Docs den Wert gefunden. Aufrufen der Buffer 0-3 funktioniert auch , nur bräuchte ich Buffer 4 und 5 , hoffe jem kennt sich da aus und weiß Rat LG Code:
#property indicator_chart_window #property indicator_buffers 8 #property indicator_color1 clrLime // UpperLine #property indicator_color2 clrRed // LowerLine #property indicator_color3 clrBlueViolet // Target1 #property indicator_color4 clrOrange // Target2 #property indicator_color5 clrDarkBlue // BuyArrow #property indicator_color6 clrYellow // SellArrow #property indicator_color7 clrMagenta // BullDot #property indicator_color8 clrWhite // BearDot #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 5 // BuyArrow #property indicator_width6 5 // SellArrow #property indicator_width7 1 // BullDot #property indicator_width8 1 // BearDot extern int ZigZagDepth = 5; extern double RetraceDepthMin = 0.4; extern double RetraceDepthMax = 1.0; extern bool ShowAllLines = True; extern bool ShowAllBreaks = True; extern bool ShowTargets = True; extern double Target1Multiply = 1.5; extern double Target2Multiply = 3.0; extern bool HideTransitions = True; // indicator buffers double UpperLine[]; double LowerLine[]; double Target1[]; double Target2[]; double BuyArrow[]; double SellArrow[]; double BullDot[]; double BearDot[]; int Size,Posi_Multi; string Style; double firsthigh, firstlow, lasthigh, lastlow, prevhigh, prevlow, signalprice, brokenline,Posi,entryprice_L,entryprice_S; datetime firsthightime, firstlowtime, lasthightime, lastlowtime, prevhightime, prevlowtime, signaltime; datetime redrawtime; // remember when the indicator was redrawn int signal,D; #define NOSIG 0 #define BUYSIG 1 #define SELLSIG 2 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { int i; for(i=0; i<=7; i++) SetIndexEmptyValue(i,EMPTY_VALUE); if(ShowAllLines == True) SetIndexStyle(0,DRAW_LINE); else SetIndexStyle(0,DRAW_NONE); if(ShowAllLines == True) SetIndexStyle(1,DRAW_LINE); else SetIndexStyle(1,DRAW_NONE); if(ShowTargets == True) SetIndexStyle(2,DRAW_LINE); else SetIndexStyle(2,DRAW_NONE); if(ShowTargets == True) SetIndexStyle(3,DRAW_LINE); else SetIndexStyle(3,DRAW_NONE); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,SYMBOL_ARROWUP); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,SYMBOL_ARROWDOWN); SetIndexStyle(6,DRAW_ARROW); SetIndexArrow(6,161); // BullDot (WingDings character) SetIndexStyle(7,DRAW_ARROW); SetIndexArrow(7,161); // BearDot (WingDings character) SetIndexBuffer(0,UpperLine); SetIndexBuffer(1,LowerLine); SetIndexBuffer(2,Target1); SetIndexBuffer(3,Target2); SetIndexBuffer(4,BuyArrow); SetIndexBuffer(5,SellArrow); SetIndexBuffer(6,BullDot); SetIndexBuffer(7,BearDot); IndicatorDigits(Digits); if(ShowAllLines == True) SetIndexLabel(0,"UpperLine"); else SetIndexLabel(0,""); if(ShowAllLines == True) SetIndexLabel(1,"LowerLine"); else SetIndexLabel(1,""); if(ShowTargets == True) SetIndexLabel(2,"Target1"); else SetIndexLabel(2,""); if(ShowTargets == True) SetIndexLabel(3,"Target2"); else SetIndexLabel(3,""); SetIndexLabel(4,"BuyArrow"); SetIndexLabel(5,"SellArrow"); SetIndexLabel(6,""); SetIndexLabel(7,""); // cleanup display buffers for(i=0; i<Bars; i++) { UpperLine[i] = EMPTY_VALUE; LowerLine[i] = EMPTY_VALUE; Target1[i] = EMPTY_VALUE; Target2[i] = EMPTY_VALUE; BuyArrow[i] = EMPTY_VALUE; SellArrow[i] = EMPTY_VALUE; BullDot[i] = EMPTY_VALUE; BearDot[i] = EMPTY_VALUE; } return( INIT_SUCCEEDED); } // end of init() double Komma = Digits; //+------------------------------------------------------------------+ //| Status Message prints below OHLC upper left of chart window //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { // REDRAW ONLY ONE TIME PER CANDLE if(redrawtime == Time[0]) { return(0);} // if already redrawn on this candle then do no more else redrawtime = Time[0]; // remember when the indicator was redrawn double zigzag, range, retracedepth, one, two, three; datetime onetime, twotime, threetime; int shift = Bars-1; while(shift >= 0) { // UPPERLINES and LOWERLINES based on ZIGZAG UpperLine[shift] = UpperLine[shift+1]; LowerLine[shift] = LowerLine[shift+1]; Target1[shift] = Target1[shift+1]; Target2[shift] = Target2[shift+1]; // BuyArrow[shift] = EMPTY_VALUE; // SellArrow[shift] = EMPTY_VALUE; BullDot[shift] = EMPTY_VALUE; BearDot[shift] = EMPTY_VALUE; zigzag = iCustom(NULL,0,"ZigZag",ZigZagDepth,5,3,0,shift); if(zigzag == High[shift]) { UpperLine[shift] = High[shift]; firsthigh = prevhigh; firsthightime = prevhightime; prevhigh = lasthigh; prevhightime = lasthightime; lasthigh = zigzag; lasthightime = Time[shift]; } if(zigzag == Low[shift]) { LowerLine[shift] = Low[shift]; firstlow = prevlow; firstlowtime = prevlowtime; prevlow = lastlow; prevlowtime = lastlowtime; lastlow = zigzag; lastlowtime = Time[shift]; } /////////////////////////// // BULLISH BREAK ABOVE #2 one = prevlow; onetime = prevlowtime; two = lasthigh; twotime = lasthightime; if(twotime == Time[shift]){two = prevhigh; twotime = prevhightime;} three = lastlow; threetime = lastlowtime; if(one - two != 0) retracedepth = (three - two) / (one - two); // retrace depth // signal rules if(shift > 0) if(retracedepth > RetraceDepthMin) // minimum retrace depth for 123 pattern if(retracedepth < RetraceDepthMax) // maximum retrace depth for 123 pattern if(brokenline != UpperLine[shift]) // if this line has not already been broken if(Low[shift] < UpperLine[shift]) // low of rangebar is below the line if(Close[shift] > UpperLine[shift]) // close of rangebar body is above the line (break) { range = MathAbs(two - three); // range is the distance between two and three BuyArrow[shift] = Low[shift]; BullDot[iBarShift(NULL,0,onetime)] = one; // ONE BullDot[iBarShift(NULL,0,twotime)] = two; // TWO BullDot[iBarShift(NULL,0,threetime)] = three; // THREE signal = BUYSIG; Target1[shift] = ( two + ((two-three/100)*61.8*10*Point ) ); Target2[shift] = two+(range*Target2Multiply); signaltime = Time[shift]; signalprice = BuyArrow[shift]; brokenline = UpperLine[shift]; // Ausgabe("Target 1 :",DoubleToStr(Target1[shift],Digits),clrBlack ); // Alert( "Long Signal im " + Symbol() + "." +" Punkt 2 um: " + TimeToString(Time[shift],TIME_MINUTES )+" Uhr gebrochen "); } ///////////////////////////////////////////// // BULLISH BREAK OF UPPERLINE (NOT 123 SETUP) // signal rules if(shift > 0) if(ShowAllBreaks == True) if(brokenline != UpperLine[shift]) // if this line has not already been broken if(Low[shift] < UpperLine[shift]) // low of rangebar is below the line if(Close[shift] > UpperLine[shift]) // close of rangebar body is above the line (break) { range = UpperLine[shift]-LowerLine[shift]; Target1[shift] = UpperLine[shift]+(range*Target1Multiply); Target2[shift] = UpperLine[shift]+(range*Target2Multiply); BuyArrow[shift] = Low[shift]; signal = BUYSIG; signaltime = Time[shift]; signalprice = BuyArrow[shift]; brokenline = UpperLine[shift]; } /////////////////////////// // BEARISH BREAK BELOW #2 one = prevhigh; onetime = prevhightime; two = lastlow; twotime = lastlowtime; if(twotime == Time[shift]){two = prevlow; twotime = prevlowtime;} three = lasthigh; threetime = lasthightime; if(one - two != 0) retracedepth = (three - two) / (one - two); // retrace depth // signal rules if(shift > 0) if(retracedepth > RetraceDepthMin) // minimum retrace depth for 123 pattern if(retracedepth < RetraceDepthMax) // maximum retrace depth for 123 pattern if(brokenline != LowerLine[shift]) // if this line has not already been broken if(High[shift] > LowerLine[shift]) // high of rangebar is above the line if(Close[shift] < LowerLine[shift]) // close of rangebar is below the line (break) { range = MathAbs(two - three); // range is the distance between two and three Target1[shift] = two-(range*Target1Multiply); Target2[shift] = two-(range*Target2Multiply); SellArrow[shift] = High[shift]; BearDot[iBarShift(NULL,0,onetime)] = one; // ONE BearDot[iBarShift(NULL,0,twotime)] = two; // TWO BearDot[iBarShift(NULL,0,threetime)] = three; // THREE signal = SELLSIG; signaltime = Time[shift]; signalprice = SellArrow[shift]; brokenline = LowerLine[shift]; // entryprice_S = Open[shift-1]; // Alert( "Short Signal im " + Symbol() + ". Punkt 2 um: " + TimeToString(Time[shift],TIME_MINUTES )+" Uhr gebrochen "); } ///////////////////////////////////////////// // BEARISH BREAK OF LOWERLINE (NOT 123 SETUP) // signal rules if(shift > 0) if(ShowAllBreaks == True) if(brokenline != LowerLine[shift]) // if this line has not already been broken if(High[shift] > LowerLine[shift]) // high of rangebar is above the line if(Close[shift] < LowerLine[shift]) // close of rangebar is below the line (break) { range = UpperLine[shift]-LowerLine[shift]; Target1[shift] = LowerLine[shift]-(range*Target1Multiply); Target2[shift] = LowerLine[shift]-(range*Target2Multiply); SellArrow[shift] = High[shift]; signal = SELLSIG; signaltime = Time[shift]; signalprice = SellArrow[shift]; brokenline = LowerLine[shift]; // entryprice_S = Open[shift-1]; } // TARGET LINE RULES if(signal == BUYSIG) { if(Low[shift] > Target1[shift]) Target1[shift] = EMPTY_VALUE; if(Low[shift] > Target2[shift]) Target2[shift] = EMPTY_VALUE; } if(signal == SELLSIG) { if(High[shift] < Target1[shift]) Target1[shift] = EMPTY_VALUE; if(High[shift] < Target2[shift]) Target2[shift] = EMPTY_VALUE; } // HIDE LINE TRANSITIONS if(HideTransitions == True) { if(UpperLine[shift] != UpperLine[shift+1]) UpperLine[shift+1] = EMPTY_VALUE; if(LowerLine[shift] != LowerLine[shift+1]) LowerLine[shift+1] = EMPTY_VALUE; if(Target1[shift] != Target1[shift+1]) Target1[shift+1] = EMPTY_VALUE; if(Target2[shift] != Target2[shift+1]) Target2[shift+1] = EMPTY_VALUE; } shift--; // move ahead one candle } return(0); }// end of start() //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { // cleanup display buffers for(int i=0; i<Bars; i++) { UpperLine[i] = EMPTY_VALUE; LowerLine[i] = EMPTY_VALUE; Target1[i] = EMPTY_VALUE; Target2[i] = EMPTY_VALUE; BuyArrow[i] = EMPTY_VALUE; SellArrow[i] = EMPTY_VALUE; BullDot[i] = EMPTY_VALUE; BearDot[i] = EMPTY_VALUE; } return (0); }// end of deinit() |
|
|||
Wenn Du die Werte von Objekte im Buffer verfügbar haben willst, dann musst Du diese Werte auch in ein Buffer (Array) schreiben, und diese dann auch verfügbar machen. Ansonsten ist ein Objekt lediglich ein Objekt, was auf dem Chart dargestellt wird.
|
|
|||
danke für deine Antwort marquez,
den Indikator habe ich nicht geschrieben, dazu bin ich programmiertechnisch ned fit genug. Wenn du mir nen tipp/kleines Code-Beispiel geben kannst wie ich das ummodeln kann damit die werte auch abrufbar sind, wäre ich dir sehr dankbar LG |
|
|||
Zitat:
Der Indikator, so wie Du ihn gepostet hast, sollte sich, auch wenn es alter Code ist, korrekt verhalten. Mir erweckt sich eher der Eindruck, Du möchtest die Werte mittels eines EA und icustom auslesen, und hast dort einen programmier oder Abfragefehler drin. |
|
|||
ja das is korrekt wollt/will den Indikator über nen EA und iCustum funktion auslesen, hätte ich wohl noch explizieter erwähnen müssen, deswegen hab ich auch den chart oben mit dran gepostet, da sind auch die ausgelesenen Werte der Buffer im Kommentar oben Links aufgelistet. Dacht das man dass dementsprechend ableiten kann. Werds beim nächsten post konkreter beschreiben, spart weitere Erklärungen
Wenn du sagst Fehlerhaft, gibt es denn noch eine andere Methode wenn es um Objekte geht?!? Auf "normalem" Weg bekomm ich wie gesagt nur die Standartwerte von EMPTY_VALUE zurück siehe Chartanhang |
|
|||
Da wird der Hund begraben sein.
Deswegen wird Dir hier auch niemand der experten geantwortet haben. Bei solchen Fehlern wie bei Dir, wird normalerweise der Code erwartet, den Du geschrieben hast. Das pasten des Indikators den Du auslesen willst, hilft dabei nur sekundär weiter. Also ohne Deinen Code zu sehen wird dir keiner, auch nicht nicht, weiterhelfen können. |
|
|||
Sorry, hast Du den Code mal angeschaut. Der ist super programmiert und man kann alle Buffer mit iCustom() z.B. iCustom(NULL, PERIOD_CURRENT, "DeinIndiName",5,0.4,1,true,true,true,1.5,3,true,1 ,current) ohne Probleme auslesen :-)
|
|
|||
Zitat:
Zitat:
wenns was hilft, aber sprech ja alle Buffer gleich an. Code:
#property copyright "Copyright 2016, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ int start() { double A = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,0,1); //Buffer 0 double B = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,1,1); //Buffer 1 double C = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,2,1); //Buffer 2 double D = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,3,1); //Buffer 3 double E = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,4,1); //Buffer 4 double F = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,5,1); //Buffer 5 double G = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,6,1); //Buffer 6 double H = iCustom(NULL,0,"Testindikator",5,0.4,1.0,true ,true,false,1.5,3.0,true,7,1); //Buffer 7 Comment("Buffer 0: ",A, "\nBuffer 1: ",B, "\nBuffer 2: ",C, "\nBuffer 3: ",D, "\nBuffer 4: ",E, "\nBuffer 5: ",F, "\nBuffer 6: ",G, "\nBuffer 7: ",H); return(0); } Buffer 0-3 geben auch die errechneten Zonen wieder , nur 4-7 eben nicht. Das false im iCustom hat auch keine Auswirkung. |
|
|||
Hi,
Upps mit "Sorry, hast Du den Code mal angeschaut." hatte ich eigentlich nicht Dich gemeint :-) So sind die Buffer im Indikator dokumentiert: 0 - > double UpperLine[]; 1 - > double LowerLine[]; 2 - > double Target1[]; 3 - > double Target2[]; 4 - > double BuyArrow[]; 5- > double SellArrow[]; 6 - > double BullDot[]; 7- > double BearDot[]; Wenn Du die aktuelle Kerze aufrufst, bekommst Du immer 0 bis 3 zurück. Für die anderen Buffer gibt es zunächst EMPTY_VALUE. Erst wenn ein Wert tatsächlich vorhanden ist (sprich: er malt einen Arrow oder einen Dot) bekommst Du auch den dazugehörigen Wert. In der nächsten Kerze hast Du dann aber schon wieder EMPTY_VALUE. Für einen EA musst Du nur Ask/Bid >/< BuyArrow/SellArrow in der aktuellen Kerze hernehmen. Nettes Teil, der Indikator! |
|
|||
Zitat:
Das einzige was mir an dem Indikator halt nicht so wirklich gefällt, dass er nach altem code geschrieben ist, (init, start usw). Daher vermute ich das es ein alter ist. Davon abgesehen, alt muß ja nicht schlecht sein. Aber da ich persönlich nur noch MT5 benutzen, müsste ich für mich ein paar anpassungen hier und da vornehmen um ihn für mich benutzen zu können. However, ich hoffe ihm konnte jetzt geholfen werden, und alle sind glücklich |
Lesezeichen |
Stichworte |
buffer, bufferauswertung, indikator buffer, mql4, programmierung, programmierung metatrader |
|
|