Hello
I have created a code as below.
I wish to have result for" myCounter>=5";but i am not getting that.
I have applied all indicators manually and checked and result is coming but code is giving wrong result.
What could be the error.
Pl help .
Thanks in advance.
protected override void OnBarUpdate()
{
if (CurrentBar<180)
return;
int myCounter = 0;
if (Wealth1(Close).Bullish[0]>0) ++myCounter; // increment counter
else if (Wealth2(Close).Bullish[0]>0)++ myCounter; // increment counter
else if (Wealth3(Close).Bullish[0]>0)++ myCounter; // increment counter
else if (Wealth4(Close).Bullish[0]>0)++ myCounter;// increment counter
else if (Wealth5(Close).Bullish[0]>0) ++myCounter;
else if (Wealth6(Close).Bullish[0]>0) ++myCounter;
else if (Wealth7(Close).Bullish[0]>0)++ myCounter;
else if (Wealth8(Close).Bullish[0]>0)++ myCounter;
else if (Wealth9(Close).Bullish[0]>0)++ myCounter;
else if (Wealth10(Close).Bullish[0]>0)++ myCounter;
else if (Wealth11(Close).Bullish[0]>0)++ myCounter;
else if (Wealth12(Close).Bullish[0]>0)++ myCounter;
else if (Wealth13(Close).Bullish[0]>0)++ myCounter;
else if (Wealth14(Close).Bullish[0]>0)++ myCounter;
else if (Wealth15(Close).Bullish[0]>0)++ myCounter;
else if (Wealth16(Close).Bullish[0]>0)++ myCounter;
else if (Wealth17(Close).Bullish[0]>0)++ myCounter;
else if (Wealth18(Close).Bullish[0]>0)++ myCounter;
else if (Wealth19(Close).Bullish[0]>0)++ myCounter;
else if (Wealth20(Close).Bullish[0]>0)++ myCounter;
if (myCounter >=5 )
{
Bullish[0] = Low[0]-TickSize;
}
}
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
is unreachable. myCounter is never greater than 1.
Do you intend to check all 20 closing values every time you call the function, or do you really mean to check later values only if preceding values are less than 0 (what you’re currently doing)?
This is a trading indicator and when i apply this indicator on the chart it should give me bullish signal whenever “myCounter>=5”
This indicator may be applied on real time data charts.
Kindly advise.
Thanks.
Thanks for the reply.
I assume you say Keep “If " and Remove"If Else” statements.
Am i right?
I have tried that also…but still result is not greater than 1.
What could be wrong?
Many thanks for help.
We don’t see enough of your code to be sure aboutwwhat’s going on here. At the very least you chose your data structures poorly and it’s making reading and debugging your code extremely difficult. Why don’t you have an array of these Wealth variables?
Thanks for the reply.
In case debugging is needed;let me check all the arrays of Wealth and get it debugged.
I will come back post debugging.(Huge length of code)
Thanks.
What I meant is that the way you are managing your variables is making a debugging nightmare for you. You have 20 nearly identical lines of code with the exception of the variable names, which is an indication that you should put the variables in an array and iterate over that array. Repeating identical lines for different variables is a huge red flag.