hi all... i'm stuck here... can anyone help me decify this?
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:
i 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
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:
i 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