MQL4 Learning - page 55

 

Please, show us logs from function Almost_Cross (). I mean you wrote:

Print("filtered sell order: "," ",line2," ",line1," ",MathAbs(line2-line1));

What is on logs?

 

hi, roger, here is the log for the exact minute

The filtered SELL order lines are not found at that minute. I don't know why a zero is returned to generate the

"SELL order filtered" lines below.

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.3971 84.8517 4.5454

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.3971 84.8517 4.5454

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.3971 84.8517 4.5454

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.0658 84.8347 4.2311

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.0658 84.8347 4.2311

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.0658 84.8347 4.2311

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.1484 84.839 4.3094

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.2311 84.8432 4.3879

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.3971 84.8517 4.5454

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.314 84.8475 4.4666

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.3971 84.8517 4.5454

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.4803 84.856 4.6243

23:34:03 2008.11.19 17:42 fxlive_caller GBPJPY,M5: SELL order filtered : 89.5636 84.8603 4.7034

 

Change your code:

int Almost_Cross (double line1 , double line2)

{

if (line1 < 30.0 && line2 <30.0 && MathAbs(line1 - line2)<5.0)

{

return (1);

}

else

{

if (line1 < 30.0 && line2 < 30)

{

Print("filtered buy order: "," ",line1," ",line2," ",MathAbs(line1-line2));

return (0);

}

}

if (line1 > 70.0 && line2 >70.0 && MathAbs(line2 - line1)<5.0)

{

return (2);

}

else

{

if (line1 > 70.0 && line2 >70.0)

{

Print("filtered sell order: "," ",line2," ",line1," ",MathAbs(line2-line1));

return (0);

}

}

}

 

difference between the indicator called within my EA and the indicator running alone

roger, thanks for your answer. It solves the problem I raised in the last post now I have a different problem.

My EA uses a custom indicator called "fx-live". The custom indicator appears to assign a non-empty value to the variable UpArrow if at time i a buy signal is generated. It also appears to assign a non-empty value to the variable DnArrow if at time i a sell signal is generated.

But the indicator would only send an alert message under some condition extra to a non-empty UpArrow or DnArrow value. And the alert message is the "real" signal. Non-empty UpArrows or DnArrows not accompanied by an alert messages are false signals.

The problem is I do not understand the extra condition...below is the relevant code of the indicator...can anyone help me with getting the EA to work with the "real" signal only?

###

for (i = CountBars; i >= 0; i--)

{

DIR = DIR;

if (fxlive - fxlive > 0) DIR = 1;

if (fxlive - fxlive > 0) DIR = -1;

if (Color == true)

{

if (DIR > 0)

{

UpBuffer = fxlive;

if (DIR < 0) UpBuffer = fxlive;

DnBuffer = EMPTY_VALUE;

}

else

{

if (DIR < 0)

{

DnBuffer = fxlive;

if (DIR > 0) DnBuffer = fxlive;

UpBuffer = EMPTY_VALUE;

}

}

}

if (Alerts == true)

///Where UpArrow and DnArrow get assigned non-empty value

{

UpArrow = EMPTY_VALUE; DnArrow = EMPTY_VALUE;

if ((DIR == 1) && (DIR == -1)) UpArrow = fxlive - (Ask - Bid);

if ((DIR == -1) && (DIR == 1)) DnArrow = fxlive + (Ask - Bid);

}

}

###

***

if (Alerts == true)

