



WHRoeder:
double SlopeUp = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,0,0); double SlopeUp2 = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,0,0); double SlopeDown = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,1,0); double SlopeDown2 = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,1,0); however it still didnt work. on the M15 time line still bought 15 minutes to late, sold and close 15 minutes to late as well. did not do the actions on the line. any other suggestions? thanks inadvance 
i am trying to make an EA with the slope direction indicator. not on hedging or scalping.
but i would like to start a buy when color goes from red to blue and close the order when lines changes from blue to red and start a sell. and then so on.
now i have come pretty far. except that it starts the buy to late, sell to late and close order to late.
if i start the EA on a timeframe of 15 minutes it will close the order 15 minutes after the line has changed if i start the Ea on 1 hour timeframe it will close the order 1 hour after the line has changed.
if possible could someone look into the code and could explain to me how to fix it. indicator attached as well.
thank you
//++
// sample.EA.indicatortest.mq4
//++
// External Varibales
extern double LotSize = 1.0;
extern double StopLoss = 0;
extern double TakeProfit = 0;
extern int Slippage = 5;
extern int MagicNumber = 123;
extern int SlopePeriod = 80;
extern int SlopeMethod = 3;
extern int SlopePrice = 0;
extern bool bRichard=true;
//Global varibales
int BuyTicket;
int SellTicket;
double UsePoint;
int UseSlippage;
// init function
int init()
{
UsePoint = PipPoint(Symbol());
UseSlippage = GetSlippage(Symbol(),Slippage);
}
// Start Function
int start()
{
//moving averages
double SlopeUp = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,0,1);
double SlopeUp2 = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,0,2);
double SlopeDown = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,1,1);
double SlopeDown2 = iCustom(NULL,0,"Slope Direction Line",SlopePeriod,SlopeMethod,SlopePrice,1,2);
//Buy order
if( SlopeUp != SlopeDown && SlopeDown2 == EMPTY_VALUE && BuyTicket == 0 ) // BUY
{
OrderSelect(SellTicket,SELECT_BY_TICKET);
//Close OrderClose
if(OrderCloseTime() == 0 && SellTicket > 0)
{
double CloseLots = OrderLots();
double ClosePrice = Ask;
bool Closed = OrderClose(SellTicket,CloseLots,ClosePrice,UseSlippage,Red);
}
double OpenPrice = Ask;
//Calculate Stop loss and take profit
if(StopLoss > 0) double BuyStopLoss = OpenPrice  (StopLoss * UsePoint);
if(TakeProfit > 0) double BuyTakeProfit = OpenPrice + (TakeProfit * UsePoint);
// Open Buy Order
BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,UseSlippage,
BuyStopLoss,BuyTakeProfit,"Buy Order",MagicNumber,0,Green);
SellTicket = 0;
}
// Sell Order
if(SlopeUp == SlopeDown && SlopeUp2 != EMPTY_VALUE && SellTicket == 0) // Sell
{
OrderSelect(BuyTicket,SELECT_BY_TICKET);
if(OrderCloseTime() == 0 && BuyTicket > 0)
{
CloseLots = OrderLots();
ClosePrice =Bid;
Closed = OrderClose(BuyTicket,CloseLots,ClosePrice,UseSlippage,Red);
}
OpenPrice = Bid;
if(StopLoss > 0) double SellStopLoss = OpenPrice + (StopLoss * UsePoint);
if(TakeProfit > 0) double SellTakeProfit = OpenPrice  (TakeProfit * UsePoint);
SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,OpenPrice,UseSlippage,SellStopLoss,SellTakeProfit,"Sell Order",MagicNumber,0,Red);
BuyTicket = 0;
}
return(0);
}
// Pip Point Function
double PipPoint(string Currency)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if (CalcDigits == 2  CalcDigits == 3) double CalcPoint = 0.01;
else if(CalcDigits == 4  CalcDigits == 5) CalcPoint = 0.0001;
return(CalcPoint);
}
// Get Slippage Function
int GetSlippage(string Currency,int SlippagePips)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2  CalcDigits == 4) double CalcSlippage = SlippagePips;
else if(CalcDigits == 3  CalcDigits == 5) CalcSlippage = SlippagePips * 10;
return(CalcSlippage);
}
//+END+
slopevdirectionlline.mq4 (4.10 KB)