question about Drawing arrows using iBarshift

question about Drawing arrows using iBarshift

Manage alerts

Loading saved threads...

Sam · External communityPost link
External question — Stack Overflow Stack Exchange Author: Sam Original post: https://stackoverflow.com/questions/68549543 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am trying to draw Arrows Based on another indicator's signal from higher timeframe, but the problem i am facing is that it draws the arrow on multiple candles For example : If I check the arrow visibility on W1 timeframe and have the my indicator draw the arrow on D1 timeframe it will draw 5 arrows on 5 daily candles for the weekly candle where the arrow appeared , but i cant figure out how to limit it to only place the arrow on one candle and not all five. here is my code: for(int i = limit-1; i >= 0; i--) { int barshift_W1 = iBarShift(Symbol(), PERIOD_W1, Time[i]); if(barshift_W1 < 0) continue; //Indicator Buffer 1 if(iCustom(NULL, PERIOD_W1, "Arrow Indicator", 0, barshift_W1) != EMPTY_VALUE ) { Buffer1[i] = iLow(NULL, PERIOD_W1, barshift_W1) - iATR(NULL, PERIOD_CURRENT, 14, i); } else { Buffer1[i] = EMPTY_VALUE; } //Indicator Buffer 2 if(iCustom(NULL, PERIOD_W1, "Arrow Indicator", 1, barshift_W1) != EMPTY_VALUE ) { Buffer2[i] = iHigh(NULL, PERIOD_W1, barshift_W1) + iATR(NULL, PERIOD_CURRENT, 14, i); } else { Buffer2[i] = EMPTY_VALUE; } }
Quote
Report
Investing TS · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Investing TS Original post: https://stackoverflow.com/a/69836710 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Try this code below. I haven't tested it, but the concept is, if you're not on a W1 chart, you want to only draw an arrow once on the first bar of the week, probably...: for(int i = limit-1; i >= 0; i--) { int barshift_W1 = iBarShift(Symbol(), PERIOD_W1, Time[i]); if(barshift_W1 < 0) continue; //Indicator Buffer 1 if(iCustom(NULL, PERIOD_W1, "Arrow Indicator", 0, barshift_W1) != EMPTY_VALUE && (Period()==PERIOD_W1 || i != limit-1 && (i * Period() / 10080 != (i+1) * Period() / 10080) ) { Buffer1[i] = iLow(NULL, PERIOD_W1, barshift_W1) - iATR(NULL, PERIOD_CURRENT, 14, i); } else { Buffer1[i] = EMPTY_VALUE; } //Indicator Buffer 2 if(iCustom(NULL, PERIOD_W1, "Arrow Indicator", 1, barshift_W1) != EMPTY_VALUE && (Period()==PERIOD_W1 || i != limit-1 && (i * Period() / 10080 != (i+1) * Period() / 10080) ) { Buffer2[i] = iHigh(NULL, PERIOD_W1, barshift_W1) + iATR(NULL, PERIOD_CURRENT, 14, i); } else { Buffer2[i] = EMPTY_VALUE; } }
Quote
Report

Post Reply

Checking account access…