Download MetaTrader 5
To add comments, please log in or register
Track Market top sellers!
Brok123
11
Brok123 2016.08.06 08:00 
Hello

 Where is the problem with the small code below.

Idea is to buy after a candle crosses "overSold".

 

Do you have a code which functiones (regardless of indicator). I need to find principle for "candle crossing"...

 

 

 

 


int start()
{

//----
if(Bars<=RSIPeriod) return(0);
//----

i=RSIPeriod;
//---- We here below fill buffer with RSI values

while(i>=0)
{
RSIBuffer[i]=iRSI(NULL,0,RSIPeriod,ApplyTo,i);

i--;
}

//--Below the criteria which check new bar started

 

if(IsItNewBar())
{




int result=0;
int OneCandleAgoCloseRSI = RSIBuffer[1];
int TwoCandlesAgoCloseRSI = RSIBuffer[2];


if(TwoCandlesAgoCloseRSI >= OverSold && OneCandleAgoCloseRSI < OverSold)
   {
   result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0," BROK123",MagicNumber, 0,Blue);
   if(result>0)
   {

OrderSelect(result,SELECT_BY_TICKET );
OrderModify(OrderTicket(),OrderOpen Price(),NormalizeDouble(TheStopLoss ,Digits),NormalizeDouble(TheTakePro fit,Digits),0,Green);
   }
   return(0);
   }

//----closing area s new bar 

 

return(0);

}

 

//----closing start area

 

bool IsItNewBar()
{
static datetime lastTime;
bool IsNewBar = (Time[0] != lastTime);
lastTime = Time[0];
return(IsNewBar);
peter.MT4Web
158
peter.MT4Web 2016.08.06 08:30  
If you are so kind to tell us what your problem is, maybe we are able to tell you where it is.
Brok123
11
Brok123 2016.08.06 08:41  

Actually I ran it on M1 DAX and on Tester.

Buy does not occur in whole year even with RSI overSold value 45

 

Thank you a lot in advance 

 

kindest regards

Keith Watford
Moderator
7985
Keith Watford 2016.08.06 11:43  

Why are you calculating the RSI values every tick when you are only using them when a new bar forms?

Buffers are used in indicators, not EAs, naming an array with "Buffer" in its name can be confusing. Why use an array anyway, you only check 2 values.

You can cut out

i=RSIPeriod;
//---- We here below fill buffer with RSI values

while(i>=0)
{
RSIBuffer[i]=iRSI(NULL,0,RSIPeriod,ApplyTo,i);

i--;
}

completely

and just use

int OneCandleAgoCloseRSI = iRSI(NULL,0,RSIPeriod,ApplyTo,1);
int TwoCandlesAgoCloseRSI = iRSI(NULL,0,RSIPeriod,ApplyTo,2);

instead of

int OneCandleAgoCloseRSI = RSIBuffer[1];
int TwoCandlesAgoCloseRSI = RSIBuffer[2];


Your code should place trades unless you have something like incorrectly sized array

whroeder1
13641
whroeder1 2016.08.06 19:41  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Just get the two values as GumRai suggested after you have a new bar.
  3. Does RSIBuffer have a size? It's not a buffer. Don't use misleading names.
  4. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Brok123
11
Brok123 2016.08.06 22:39  

GumRai

YOUR SOLUTION WORKS!!! Thank you a lot!!!

Pitty this forum does not have points,so I could give you highest grades

Is there anything I can do for you?

You saved me days od researching. Maybe you have email?

 

kindest regards 

/
To add comments, please log in or register