I am trying to enable my ea if spread is ok and if ea loses 3 times in a row the ea is disable.
Lucas Santana:
Hi, as the title says I am trying to do a spread check and if ea loses 3 times in a row the ea stop working. I dont know why it is not workinnng. Any help will be much appreciated. I will be using my ea just for forex.
- declare on global for; static int LosCount = 0;
- use void OnTick()
- you check the whole history & whole symbol
- ...
Mohamad Zulhairi Baba:
- declare on global for; static int LosCount = 0;
- use void OnTick()
- you check the whole history & whole symbol
- ...
Thanks for the answer sir. Did some changes I think its working now
Here is the new code.
static bool lossesS=false;
static int losses=0;
static int spread=0;
static bool SpreadCount=false;
void init() {
}
void deinit() {
}
void OnTick() {
for(int i=0; i<OrdersHistoryTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if (OrderCloseTime() < 1) continue; // redundant check :D
if(OrderProfit()<=0) losses++;
else losses=0;
}
if(losses==3) //ALTERAR AQUI CONSECUTIVE LOSS
{
Comment("derrotas consecutivas");
//PlaySound("Alert.wav");
lossesS=true;
}
if (losses<3) //ALTERAR AQUI CONSECUTIVE LOSS
{
Comment("ea funcionando");
lossesS=false;
}
spread = (Ask-Bid)*100000;
if (StringFind(Symbol(), "JPY") >= 0) {
spread = (Ask-Bid)*1000;
}
if (StringFind("JPY",Symbol()) >= 0){
spread = (Ask-Bid)*1000;
}
if(spread<30) //ALTERAR AQUI A SPREAD EM PIPPETES
{
SpreadCount=false;
}
else{
Comment("spread alta");
SpreadCount=true;
}
if(lossesS==false && SpreadCount==false) // only submit orders if last order was not a loss
{
Hi, as the title says I am trying to do a spread check and if ea loses 3 times in a row the ea stop working. I dont know why it is not workinnng. Any help will be much appreciated. I will be using my ea just for forex.