kei41202: But it always count a zero as result. The following is my code.
int Bull; int Bear; for(int i=1; i<CandlesToRetrace;i++){ if(Close[i]>Open[i]) Bull++; else (Bear++); | I doubt it's always zero.
|
I doubt it's always zero.
|
//+------------------------------------------------------------------+ //| BullBear Counter.mq4 | //| Copyright 2017, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict input int CandlesToRetrace =50; int Bull; int Bear; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- for(int i=1; i<CandlesToRetrace;i++) { if(Close[i]>Open[i]) Bull++; else(Bear++); Comment("The Bull and Bear are respectively "+(Bull)+" and"+ (Bear)); } }

- www.mql5.com
kei41202: Is there anyway I can stop it from adding?
| Why would you want to stop? When you start counting what number do you begin with? |
Why would you want to stop? When you start counting what number do you begin with? |
Because it adds up non-stop. Retracing 50 candles, 23 is bull and 27 is bear. However, it doesnt stop there. It just continue to roll to 46 and 54 and so on.
I want to have it static like. It will count again next candle comes. Before that it stays 23-27.
Bull=0; Bear=0; for(int i=1; i<CandlesToRetrace;i++) { if(Close[i]>Open[i]) Bull++; else(Bear++); Comment("The Bull and Bear are respectively "+(Bull)+" and"+ (Bear)); }.
.
You can't add an integer to a string.
Comment("The Bull and Bear are respectively "+(Bull)+" and"+ (Bear)); // adding string to int. // instead use Comment("The Bull and Bear are respectively ",Bull," and ",Bear); // or Comment("The Bull and Bear are respectively "+IntegerToString(Bull)+" and "+IntegerToString(Bear));
You can't add an integer to a string.
That was not my code, so no need to quote me. I simply added the resetting of global-scope variables to zero.
You can add integers to a string but you will get a warning that it will be implicitly converted to a string.
Because it adds up non-stop. Retracing 50 candles, 23 is bull and 27 is bear. However, it doesnt stop there. It just continue to roll to 46 and 54 and so on.
I want to have it static like. It will count again next candle comes. Before that it stays 23-27.
Any solutions in this problem ? How to stop counting ?
Any solutions in this problem ? How to stop counting ?
Yes, in post #5

- 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 guys, got a question that you guys may help me with.
I am trying to make an EA to have a for loop to count the number of bull and bear candles in a range.
But it always count a zero as result. The following is my code.
Any idea?