Hey
Rick, I'm glad you're doing this.
What's the code for crossing of two 2-line indicators? I'm sure it isn't really difficult. Say, the 1st indicator's lines cross each other 1 bar before [MAIN > SIGNAL] = BUY order, 2nd indicator's lines cross one another [MAIN < SIGNAL] = SELL order.
What I came up with is this, but it just doesn't cut it.
Code:
if (Time[0] == prevtime)
return(0);
prevtime = Time[0];
//IND1 = iIND1 (NULL, 0, 0, MODE_MAIN, 0); mentioned later
//IND1S = iIND1 (NULL, 0, 0, MODE_SIGNAL, 0); mentioned later
IND2 = iIND2 (NULL, 0, 0, MODE_MAIN, 0); // how to go about these two?
IND2S = iIND2 (NULL, 0, 0, MODE_SIGNAL, 0); // how to go about these two?
Taking into consideration
Guru's approach, [with some minor changes and fixed
direction b/c it's misspelled all over the lesson

]
Code:
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up
if(line1<line2)current_direction = 2; //down
if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
IND1 = iIND1 (NULL, 0, 0, MODE_MAIN, 0);
IND1S = iIND1 (NULL, 0, 0, MODE_SIGNAL, 0);
int isCrossed = Crossed (IND1 ,IND2);
if(isCrossed == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Yikes! You're screwed! Get back to the manual!!! Ha! ",GetLastError());
return(0);
}
if(isCrossed == 2)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print(""Yikes! You're screwed! Get back to the manual!!! Ha! "",GetLastError());
return(0);
}
return(0);
}