Ask for help: 1 hour tunnel EA problem New comment duanchzhu 2009.03.26 08:21 Hi every one I have downloaded a 1 hour tunnel EA generated by Vegas. This EA is efficient for open orders, but it can not close any order. I would like to ask someone kindly help me. Thanks! #property copyright "Mikey" #property link "" extern int minTunnelInPips = 30; extern int unitsPerOrder = 5; double unitSize = 0.02; extern bool onlyOnEMA12Filter = false; extern int moneyManagementInPercent = 10; int orderTicket = 0; int fibsTaken = 0; bool gotTunnel = false; bool got12ema = false; double currentUnitSize; double ema144High; double ema144Low; double ema12; double top; double bottom; double shift; double minTunnel; double diff; double m_dOpenPrice; int init() { return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- if(Bars<100 || IsTradeAllowed()==false) return; minTunnel = minTunnelInPips *Point; ema144Low = iMA(NULL, PERIOD_M15, 144, 0, MODE_EMA, PRICE_LOW, 0); ema144High = iMA(NULL, PERIOD_M15, 144, 0, MODE_EMA, PRICE_HIGH, 0); ema12 = iMA(NULL, PERIOD_M15, 12, 0, MODE_EMA, PRICE_CLOSE, 0); top = ema144High; bottom = ema144Low; diff = top-bottom; if(Close[0]ema144Low )// && OrdersTotal()==0) { gotTunnel = true; } ////////////////////////////////////////////// if(ema12ema144Low) { got12ema = true; } else { got12ema = false; } if(diff<minTunnel) { shift = (minTunnel -diff)/2; top = top+shift; bottom = bottom-shift; } //Print("PIP VALUE: ",MarketInfo(Symbol(),MODE_TICKVALUE)); if(OrdersTotal()>0) CheckForClose(); else CheckForOpen(); //---- return(0); } //+------------------------------------------------------------------+ double GetUnitSize(double sl) { sl = sl*10000; double canLoss = AccountBalance()*moneyManagementInPercent*0.01; int canLossInPips = canLoss/((MarketInfo(Symbol(),MODE_TICKVALUE))); double lossPerPip = canLossInPips / sl; double temp = (lossPerPip/unitsPerOrder); int rounded = MathRound(temp*10); //Print("canlossinpips: ", canLossInPips, "lossPerPip: ", lossPerPip, "temp: ", temp, "rounded: ", rounded); temp = rounded; temp = temp*0.1; double final = temp; Print("temp: ", temp); if(temp<0.1) final = 0.1; Print("UNIT SIZE: ", final); return (final); } void CheckForOpen() { currentUnitSize = GetUnitSize(top-bottom); bool openPosition = true; if(onlyOnEMA12Filter && !got12ema) { openPosition = false; } if(openPosition) { if(Close[0]>top && gotTunnel) { m_dOpenPrice=Ask; orderTicket = OrderSend(Symbol(), OP_BUY,currentUnitSize*unitsPerOrder, Ask, 5, bottom, 0); gotTunnel = false; got12ema = false; fibsTaken = 0; } else if(Close[0]<bottom && gotTunnel) { m_dOpenPrice=Bid; orderTicket = OrderSend(Symbol(), OP_SELL, currentUnitSize*unitsPerOrder, Bid, 5, top, 0); gotTunnel = false; fibsTaken = 0; got12ema = false; } } } void CheckForClose() { double ema144; double ema169; double ema157; double fib[5]; int orderType; double orderLots; ema144 = iMA(NULL, PERIOD_M15, 144, 0, MODE_EMA, PRICE_CLOSE, 0); ema169 = iMA(NULL, PERIOD_M15, 169, 0, MODE_EMA, PRICE_CLOSE, 0); ema157 = iMA(NULL, PERIOD_M15, 157, 0, MODE_EMA, PRICE_CLOSE, 0); double newSL; if(OrderSelect(0, SELECT_BY_POS)==true) { orderType=OrderType(); //orderLots = OrderLots(); orderTicket = OrderTicket(); double sl = OrderStopLoss(); double closeValue = currentUnitSize; if(orderType == OP_BUY) { //fib[0] = m_dOpenPrice+55*Point; //fib[1] = m_dOpenPrice+89*Point; //fib[2] = m_dOpenPrice+144*Point; //fib[3] = m_dOpenPrice+233*Point; //fib[4] = m_dOpenPrice+377*Point; fib[0] = ema157+55*Point; fib[1] = ema157+89*Point; fib[2] = ema157+144*Point; fib[3] = ema157+233*Point; fib[4] = ema157+377*Point; if(Ask>=fib[fibsTaken]) { if(fibsTaken==0) { //closeValue = currentUnitSize*3; } OrderClose(orderTicket, closeValue, Ask, 5, Red); fibsTaken = fibsTaken+1; } if(ema169<ema144) { newSL = ema169; } else { newSL = ema144; } if(fibsTaken>0 && newSL-sl>5*Point) { OrderModify(orderTicket, 0, newSL, 0, 0); } } else if(orderType == OP_SELL) { //fib[0] = m_dOpenPrice-55*Point; //fib[1] = m_dOpenPrice-89*Point; //fib[2] = m_dOpenPrice-144*Point; //fib[3] = m_dOpenPrice-233*Point; //fib[4] = m_dOpenPrice-377*Point; fib[0] = ema157-55*Point; fib[1] = ema157-89*Point; fib[2] = ema157-144*Point; fib[3] = ema157-233*Point; fib[4] = ema157-377*Point; if(Bid<=fib[fibsTaken]) { if(fibsTaken==0) { //closeValue = currentUnitSize*3; } OrderClose(orderTicket, closeValue, Bid, 5, Red); fibsTaken = fibsTaken+1; } if(ema169>ema144) { newSL = ema169; } else { newSL = ema144; } if(fibsTaken>0 && sl-newSL>5*Point) { OrderModify(orderTicket, 0, newSL, 0, 0); } } if(OrdersTotal()==0) { gotTunnel = false; Print(MarketInfo(Symbol(),MODE_TICKVALUE)); } } } Need Help Spotting Coding Error simple question about previous orders, but i do need some help Error 130 driving me nuts New comment
Hi every one
I have downloaded a 1 hour tunnel EA generated by Vegas. This EA is efficient for open orders, but it can not close any order.
I would like to ask someone kindly help me.
Thanks!
#property copyright "Mikey"
#property link ""
extern int minTunnelInPips = 30;
extern int unitsPerOrder = 5;
double unitSize = 0.02;
extern bool onlyOnEMA12Filter = false;
extern int moneyManagementInPercent = 10;
int orderTicket = 0;
int fibsTaken = 0;
bool gotTunnel = false;
bool got12ema = false;
double currentUnitSize;
double ema144High;
double ema144Low;
double ema12;
double top;
double bottom;
double shift;
double minTunnel;
double diff;
double m_dOpenPrice;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(Bars<100 || IsTradeAllowed()==false) return;
minTunnel = minTunnelInPips *Point;
ema144Low = iMA(NULL, PERIOD_M15, 144, 0, MODE_EMA, PRICE_LOW, 0);
ema144High = iMA(NULL, PERIOD_M15, 144, 0, MODE_EMA, PRICE_HIGH, 0);
ema12 = iMA(NULL, PERIOD_M15, 12, 0, MODE_EMA, PRICE_CLOSE, 0);
top = ema144High;
bottom = ema144Low;
diff = top-bottom;
if(Close[0]ema144Low )// && OrdersTotal()==0)
{
gotTunnel = true;
}
//////////////////////////////////////////////
if(ema12ema144Low)
{
got12ema = true;
}
else
{
got12ema = false;
}
if(diff<minTunnel)
{
shift = (minTunnel -diff)/2;
top = top+shift;
bottom = bottom-shift;
}
//Print("PIP VALUE: ",MarketInfo(Symbol(),MODE_TICKVALUE));
if(OrdersTotal()>0)
CheckForClose();
else
CheckForOpen();
//----
return(0);
}
//+------------------------------------------------------------------+
double GetUnitSize(double sl)
{
sl = sl*10000;
double canLoss = AccountBalance()*moneyManagementInPercent*0.01;
int canLossInPips = canLoss/((MarketInfo(Symbol(),MODE_TICKVALUE)));
double lossPerPip = canLossInPips / sl;
double temp = (lossPerPip/unitsPerOrder);
int rounded = MathRound(temp*10);
//Print("canlossinpips: ", canLossInPips, "lossPerPip: ", lossPerPip, "temp: ", temp, "rounded: ", rounded);
temp = rounded;
temp = temp*0.1;
double final = temp;
Print("temp: ", temp);
if(temp<0.1)
final = 0.1;
Print("UNIT SIZE: ", final);
return (final);
}
void CheckForOpen()
{
currentUnitSize = GetUnitSize(top-bottom);
bool openPosition = true;
if(onlyOnEMA12Filter && !got12ema)
{
openPosition = false;
}
if(openPosition)
{
if(Close[0]>top && gotTunnel)
{
m_dOpenPrice=Ask;
orderTicket = OrderSend(Symbol(), OP_BUY,currentUnitSize*unitsPerOrder, Ask, 5, bottom, 0);
gotTunnel = false;
got12ema = false;
fibsTaken = 0;
}
else if(Close[0]<bottom && gotTunnel)
{
m_dOpenPrice=Bid;
orderTicket = OrderSend(Symbol(), OP_SELL, currentUnitSize*unitsPerOrder, Bid, 5, top, 0);
gotTunnel = false;
fibsTaken = 0;
got12ema = false;
}
}
}
void CheckForClose()
{
double ema144;
double ema169;
double ema157;
double fib[5];
int orderType;
double orderLots;
ema144 = iMA(NULL, PERIOD_M15, 144, 0, MODE_EMA, PRICE_CLOSE, 0);
ema169 = iMA(NULL, PERIOD_M15, 169, 0, MODE_EMA, PRICE_CLOSE, 0);
ema157 = iMA(NULL, PERIOD_M15, 157, 0, MODE_EMA, PRICE_CLOSE, 0);
double newSL;
if(OrderSelect(0, SELECT_BY_POS)==true)
{
orderType=OrderType();
//orderLots = OrderLots();
orderTicket = OrderTicket();
double sl = OrderStopLoss();
double closeValue = currentUnitSize;
if(orderType == OP_BUY)
{
//fib[0] = m_dOpenPrice+55*Point;
//fib[1] = m_dOpenPrice+89*Point;
//fib[2] = m_dOpenPrice+144*Point;
//fib[3] = m_dOpenPrice+233*Point;
//fib[4] = m_dOpenPrice+377*Point;
fib[0] = ema157+55*Point;
fib[1] = ema157+89*Point;
fib[2] = ema157+144*Point;
fib[3] = ema157+233*Point;
fib[4] = ema157+377*Point;
if(Ask>=fib[fibsTaken])
{
if(fibsTaken==0)
{
//closeValue = currentUnitSize*3;
}
OrderClose(orderTicket, closeValue, Ask, 5, Red);
fibsTaken = fibsTaken+1;
}
if(ema169<ema144)
{
newSL = ema169;
}
else
{
newSL = ema144;
}
if(fibsTaken>0 && newSL-sl>5*Point)
{
OrderModify(orderTicket, 0, newSL, 0, 0);
}
}
else if(orderType == OP_SELL)
{
//fib[0] = m_dOpenPrice-55*Point;
//fib[1] = m_dOpenPrice-89*Point;
//fib[2] = m_dOpenPrice-144*Point;
//fib[3] = m_dOpenPrice-233*Point;
//fib[4] = m_dOpenPrice-377*Point;
fib[0] = ema157-55*Point;
fib[1] = ema157-89*Point;
fib[2] = ema157-144*Point;
fib[3] = ema157-233*Point;
fib[4] = ema157-377*Point;
if(Bid<=fib[fibsTaken])
{
if(fibsTaken==0)
{
//closeValue = currentUnitSize*3;
}
OrderClose(orderTicket, closeValue, Bid, 5, Red);
fibsTaken = fibsTaken+1;
}
if(ema169>ema144)
{
newSL = ema169;
}
else
{
newSL = ema144;
}
if(fibsTaken>0 && sl-newSL>5*Point)
{
OrderModify(orderTicket, 0, newSL, 0, 0);
}
}
if(OrdersTotal()==0)
{
gotTunnel = false;
Print(MarketInfo(Symbol(),MODE_TICKVALUE));
}
}
}