You should initialize every arrow buffer to EMPTY_VALUE per iteration.
for(int i=count-1; i>=0 && !IsStopped(); i--) { SellBuffer[i]=EMPTY_VALUE; BuyBuffer[i]=EMPTY_VALUE; //...
thanks Yashar for replying
and about initialization buffers, i afraid not!
because the signal is sent by breaking the high/low of the step 1 candle which happened some candles ago, this step 1 confirmation is checked with Boolean flags (ValidBuy // ValidSell)
// Step 1 buy candle if(i != 0 && !ValidBuy && Step1(0, i)) { ValidBuy = true; BuyPrice = iHigh(Symbol(), PERIOD_CURRENT, i); BuySL = iLow(Symbol(), PERIOD_CURRENT, i); } // Step 1 sell candle if(i != 0 && !ValidSell && Step1(1, i)) { ValidSell = true; SellPrice = iLow(Symbol(), PERIOD_CURRENT, i); SellSL = iHigh(Symbol(), PERIOD_CURRENT, i); }
once sending the signal, it turns those flags to false and searches for new cycles
if(ValidBuy) { BuyBuffer[i] = iLow(Symbol(), PERIOD_CURRENT, i); ValidBuy = false; BuySL = 0.0; BuyPrice = 0.0; }
if(ValidSell) { SellBuffer[i] = iHigh(Symbol(), PERIOD_CURRENT, i); ValidSell = false; SellSL = 0.0; SellPrice = 0.0; }
if a signal is correctly sent and the arrow is printed on the currently open candle, then the Boolean changes to false but
on next tick, it again sets the buffers to empty value, and removes the arrow, and the signal disappears!!
apart from this special case i explained above
out of curiosity, why should we initialize the buffers to empty value?! (However i do it myself too!)
every time a new bar is opened, the indicator increases the buffers by one cell, and it allocates zero to it, while i have set that 0 value to indicator empty value
#define EMPTY 0.0
PlotIndexSetDouble(bufferIndex, PLOT_EMPTY_VALUE, EMPTY);
so even with not initializing arrow buffers to empty values, it should draw nothing, not strange arrows on strange places!!
once sending the signal, it turns those flags to false and searches for new cycles
If that is the case you have to define buffers for ValidBuy and ValidSell and reinitialize them to the previous bar value at every iteration...
for(int i=count-1; i>=0 && !IsStopped(); i--) { SellBuffer[i]=EMPTY_VALUE; BuyBuffer[i]=EMPTY_VALUE; ValidBuy[i] = ValidBuy[i+1]; ValidSell[i] = ValidSell[i+1]; ...
out of curiosity, why should we initialize the buffers to empty value?! (However i do it myself too!)
Use of uninitialized variables is prohibited as you cannot know what value they are holding at start. The piece of code to initialize those values does not run on every bar during execution. Other than that the value may change several times during the current bar evolution. All these can cause unwanted data to be stored.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi everyone
i have an issue with my indicator, the arrow buffer is filling with some strange values that draws wrong signals on charts
here is the issue picture
and here is the code:
thanks in advance