help with time of cross - page 2

 
WHRoeder:

Thanks for responding

first of all, I confirm that the SRC below your quotes, not mine, because compared with my code, spare:


datetime time = TimeCurrent();

about the explanation you give me timecrossSELL function (); understand that not well done, then you can be like this:

timecrossSELL ()        
{
Timecurrent ();  
}



Sorry if I do not understand is that language is a big barrier, lol,

you think what I'm searching is necessary to use the TimeCurrent, or can I use another function, which I compare the crossing time with another time.
is that I can not think of another

THANKS

 
Latino:
Thanks for responding

first of all, I confirm that the SRC below your quotes, not mine, because compared with my code, spare:



about the explanation you give me timecrossSELL function (); understand that not well done, then you can be like this:

No.

You need to read about and understand function return values . . .
 
Latino:

deVries, thanks,

the code of calcule of cross of MA`s is this: no have more

and no understand how can to do it, without take the time, thanks

   double MAR = iMA(NULL, 0, 12, 0, 1, PRICE_CLOSE, 0);
   double MAL = iMA(NULL, 0, 84, 0, 1, PRICE_CLOSE, 0);

take the moment that 2 EMAs cross, when happend the cross, wait 3 or 4 candles and in this moment do a sell or buy.

this is what you want to do .....

if we check the value at bar 0 of the two MA's we know that we do it with the lines above you gave

This can give also the information to find out

if ( MAR > MAL ) we have to check at what first bar in the past situation was MAR < MAL and we know the moment it crossed last time

......

also

if ( MAR < MAL ) we have to check at what first bar in the past situation was MAR > MAL and we know the moment it crossed last time

we have to calculate also

until firstcross or 3 or 4 candles + 1

   double MAR[i] = iMA(NULL, 0, 12, 0, 1, PRICE_CLOSE, i);
   double MAL[i] = iMA(NULL, 0, 84, 0, 1, PRICE_CLOSE, i);

now you have to find out what first bar situation bar 0 is opposite of bar i

if situation happend MAR > MAL at bar 0 and MAR[i] < MAL[i]

 

When you have determined the cross has happened

static datetime bear_cross_time = Time[0]   //store open time of cross bar

Then if the last cross was more than 3 bars ago

if( iBarShift(NULL,0,bear_cross_time,true) ) > 3   //cross was more than 3 bars ago
{
 //make sell trade
 //reset bear_cross_time to zero
}
 
SDC:

When you have determined the cross has happened

Then if the last cross was more than 3 bars ago


thanks, but


if put this code:

static datetime  bear_cross_time = Time[0];

= imagen


..........................................................

deVries 2014.01.01 14:23 #



thank you, but i not understand, i am sorry.

 
Latino:

thanks, but


if put this code:

Where is the ; at the end ?

 
RaptorUK:

Where is the ; at the end ?


yes,


static datetime  bear_cross_time = Time[0];
 
Latino:

yes,


And it works now ? you can only initialise a static or global scope variable with a constant . . .

static datetime  bear_cross_time = 0;

bear_cross_time = Time[0];
 
Latino:

deVries 2014.01.01 14:23 #



thank you, but i not understand, i am sorry.


The code of SDC is not needed

you wanna check when happend the cross, wait 3 or 4 candles and in this moment do a sell or buy.

this function i give

  • 0 means nosignal
  • 1 buysignal
  • 2 sellsignal
extern int candelwait = 3;


int CheckCross()
{
   int i;
   double MAR = iMA(NULL, 0, 12, 0, 1, PRICE_CLOSE, 0);
   double MAL = iMA(NULL, 0, 84, 0, 1, PRICE_CLOSE, 0);
   double MARi = MAR;
   double MALi = MAL;
   
   if (MAR > MAL)
    {
    while (MARi > MALi)
        {
        i++;
        MARi = iMA(NULL, 0, 12, 0, 1, PRICE_CLOSE, i);
        MALi = iMA(NULL, 0, 84, 0, 1, PRICE_CLOSE, i);
        }
    if((MARi < MALi)&&(i == candelwait + 1))return(1);     
    }
    
   if (MAR < MAL)
    {
    while (MARi < MALi)
        {
        i++;
        MARi = iMA(NULL, 0, 12, 0, 1, PRICE_CLOSE, i);
        MALi = iMA(NULL, 0, 84, 0, 1, PRICE_CLOSE, i);
        }
    if((MARi > MALi)&&(i == candelwait + 1))return(2);     
    }
   return(0);   
}
int Signal = CheckCross();
if(Signal == 1)  .....    //Open buy
if(Signal == 2)  .....    //Open sell

 
That was my fault I apologize I didnt check that code I just typed it into the src box and forgot about the intialization rule.
Reason: