How do i shorten this code
bool conditionMet=true; int x=0; for(; x<=9; x++) { double emaTrend = iMA (NULL,0,200,0,MODE_EMA,PRICE_CLOSE,x); if (emaTrend > High[x]) continue; else { conditionMet=false; break; } } if(conditionMet) Print("Sell Signal"); else Print("No Sell Signal");
This may give you a few ideas how to shorten your code.
Incidentally, it can be shortened further.
Often in my codes I will actually look for when a condition is NOT met
for(; x<=9; x++) { double emaTrend = iMA (NULL,0,200,0,MODE_EMA,PRICE_CLOSE,x); if (emaTrend <= High[x]) { conditionMet=false; break; } }
Incidentally, it can be shortened further.
Often in my codes I will actually look for when a condition is NOT met
What would be the purpose of break, the loop would only run when all of the conditions met isn't it?
bool trend() { bool status; int i; for (i=0; i<10; i++) { double emaTrend = iMA (NULL,0,200,0,MODE_EMA,PRICE_CLOSE,i); if (emaTrend > High[i]) { status = true; } else if (emaTrend <Low[i]) { status = false; } return status; }
What would be the purpose of break, the loop would only run when all of the conditions met isn't it?
The execution of the loop has nothing to do with any conditions.
When it is found that one EA is smaller than the high, there is no point in continuing with the loop. Hence the break.
else if (emaTrend <Low[i])
Why do you have this?
The Low doesn't figure in your outline at all!
Why do you have this?
The Low doesn't figure in your outline at all!
I've been trying out things but i really can't seem to figure it out, i tried doing loops but i'm probably doing something wrong.
What i wanted to happen is to only do a sell signal when all 10 candles is below the moving average.
Here is the photo to visualize more : https://ibb.co/LtHDPhp