Hi, I'm a new trader but I have a basic understanding of programming. It seems to me as if the latest ea version of this system makes all orders exit after gaining 40 pips. Looking back in the thread, it seems to me that only condition 2 orders (MACD agrees with the moving average crossover) have a set takeprofit level. Please correct me if I'm mistaken but the exit parameter for all types of orders is either when the moving averages cross over in the opposite direction or a loss of 30 pips whichever comes first. I've been playing around with the code and made it so that some orders would exit because of the moving average crossover before going so far as to hit the stoploss.
here is what I have so far in the exit section of the code
if(OrderType()==OP_BUY) // long position
{
if(OrderMagicNumber() == MagicNumber + 1 && Bid - OrderOpenPrice() >= TakeProfitNum) // long position is opened with Scen. #2
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position
return(0); // exit
}
// should it be closed?
else if(ShortEmaCurrent < LongEmaCurrent && ShortEmaPrevious > LongEmaPrevious)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position
return(0); // exit
}
}
else if(OrderType()==OP_SELL) // short position
{
if(OrderMagicNumber() == MagicNumber + 1 && OrderOpenPrice() - Ask >= TakeProfitNum)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; //close position
}
// should it be closed?
if(ShortEmaCurrent > LongEmaCurrent && ShortEmaPrevious < LongEmaPrevious)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position
return(0); // exit
}
}
|