{

string AlertTXT;

///extra conditions for generating an alert

if (UpArrow[0+p]!=EMPTY_VALUE && TurnedUp==false)

{

AlertTXT="fxlive BUY: "+Symbol()+" - "+Period()+" at "+ DoubleToStr(Close[0],Digits)+ " - "+ TimeToStr(CurTime(),TIME_SECONDS);

Alert(AlertTXT); if (EmailON) SendMail(AlertTXT,AlertTXT);

if (SignalPrice == true)

{

ObjectCreate("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJ_ARROW,0,Time[0],Close[0]);

ObjectSet("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_ARROWCODE,5);

ObjectSet("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_COLOR,SignalPriceBUY);

}

TurnedDn = false; TurnedUp = true;

}

if (DnArrow[0+p]!=EMPTY_VALUE && TurnedDn==false)

{

AlertTXT="fxlive SELL: "+Symbol()+" - "+Period()+" at "+ DoubleToStr(Close[0],Digits)+ " - "+ TimeToStr(CurTime(),TIME_SECONDS);

Alert(AlertTXT); if (EmailON) SendMail(AlertTXT,AlertTXT);

if (SignalPrice == true)

{

ObjectCreate("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJ_ARROW,0,Time[0],Close[0]);

ObjectSet("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_ARROWCODE,5);

ObjectSet("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_COLOR,SignalPriceSELL);

}

TurnedUp = false; TurnedDn = true;

}

}

***

+++

///the value of p is found here

if (!RealTime)

{

if(timeprev2==iTime(NULL,TimeFrame,0)) return(0);

timeprev2=iTime(NULL,TimeFrame,0);

p=TimeFrame/Period()+1; if (p==0) p=1;

}

+++

How can I fix the codes for calling the indicator and generating an order attached below to capture the real signal?

---

//original codes in my EA

fxb = iCustom(NULL,0,"fx-live",Crash,TimeFrame,Length,Method,Smoothing,Filter,RealTime,Steady,Color,Alerts,EmailON,SignalPrice,SignalPriceBUY,SignalPriceSELL,CountBars,3,0);

if(fxb != EMPTY_VALUE && is_almost_crossed ==1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,99,0,0,"fx-live buy",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);

}

---

Trillion of Trillion Thanks in advance

 

Is this the proper code to loop through all open orders. I am trying to count how many open buy orders and how many open sell orders there are currently open.

//Start of Open and Short Order count

int totalBuy =0;

int totalSell =0;

int EAopenOrders= totalBuy+totalSell;

for (int q = 0; q<=total; q++ )

{

OrderSelect(q,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)

totalBuy++;

if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)

totalSell++;

}

//End of total Open Long and Short count code
 

Actually the code is correct, just a little nuances

int totalBuy =0;

int totalSell =0;

for (int q = 0; q<=OrdersTotal(); q++ )

{

OrderSelect(q,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)

totalBuy++;

if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)

totalSell++;

}

int EAopenOrders= totalBuy+totalSell;
 

Sorry I forgot to post "int total=OrdersTotal();" in my code in the earlier post. So its not that the problem. But the EA seems like it is not working right. It is not opening up any sell orders after the Max number of buy orders are already open.

 

Well, can you show us the whole code?

 

here is the whole code for your reference

extern double Lots=0.1;

//parameters used by fx-live

extern bool Crash = false;

extern int TimeFrame = 0;

extern int Length = 5;

extern int Method = 2;

extern int Smoothing = 6;

extern int Filter = 5;

extern bool RealTime = true;

extern bool Steady = false;

extern bool Color = true;

extern bool Alerts = true;

extern bool EmailON = false;

extern bool SignalPrice = true;

extern color SignalPriceBUY = Yellow;

extern color SignalPriceSELL = Aqua;

extern int CountBars = 1485;

//parameters used by RSIOMA

extern int RSIOMA = 21;

extern int RSIOMA_MODE = 1;

extern int RSIOMA_PRICE = 0;

extern int Ma_RSIOMA = 38;

extern int Ma_RSIOMA_MODE = 1;

extern double BuyTrigger = 20.00;

extern double SellTrigger = 80.00;

extern color BuyTriggerColor = Magenta;

extern color SellTriggerColor = DodgerBlue;

extern double MainTrendLong = 70.00;

extern double MainTrendShort = 30.00;

extern color MainTrendLongColor = Green;

extern color MainTrendShortColor = Red;

extern double MajorTrend = 50;

extern int BarsToCount = 500;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int Almost_Cross (double line1 , double line2)

{

if (line1 < 30.0 && line2 <30.0 && MathAbs(line1 - line2)<5.0)

{

return (1);

}

else

{

if (line1 < 30.0 && line2 < 30)

{

Print("filtered buy order: "," ",line1," ",line2," ",MathAbs(line1-line2));

return (0);

}

}

if (line1 > 70.0 && line2 >70.0 && MathAbs(line2 - line1)<5.0)

{

return (2);

}

else

{

if (line1 > 70.0 && line2 >70.0)

{

Print("filtered sell order: "," ",line2," ",line1," ",MathAbs(line2-line1));

return (0);

}

}

}

//if(line1>line2)current_direction = 1; //up

//if(line1<line2)current_direction = 2; //down

//if(current_direction != last_direction) //changed

//{

//last_direction = current_direction;

//return (last_direction);

//}

//else

//{

//return (0);

//}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total;

double fxb;

double fxs;

double rsioma;

double marsioma;

fxb = iCustom(NULL, 0, "fx-live", Crash, TimeFrame, Length, Method, Smoothing, Filter, RealTime, Steady, Color, Alerts, EmailON, SignalPrice, SignalPriceBUY, SignalPriceSELL, CountBars, 3, 0);

fxs = iCustom(NULL, 0, "fx-live", Crash, TimeFrame, Length, Method, Smoothing, Filter, RealTime, Steady, Color, Alerts, EmailON, SignalPrice, SignalPriceBUY, SignalPriceSELL, CountBars, 4, 0);

rsioma = iCustom(NULL, 0, "RSIOMA_V3", RSIOMA, RSIOMA_MODE, RSIOMA_PRICE, Ma_RSIOMA, Ma_RSIOMA_MODE, BuyTrigger, SellTrigger, BuyTriggerColor, SellTriggerColor, MainTrendLong, MainTrendShort, MainTrendLongColor, MainTrendShortColor, MajorTrend, BarsToCount, 0, 0);

marsioma = iCustom(NULL, 0, "RSIOMA_V3", RSIOMA, RSIOMA_MODE, RSIOMA_PRICE, Ma_RSIOMA, Ma_RSIOMA_MODE, BuyTrigger, SellTrigger,BuyTriggerColor,SellTriggerColor,MainTrendLong, MainTrendShort, MainTrendLongColor, MainTrendShortColor, MajorTrend, BarsToCount, 5, 0);

int is_almost_crossed = Almost_Cross(rsioma,marsioma);

total = OrdersTotal();

if(total < 1)

{

if(fxb != EMPTY_VALUE && is_almost_crossed==0)

{

Print("BUY order filtered : ",rsioma," ",marsioma," ",MathAbs(rsioma-marsioma));

}

if(fxs != EMPTY_VALUE && is_almost_crossed == 0)

{

Print("SELL order filtered : ",rsioma," ",marsioma," ",MathAbs(rsioma-marsioma));

}

if(fxb != EMPTY_VALUE && is_almost_crossed ==1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,99,0,0,"fx-live buy",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(fxs != EMPTY_VALUE && is_almost_crossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,99,0,0,"fx-live sell",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

{

// should it be closed?

if(fxs != EMPTY_VALUE)

{

OrderClose(OrderTicket(),OrderLots(),Bid,99,Violet);

// close position

return(0); // exit

}

}

else // go to short position

{

// should it be closed?

if(fxb != EMPTY_VALUE)

{

OrderClose(OrderTicket(),OrderLots(),Ask,99,Violet);

// close position

return(0); // exit

}

// check for trailing stop

}

}

}

//----

return(0);

}

//+----------------------------------------------------------

 

To wailoktam

Actually I asked to show me the indicator code. I don't realy understand your problems because of my English. I have to figure out how this indicator fulfills.

To cutzpr

I need to see your whole code as well to help you

You can use PM service if you need the confidentiality.

Reason: