Download MetaTrader 5
To add comments, please log in or register
Unable to find the answer to your question? Use the search!
pascalboy
238
pascalboy 2014.03.17 07:08 
//FIRST PROGRAM 

extern int K=80;
extern int D=10;
extern int S=15;
extern double A,B,C;

int start()
{
double stoccurrM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,0);
double stocprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,1);
double stocprevprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,2);

double stoccurrS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,0);
double stocprevS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,1);
double stocprevSS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,2);

double macd=iMACD(Symbol(),0,12,26,9,0,0,0);
double pmacd=iMACD(Symbol(),0,12,26,9,0,0,1);
double rsi=iRSI(Symbol(),0,14,0,0);

if(stoccurrS>stocprevS&&stocprevS<stocprevSS&&rsi<60&&macd<0)
{

A=Ask;

}
if(stoccurrS<stocprevS&&stocprevS>stocprevSS&&rsi>40&&macd>0)
{
B=Bid;
if(fiy1>0&&fiy1tersi>0)
{
C=(fiy1tersi-fiy1)*100;
Print(C);
A=0;
B=0;
}
}








return;
}


























//SECOND PROGRAM



 


extern int K=80;
extern int D=10;
extern int S=15;
int start()
{
double stoccurrM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,0);
double stocprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,1);
double stocprevprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,2);

double stoccurrS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,0);
double stocprevS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,1);
double stocprevSS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,2);

double macd=iMACD(Symbol(),0,12,26,9,0,0,0);
double pmacd=iMACD(Symbol(),0,12,26,9,0,0,1);
double rsi=iRSI(Symbol(),0,14,0,0);

if(stoccurrS>stocprevS&&stocprevS<stocprevSS&&rsi<60&&macd<0)
{
double A=Ask;

}
if(stoccurrS<stocprevS&&stocprevS>stocprevSS&&rsi>40&&macd>0)
{
double B=Bid;
if(A>0&&B>0)
{
double C=(A-B)*100;
Print(C);
A=0;
B=0;
}
}


return;
}



Hello,


there are two simple programs above .
The difference between them is just the declaration of A ,B,C variables.
Why the are Printing values of "C" different?
What are logical differences between them .

Keith Watford
Moderator
7887
Keith Watford 2014.03.17 07:23  

How would we know?

We dont know what the values of these variables are

if(fiy1>0&&fiy1tersi>0)
{
C=(fiy1tersi-fiy1)*100;
pascalboy
238
pascalboy 2014.03.17 09:42  
//FIRST PROGRAM 

extern int K=80;
extern int D=10;
extern int S=15;
extern double A,B,C;

int start()
{
double stoccurrM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,0);
double stocprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,1);
double stocprevprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,2);

double stoccurrS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,0);
double stocprevS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,1);
double stocprevSS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,2);

double macd=iMACD(Symbol(),0,12,26,9,0,0,0);
double pmacd=iMACD(Symbol(),0,12,26,9,0,0,1);
double rsi=iRSI(Symbol(),0,14,0,0);

if(stoccurrS>stocprevS&&stocprevS<stocprevSS&&rsi<60&&macd<0)
{

A=Ask;

}
if(stoccurrS<stocprevS&&stocprevS>stocprevSS&&rsi>40&&macd>0)
{
B=Bid;
if(A>0&&B>0)
{
C=(B-A)*100;
Print(C);
A=0;
B=0;
}
}








return;
}


























//SECOND PROGRAM






extern int K=80;
extern int D=10;
extern int S=15;
int start()
{
double stoccurrM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,0);
double stocprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,1);
double stocprevprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,2);

double stoccurrS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,0);
double stocprevS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,1);
double stocprevSS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,2);

double macd=iMACD(Symbol(),0,12,26,9,0,0,0);
double pmacd=iMACD(Symbol(),0,12,26,9,0,0,1);
double rsi=iRSI(Symbol(),0,14,0,0);

if(stoccurrS>stocprevS&&stocprevS<stocprevSS&&rsi<60&&macd<0)
{
double A=Ask;

}
if(stoccurrS<stocprevS&&stocprevS>stocprevSS&&rsi>40&&macd>0)
{
double B=Bid;
if(A>0&&B>0)
{
double C=(B-A)*100;
Print(C);
A=0;
B=0;
}
}


return;
}

pascalboy
238
pascalboy 2014.03.17 09:44  

Very Big Sorry,

Right scripts are above

i hope ;)

Keith Watford
Moderator
7887
Keith Watford 2014.03.17 10:04  

When you declare a double, that declaration only applies to the block of code that contains it

if(stoccurrS>stocprevS&&stocprevS<stocprevSS&&rsi<60&&macd<0)
{
double A=Ask;

}

Outside of that block, the value is lost and you will probably have an error report from the compiler about the undeclared variable. Declare it outside of the block

double A
if(stoccurrS>stocprevS&&stocprevS<stocprevSS&&rsi<60&&macd<0)
{
A=Ask;

}
pascalboy
238
pascalboy 2014.03.18 07:44  
//FIRST PROGRAM 

extern int K=80;
extern int D=10;
extern int S=15;
extern double A,B,C,SUMC;

int start()
{
double stoccurrM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,0);
double stocprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,1);
double stocprevprevM=iStochastic(Symbol(),0,K,D,S,0,0,MODE_MAIN,2);

double stoccurrS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,0);
double stocprevS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,1);
double stocprevSS=iStochastic(Symbol(),0,K,D,S,0,0,MODE_SIGNAL,2);

double macd=iMACD(Symbol(),0,12,26,9,0,0,0);
double pmacd=iMACD(Symbol(),0,12,26,9,0,0,1);
double rsi=iRSI(Symbol(),0,14,0,0);

if(stoccurrS>stocprevS&&stocprevS<stocprevSS&&rsi<60&&macd<0)
{

A=Ask;                                             //-------------------------------IF YOU ADD BUY ORDER

}
if(stoccurrS<stocprevS&&stocprevS>stocprevSS&&rsi>40&&macd>0)
{
B=Bid;		                                      //-------------------------------IF YOU ADD CLOSE -BUY ORDER
if(A>0&&B>0)
{
C=(B-A)*100;
SUMC=SUMC+C;
Print(SUMC);
A=0;
B=0;
}
}








return;
}

I solved it with extern variables but i did not understand the logic.
When you calculate "C " and add it one by one the result will be printingin to SUMC.And the SUMC is very big positive .
With the same logic ,
At the "Ask" block ,if you add BUY order ,and at the "Bid" block if you  CLOSE this  order .
Its strategy tester loses money.

Logic is the same i think .
//
B-A =C or Closing Price of Buy -Open Price of Buy =Profit of the account.

But it differs a big...




And loses money.

qjol
3243
qjol 2014.03.18 08:00  
regardless why don't you use SYMBOL_SPREAD or MODE_SPREAD instead of B-A*100
pascalboy
238
pascalboy 2014.03.18 08:04  
I think it is not about spreads.
pascalboy
238
pascalboy 2014.03.18 08:06  

It is about strategy of buy and strategy of close points differ when you use buy -close orders.

/
To add comments, please log in or register