Hey guys, I'm a Java developer and I am now learning mql4. I am trying to write an indicator and I can't see anything drawn. I am doing something similar to ZigZag so I don't have a value to draw for every candle (I set those to EMPTY_VALUE). Also when I have a value to add to the buffer, it is not for the current candle, but for the last high/low possition. Is the indicator seeing those changes to previous candles (Their values used to be EMPTY_VALUE and then changed to the candle's high/low)?
#property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Blue double swings[]; datetime LstCndl; int swingCount; int PSH, PSL, SH, SL, SClast, PrevSH, PrevSL; bool havePSH = false; int SC = 0; //extern color swing_colour = Blue; extern int swing_count = 5; //------------------------------------------------------------------------------------ int init() { IndicatorBuffers (1); SetIndexBuffer (0,swings); SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2,indicator_color1); //SetIndexDrawBegin (0,0); SetIndexLabel (0,"Swing Indicator"); LstCndl = Time[0]; swingCount = swing_count-1; PSH = ArraySize(High)-1; PSL = ArraySize(Low )-1; SH = ArraySize(High)-1; SL = ArraySize(Low )-1; SClast = ArraySize(Low )-1; PrevSH = ArraySize(High)-1; PrevSL = ArraySize(Low )-1; return(0); } //------------------------------------------------------------------------------------ int deinit() { return(0); } //------------------------------------------------------------------------------------ int start() { int counted_bars = IndicatorCounted(); //if (counted_bars<0) {return(-1);} if (counted_bars==0) {counted_bars = 1;} int uncountedbars = Bars-counted_bars; if (newCandle()) {increment();} //Print(uncountedbars); for(int i=(uncountedbars-1);i>0;i--) { int temp = runSwingType1(i); switch (temp) { case (2) : swings[SH] = High[SH]; break; case (-2): swings[SL] = Low[SL]; break; default : swings[i] = EMPTY_VALUE; } return(0); } } //------------------------------------------------------------------------------------ bool newCandle() { if(Time[0] != LstCndl) {LstCndl = Time[0]; return (true);} return (false); } //------------------------------------------------------------------------------------ void increment() {PSH++;PSL++;SH++;SL++;SClast++;PrevSH++;PrevSL++;} //------------------------------------------------------------------------------------Cheers for the tip. I see no values in my indicator. Can you look at the code and tell me if you see anything wrong? I am keeping the indexes of the key values in the (PSH,PSL,SH,SL,SClast,PrevSH,PrevSL) variables. I'm changing them each time the buffer shifts them upwards. The runSwingType1() function returns 2 for a qualified SwingHigh and a -2 for a qualified SwingLow.
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2,indicator_color1);I am keeping the indexes of the key values in the (PSH,PSL,SH,SL,SClast,PrevSH,PrevSL)
- You are drawing a line. Unless you set consecutive bars non-empty, you won't see anything (zero length line.) Change it to an arrow and you'll see where you setting values. Set it to section to connect the dots.
- So if you have 1000 bars, all you are looking at is the left most one and when a new bar comes in you shift one - no wonder you see nothing. Drop those variable entirely. You test bar[i] for your condition and set swings[i] not swings[sh]. Indicators do not require a newCandle, just compute bar[i]
int counted_bars = IndicatorCounted(); //if (counted_bars<0) {return(-1);} if (counted_bars==0) {counted_bars = 1;} int uncountedbars = Bars-counted_bars; if (newCandle()) {increment();} //Print(uncountedbars); for(int i=(uncountedbars-1);i>0;i--) {
Contradictory information on IndicatorCounted() - MQL4 forum Initially counted is zero, you make it one so uncounted is the first bar on the chart. You then skip it with (uncounted-1). Do it properlyint counted_bars = IndicatorCounted(); if(counted_bars < LOOKBACK) counted_bars = LOOKBACK; // MA(x) has lookback of x // Don't look past end of chart. for(int i=Bars - 1 - counted_bars; i>=0; i--) { // >=0 to look at current bar
Disregard my previous comment.
1. I changed it to section.
2. Can you explain this point again. Also bare in mind that I have to examine bars ahead to set a previous candle as a Swing High. There is no way to know if the bar I am examining will be a SwingHigh/Low. That's why I am storing the index of the bars who are PotentialSwingHighs/Lows and then draw them when they qualify. I guess I'm not thinking in mql4 terms, that's what I need help with.
3. I'm reading into this now. (EDIT: I am setting counted_bars to 1 the first time the indicator runs so that bar[0] is not compared with bar[0]. There is no point to it really, just skipping one iteration.)
Disregard my previous comment.
1. I changed it to section.
2. Can you explain this point again. Also bare in mind that I have to examine bars ahead to set a previous candle as a Swing High. There is no way to know if the bar I am examining will be a SwingHigh/Low. That's why I am storing the index of the bars who are PotentialSwingHighs/Lows and then draw them when they qualify. I guess I'm not thinking in mql4 terms, that's what I need help with.
3. I'm reading into this now.
- Then you just delete it.
- You didn't post your code so there's no way for us to know what you did or how you defined a SH. perhaps:
#define LOOKBACK 20 int counted_bars = IndicatorCounted(); if(counted_bars < LOOKBACK) counted_bars = LOOKBACK; // MA(x) has lookback of x // Don't look past end of chart. for(int i=Bars - 1 - counted_bars; i>=0; i--) { // ALL Bars. for(int iBar = i + LOOKBACK; iBar >= i; iBar--) swings[iBar] = EMPTY_VALUE; // Clear invalid swings. int iHH = iHighest(NULL,0, MODE_HIGH, LOOKBACK + 1, i), // Find current swing. iLL = iLowest(NULL,0, MODE_LOW, LOOKBACK + 1, i); swings[iHH] = High[iHH]; // Display it. swings[iLL] = Low[iLL]; }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys, I'm a Java developer and I am now learning mql4. I am trying to write an indicator and I can't see anything drawn. I am doing something similar to ZigZag so I don't have a value to draw for every candle (I set those to EMPTY_VALUE). Also when I have a value to add to the buffer, it is not for the current candle, but for the last high/low possition. Is the indicator seeing those changes to previous candles (Their values used to be EMPTY_VALUE and then changed to the candle's high/low)?
Cheers