why Start function doesn.t start ?!

 

Hi

I wrote a very simple EA and it works in tester properly but it doesn't work as i attach that to a chart .

EA is successfully loaded but the first line of start function (a comment line) is never executed.

Is there any specific Error or mistake in programing that cause such a condition ?

I would be very grateful for your help.

Thanks

 
hemmat wrote >>

Hi

I wrote a very simple EA and it works in tester properly but it doesn't work as i attach that to a chart .

EA is successfully loaded but the first line of start function (a comment line) is never executed.

Is there any specific Error or mistake in programing that cause such a condition ?

I would be very grateful for your help.

Thanks

Show us the code. we can not comment on it if we do not know what you are doing.

whocares

 

1. Could it be that you were trying to get it to work over the weekend when there were no incoming ticks to trigger the Start function (as the market was closed)?

2. Are EAs enabled in the client platform?


Otherwise, as whocares says - we'd need to see the code.


CB

 
This is the code.Its my first ea if it could be named so !


//+------------------------------------------------------------------+
//| MyFirst.mq4 |
//| Copyright © 2009,Hojjat Hemmat |
//| http://www.HojjatHemmat.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009,Hojjat Hemmat"
#property link "http://www.HojjatHemmat.com"
extern double fst=25;
extern double dm=1.382;
extern double lsm=2;
extern double inils=0.1;
extern int mex=9;
extern int hpn=4;
extern int hps=50;
extern int tpip=50;
extern int slpip=25;
static double fx[50][15];
static double sp=7;
static double min,max,minpip,maxpip,initAsk,initBid;
static int i,j,maxindex,handle;
static int ticketBu1,ticketBu2,ticketBe1,ticketBe2,o;
static int Bumgc=1;
static int Bemgc=2;
double prof;
static int buAct,beAct,butrNo,betrNo,Recoflag;
static string symb;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
sp = 7;
fx[0][0] = 0; fx[0][ 1] = 0; fx[0][2] = 1; fx[0][3] = inils; fx[0][4] = 0;
fx[0][5] = inils; fx[0][6] = 0; //; fx[0][ 7) = 0.01; fx[0][ 8) = -0.14
double pop = 0;
for (i = 1;i<= mex;i++)
{
pop += fst * MathPow(dm, (i - 1));
fx[i][0] = i;
fx[i][1] = MathRound(pop/fst) * fst;// Pip
fx[i][2] = 1; //Code
fx[i][3] = inils * MathPow(lsm, i);
fx[i][4] = 0;
fx[i][5] = fx[i - 1][ 5] + fx[i][ 3];
fx[i][6] = 0;
fx[i][7] = fx[i - 1][7] + fx[i][3] * fx[i][1];
fx[i][8] = MathFloor(((fx[i][7] - fx[i][5] * sp) / fx[i][5] - tpip)*10)/10;
fx[i][9]=proFit(i,fx[i][8]);
}
for (i = mex + 1;i<= mex + hpn;i++)
{
fx[i][0] = i;
fx[i][1] = fx[i - 1][1] + hps;
fx[i][2] = 2 ;
fx[i][3] = 0;
fx[i][4] = MathFloor((fx[mex][5] / hpn)*10)/10;
fx[i][5] = fx[i - 1][5] + fx[i][3];
fx[i][6] = fx[i - 1][6] + fx[i][4];
fx[i][7] = fx[i - 1][7] - fx[i][4] * fx[i][ 1];
if (fx[i][5] != fx[i][6])fx[i][8] = MathFloor(((fx[i][7] - fx[i][5] * sp) / (fx[i][5] - fx[i][6]) - tpip)*10)/10;
else fx[i][8] = MathFloor((fx[i][7] - fx[i][5] * sp) / (fx[i][5] - fx[i][6]) - tpip);
fx[i][9]=proFit(i,fx[i][8]);
}
maxindex = mex + hpn;
maxpip = fx[maxindex][1];
double tv=MarketInfo(Symbol(), MODE_TICKVALUE);
//Finding Min & Max Profit point
for (i = 1;i<= maxindex;i++)
{
// Alert ("i=",i," Max index=",maxindex);
min = 50000; max = -50000;
for (j = fx[maxindex - 1][8] - 100;j<= fx[i][1];j++)
{
prof = proFit(i, j)*tv;
if (prof > max)
{
max = prof;
maxpip = j;
}
if (prof < min)
{
min = prof;
minpip = j;
}
}
fx[i][10] = maxpip;
fx[i][11] = MathFloor(max);
fx[i][12] = minpip;
fx[i][13] = MathFloor(min);
// Alert(" Maxpip=",maxpip," Max=",max," Minpip=",minpip," Min=",min) ;
}
for(i=0;i<=maxindex;i++)
{
fx[i][14]=0;
for(j=0;j<=i;j++)
{
if(fx[j][2]==1) fx[i][14]+=(fx[i][1]-fx[j][1]+sp)*fx[j][3]*tv;
if(fx[j][2]==2) fx[i][14]+=(fx[j][1]-fx[i][1]+sp)*fx[j][4]*tv;
}
fx[i][14]=NormalizeDouble(fx[i][14],2);
}
symb=Symbol();
Recoflag=0;
Recovery();
if (Recoflag==0){buAct=0;beAct=0;butrNo=-1;betrNo=-1;}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{

//----
Comment("Main Function is Now Running ButrNo=",butrNo," BetrNo=",betrNo);
if (butrNo==-1 || betrNo==-1)
{
// Alert("Begin at Start");
if(butrNo==-1)
{
// FileWrite(handle,"New Bullish Position Set With Magic No ",Bumgc);
initBid=Bid;
ticketBu1=OrderSend (symb,OP_SELL,inils,Bid,3,0,0,NULL,Bumgc);
o=GetLastError();
if(o==0)
{
butrNo++;
// FileWrite(handle,ticketBu1,"Sell",inils,Bid,Bumgc);
// Alert("Position:",TOT," Volume =",inils," Type=OP_SELL Ticket=",ticket1," Price =",Bid);
}
}

if(betrNo==-1)
{
// FileWrite(handle,"New Bearish Position Set With Magic No ",Bemgc);
initAsk= Ask;
ticketBe1= OrderSend (symb,OP_BUY,inils,Ask,3,0,0,NULL,Bemgc);
o=GetLastError();
if(o==0)
{
betrNo++;
// FileWrite(handle,ticketBe1,"Buy",inils,Ask,Bemgc);
// Alert("Position:",TOT," Volume =",inils," Type=OP_BUY Ticket=",ticket2," Price =",Ask);
}
}
}

//----
return(0);
}

