new with code, but stuck

 
Goal:
when two SMA's cross, i then want to check and continue to check for Stochastics to hit a level, then trade.

my problem:

can only get the code to look at the cross and the Stochastics at the time of the cross. it wont continue to check Stochastics after the cross occurs.
so... if stochastics is not at that level when the cross happens, no trade occurs. want to be able to note that a cross has occurred and continue to check for the stochastics level and trade later...

help please... i'm new at this.

thanks in advance.

here's the code i have so far:

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;
double SEma, LEma,Stoch;
//----
if(Bars < 100)
{
Print("bars less than 100");
return(0);
}
//----
if(TakeProfit < 10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
//----
SEma = iMA(NULL, 30, ShortEma, 0, MODE_LWMA, PRICE_CLOSE, 0);
LEma = iMA(NULL, 30, LongEma, 0, MODE_LWMA, PRICE_CLOSE, 0);
Stoch = iStochastic(NULL,30,Stochastic,dPeriod,slowing,MODE_SMA, 0, MODE_SIGNAL, 0);
//----
static int isCrossed = 0;
isCrossed = Crossed (SEma, LEma);
//----
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
if (SEma>LEma && Stoch>50)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - StopLoss*Point,
Ask + TakeProfit*Point, "EMA_CROSS", 12345, 0, Green);
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("BUY order opened : ", OrderOpenPrice());
}
else
Print("Error opening BUY order : ", GetLastError());
return(0);
}
if((isCrossed == 2) && (SEma<LEma) && (Stoch<50))
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + StopLoss*Point,
Bid - TakeProfit*Point, "EMA_CROSS", 12345, 0, Red);
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("SELL order opened : ", OrderOpenPrice());
}
else
Print("Error opening SELL order : ", GetLastError());
return(0);
}
return(0);
}
//----
for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
 //           if(OrderType() == OP_BUY)   // long position is opened
 
forextrader99:
Goal:
when two SMA's cross, i then want to check and continue to check for Stochastics to hit a level, then trade.

my problem:

can only get the code to look at the cross and the Stochastics at the time of the cross. it wont continue to check Stochastics after the cross occurs.
so... if stochastics is not at that level when the cross happens, no trade occurs. want to be able to note that a cross has occurred and continue to check for the stochastics level and trade later...

help please... i'm new at this.

thanks in advance.

here's the code i have so far:

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;
double SEma, LEma,Stoch;
//----
if(Bars < 100)
{
Print("bars less than 100");
return(0);
}
//----
if(TakeProfit < 10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
//----
SEma = iMA(NULL, 30, ShortEma, 0, MODE_LWMA, PRICE_CLOSE, 0);
LEma = iMA(NULL, 30, LongEma, 0, MODE_LWMA, PRICE_CLOSE, 0);
Stoch = iStochastic(NULL,30,Stochastic,dPeriod,slowing,MODE_SMA, 0, MODE_SIGNAL, 0);
//----
static int isCrossed = 0;
isCrossed = Crossed (SEma, LEma);
//----
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
if (SEma>LEma && Stoch>50)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - StopLoss*Point,
Ask + TakeProfit*Point, "EMA_CROSS", 12345, 0, Green);
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("BUY order opened : ", OrderOpenPrice());
}
else
Print("Error opening BUY order : ", GetLastError());
return(0);
}
if((isCrossed == 2) && (SEma<LEma) && (Stoch<50))
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + StopLoss*Point,
Bid - TakeProfit*Point, "EMA_CROSS", 12345, 0, Red);
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("SELL order opened : ", OrderOpenPrice());
}
else
Print("Error opening SELL order : ", GetLastError());
return(0);
}
return(0);
}
//----
for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
// if(OrderType() == OP_BUY) // long position is opened
I'm new to MetaTrader but not new to Backtesting. Therefore I won't suggest specific code but do have some ideas.

First, you have to decide how long you are willing to look for the Stodhastic trigger after the MA crossover has occurred. You probably don't want to look forever. Lets suppose you decide that the stoch has to be met within X bars.

First, on the ema crossover, capture the bar number into a static variable so that it doesn't get destroyed on each entry into the start() function.
Then on each subsequent new bar, check to see if the stochastic trigger has occured and you are within the X bars of the crossover.

You'd also need to code to be sure that if a fresh cross over occurs before the stochastic is satisfied, that you reset the bars counter to begin again.

Rollin
Reason: