| / | Forum |
|
edas
2010.10.20 14:05
Hello, Highest function is very easy to understand. However I often got strange results from it. Below is simple indicator I want to build. It should plot arrows at Highest bar, Period 100. However indicator plots also on bars who does not match this criteria. Why ? Thanks, //+------------------------------------------------------------------+ //| HighEstPeriod.mq4 | //+------------------------------------------------------------------+ #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- for(int i = ObjectsTotal() - 1; i >= 0; i--) { string label = ObjectName(i); if(StringSubstr(label, 0, 4) == "High") ObjectDelete(label); } //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int Bar, counted_bars=IndicatorCounted(); //---- int bars, HighPer = 30; double PrevHigh; int limit=Bars-counted_bars; for (Bar = 1; Bar <= limit; Bar++) //skaiciuojame nuo ankstesnio baro, iki Mx baru { int PrevHighBar = iHighest(NULL,0,MODE_HIGH, HighPer, Bar) ; PrevHigh = High[PrevHighBar ] ; string tekstas = "Highest_"+HighPer+"_"+Bar; DrawArrow("Highest_"+HighPer+"_"+Bar, Time[PrevHighBar], High[PrevHighBar]+15*Point, 251, Magenta, 1); } //---- return(0); } //+------------------------------------------------------------------+ void DrawArrow(string objectName, datetime Time1, double Price, int ArrowCode, color Color, int Width ) { ObjectCreate(objectName, OBJ_ARROW, 0, Time1, Price, 0); ObjectSet(objectName, OBJPROP_ARROWCODE, ArrowCode ); ObjectSet(objectName, OBJPROP_COLOR, Color); // ObjectSet(objectName, OBJPROP_RAY, true); ObjectSet(objectName, OBJPROP_WIDTH, Width); ObjectMove(objectName, 0, Time1, Price); } |
|
On the Long Way to Be a Successful Trader - The Two Very First Steps The main point of this article is to show a practical way to implement an effective MM. This can be achieved only by using a certain kind of strategies that we need to identify and describe first. In the following we’ll cover the basic concepts of how to build such a strategy and we’ll point out the common mistakes which always end up in draining a trader’s account. |
|
edas
2010.10.20 14:06
|
|
qjol
2010.10.20 14:49
can u explain me something? u want an arrow draw only on the highest 100 bars ? (Ar galite paaiškinti man ką nors? |
|
edas
2010.10.20 15:09
Yes, qjol, I want to draw arraw only on the highest bar, counting 100 bars from bar in the counting cycle. Many bars could be marked, but only who are highest. All bars in the right met this criteria. On left (in rectangle) does not met this criteria, as there are higher bars after them. |
|
qjol
2010.10.20 15:14
then y u need the loop for, remove the line: for (Bar = 1; Bar <= limit; Bar++) & of course u don't need the {} |
|
sergery
2010.10.20 16:13
try to use ZigZag indicator,and set depth as 100. |
|
7bit
2010.10.20 16:41
sergery: This would not be a solution, this would be capitulation.try to use ZigZag indicator,and set depth as 100. |
|
Ais
2010.10.21 02:21
Hello, 1. "It should plot arrows at Highest bar, Period 100." 2. Probably we see old arrows. Best regards |
|
edas
2010.10.21 14:21
Hello, Thanks for your attention and help. I found a solution to my needs, programming my own function and indicator. I attached it here. Arrows are plotted, if High is higher than 20 previous highs, and next bar is lower . Arrow name have the highest number. This indicator simulates Tradestation's PivotStren function. But my question is still open: is it possible to get this result with iHighest function ? Edas |
|
edas
2010.10.21 14:24
//+------------------------------------------------------------------+ //| HighEstPeriod.mq4 | //+------------------------------------------------------------------+ #property indicator_chart_window #property link "analyst.fx-analysis.com" //#include <Library_calc.mqh> extern int MaxCalc = 100; extern int LPivotStren = 20; extern int RPivotStren = 1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- for(int i = ObjectsTotal() - 1; i >= 0; i--) { string label = ObjectName(i); if(StringSubstr(label, 0, 4) == "High") ObjectDelete(label); } //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int Bar, counted_bars=IndicatorCounted(); //---- if (counted_bars < 0) return(-1); if (counted_bars>0) counted_bars--; int bars, HighBar, HighPer = 100; int limit=Bars-counted_bars; for (Bar = limit; Bar >= 0; Bar--) //skaiciuojame nuo ankstesnio baro, iki Mx baru { // HighBar = iHighest(NULL,0,MODE_HIGH, HighPer, Bar) ; int HighPivotNo = HighPivotInt(Bar, MaxCalc, RPivotStren ); if ( HighPivotNo >= LPivotStren ) { string tekstas = "HighLeftPivot_"+HighPivotNo+"_"+Bar; DrawArrow(tekstas, Time[Bar], High[Bar]+15*Point, 251, Magenta, 1); } } //---- return(0); } //+------------------------------------------------------------------+ void DrawArrow(string objectName, datetime Time1, double Price, int ArrowCode, color Color, int Width ) { ObjectCreate(objectName, OBJ_ARROW, 0, Time1, Price, 0); ObjectSet(objectName, OBJPROP_ARROWCODE, ArrowCode ); ObjectSet(objectName, OBJPROP_COLOR, Color); // ObjectSet(objectName, OBJPROP_RAY, true); ObjectSet(objectName, OBJPROP_WIDTH, Width); ObjectMove(objectName, 0, Time1, Price); } //+------------------------------------------------------------------+ int HighPivotInt(int BarNumber, int MaxBars2Calc, int RStren) { int i, PivotStr; if (RStren != 0 ) for (i = 1; i <= RStren; i++) if (High[BarNumber] < High[BarNumber-i] ) return(0); if (MaxBars2Calc != 0 ) for (i = 1; i <= MaxBars2Calc; i++) if (High[BarNumber] <= High[BarNumber+i] ) return(i); //-------------- return(MaxBars2Calc); } ![]() |
|
Ais
2010.10.21 15:38
Usually I find the highest/lowest bars like in the following sample:
|