Counter variable keep increasing in OnTick

 

Dear All , 

I'm facing my daily struggling with MQL4. I need to update a counter variable ONCE every time a condition is met.

I have created a 2D array which list all lot sizes and I'm trying to select those sizes according to OrderProfit <> 0. 


For example :

Size[count1][count2];

if(OrderProfit() > 0)  count1 ++ ; if (OrderProfit() < 0) count2 ++.

if(count1 == x || count2 == x)

count1 = 0

count2 = 0


The thing is , once a condition is met in OnTick () the counter variable keep increasing endlessly(of course).

Is there a way to fix this issue ?  Thank you very much indeed.


 
claudio.zeccolella:

Dear All , 

I'm facing my daily struggling with MQL4. I need to update a counter variable ONCE every time a condition is met.

I have created a 2D array which list all lot sizes and I'm trying to select those sizes according to OrderProfit <> 0. 


For example :

Size[count1][count2];

if(OrderProfit() > 0)  count1 ++ ; if (OrderProfit() < 0) count2 ++.

if(count1 == x || count2 == x)

count1 = 0

count2 = 0


The thing is , once a condition is met in OnTick () the counter variable keep increasing endlessly(of course).

Is there a way to fix this issue ?  Thank you very much indeed.


Show the actual OnTick code, it could be a typo, in your example, count2 would always be resetted since you forgot to put braces around the if statement:

if(count1 == x || count2 == x)  {
  count1 = 0
  count2 = 0
}
I am suspecting you are doing the same error on the actual code.