double proFit(int a,int b)
{
double pr = 0;
double price = b;
for (int h = 0;h<= a;h++) pr = pr + ((price - fx[h][1]) * fx[h][4]) - ((price - fx[h][1]) * fx[h][3]);
return(pr);
}
//+---------------------------------------------+
//|-- Recovery of Previous Positions at Start --|
//+---------------------------------------------+
void Recovery()
{
int i,totr;
int mgc,mg;
int evnumber=0;
int odnumber=0;
totr=OrdersTotal();
for (i=1;i<=totr;i++)
{
int ihh=OrderSelect(i-1,SELECT_BY_POS);
mgc=OrderMagicNumber();
mg=mgc%2;
if (mg==0 && mgc>0) evnumber++;
if (mg==1) odnumber++;
}
butrNo=odnumber%(maxindex+1)-1;
betrNo=evnumber%(maxindex+1)-1;
if (totr>0 &&(butrNo>=0 || betrNo>=0))Recoflag=1;
return(0);
}


I don't understand why, but sometimes without any basic change an ea works (with just deleting some comments)!!

This code doesn't work in real trade but works in tester in addition it doesn't allow 0.01 lot sizes while before adding recovery part it was possible to do that.

I'm using UFX Trader(Union Forex Broker) and 0.01 Lot size is allowed.

How it is possible that it differ from time to time.

Thank you cloudbreaker and whocares for your care.

Best wishes

 
hemmat wrote >>

I don't understand why but without any basic change it works (I just deleted some comments)!!

But this time it doesn't allow 0.01 lot sizes while before adding recovery part it was possible to do that.

I'm using UFX Trader(Union Forex Broker) and 0.01 Lot size is allowed.

How it is possible that it differ from time to time.

Thank you cloudbreaker and whocares.

Best wishes


Verify that your 0.01 lot is allowed by checkiing it:

Print (MarketInfo(Symbol(), MODE_MINLOT));

This will show you the minimum lot allowed in the account you are using.

whocares

 
whocares:

Verify that your 0.01 lot is allowed by checkiing it:

Print (MarketInfo(Symbol(), MODE_MINLOT));

This will show you the minimum lot allowed in the account you are using.

whocares

it shows 0.1 but i was running this code with 0.01 Lot size 2 nights ago,is it possible ?

Do you think that the brocker has changed it ?

 
hemmat wrote >>

it shows 0.1 but i was running this code with 0.01 Lot size 2 nights ago,is it possible ?

Do you think that the brocker has changed it ?

If it is the same account then yes it appears as though the account has been changed by the broker.

You will have to contact the broker and ask about it.

Also read the t's and 's of the contract behind the account. If it is a demo account the terms should be on line.

Good luck.

whocares

 
whocares:

If it is the same account then yes it appears as though the account has been changed by the broker.

You will have to contact the broker and ask about it.

Also read the t's and 's of the contract behind the account. If it is a demo account the terms should be on line.

Good luck.

whocares

Thanks.

one part of problem refers to demo account as you recognized .(there was different minlots in real(0.01) and demo(0.1) accounts)

Did you see the code?(i don't know how to attach the file so i pasted it.)

is there any problem that prevents start function from functioning ?

 

Got errors?

Try Print instead of Comment

 
phy:

Got errors?

Try Print instead of Comment

Hi phy

The problem is that the first line of start function is not executing at all no matter that it is comment or print.

in what circumstances it can happen ?!

I searched every line of init function but there was not any error that i could find in addition it works in strategy tester.

Do you experienced such a situation ?

if yes, what was the cause.


 
hemmat wrote >>

Hi phy

The problem is that the first line of start function is not executing at all no matter that it is comment or print.

in what circumstances it can happen ?!

I searched every line of init function but there was not any error that i could find in addition it works in strategy tester.

Do you experienced such a situation ?

if yes, what was the cause.

Hi hemmat

I copied the code as you produced it into a blank ea and dropped it on a chart in a demo account.

Observations:

1) The comment note (1st line of the Start function) works as it desplays on the chart.

2) The ea immediately (on start) opens a short trade

As you can see the calues you try to display in the Comment function show 0 for both.

if they are not supposed to be 0 you should look at how (and when) they are calculated.

whocares

Reason: