[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 420

 

Hello.

I have created the following loop:

for(j=0;j<ArraySize(fiboOrd);j++)
 {
  if(fiboOrd[j]==d && TP==0) TP=NormalizeDouble(Asia*fibo[j],Digits);
  if(fiboOrd[j]==d && TP>0)  Price=NormalizeDouble(Asia*fibo[j],Digits);
 }

The problem is as follows: the value of the variable TP for some reason is only found for the first value of j , while the value of the variable Price is found for all values of j .

How can I get all TP values for all values of j ? What is my mistake?

Thank you in advance.

 
nemo811:

How can I find all TP values for all values of j ? What is my mistake?

I don't have to answer the question, I figured it out on my own.

 
frixer:
Hello, could you please tell me how to find the low and high of the last candle for example


Is the last one the one that has not yet fully formed?

Low_0=Low[0];                                // Low_0 присвоена мин. цена 0-го бара
High_0=High[0];                              // High_0 присвоена макс. цена 0-го бара
 

Please, tell me why the Expert Advisor may not open trades in real trading, although in the Strategy Tester it opens everything normally? And there are no errors in the log. Alpari's demo server.

 
sss2019:

Please, tell me why the Expert Advisor may not open trades in real trading, although in the Strategy Tester it opens everything normally? And there are no errors in the log. Alpari's demo server.


it is hard to say - there are many variants.... any other details you can give me?
 
elmucon:

it is hard to say - there are a lot of options.... i would like to know more details.


I don't know, everything seems ok, everything works like clockwork in the tester, but on the demo account the time has already come, but no trades were opened and for the next hour too. Maybe you should look at the code.

//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| extern variables                                                 |
//+------------------------------------------------------------------+

extern int GMT = 2;
extern int InTime = 23;
extern int OrderDuration = 2;
extern double Lot = 0.1;
extern string MyComment = "Return";
extern int Slippage = 3;
extern int StopLoss = 150;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int CurrentHour = TimeHour(TimeCurrent());
  int CurrentMinute = TimeMinute(TimeCurrent());
  datetime OrderExpiriation = TimeCurrent() + 3600 * OrderDuration;
  
  double MyPoint = Point;
  if(Digits == 3 || Digits == 5)
    {
    MyPoint = Point * 10;
    }
//----
   if(TimeHour(TimeCurrent()) + GMT == InTime && TimeMinute(TimeCurrent()) == 0 && OrdersTotal() == 0)
     {
//---- Sending first order - Buy
     if(OrderSend(Symbol(),OP_BUYLIMIT,Lot,Open[0] - 10 * MyPoint,Slippage,Open[0] - StopLoss * MyPoint,Open[0],MyComment,16523,OrderExpiriation,Green) > 0)
       {
       Alert("Первый ордер запущен");
       }else
       {
       Alert("Первый ордер не запущен");
       }
//---- Sending second order Buy
     if(OrderSend(Symbol(),OP_BUYLIMIT,Lot,Open[0] - 15 * MyPoint,Slippage,Open[0] - StopLoss * MyPoint,Open[0],MyComment,16523,OrderExpiriation,Green) > 0)
       {
       Alert("Второй ордер запущен");
       }else
       {
       Alert("Второй ордер не летит");
       }
//---- Sending third order - Sell
     if(OrderSend(Symbol(),OP_SELLLIMIT,Lot,Open[0] + 10 * MyPoint,Slippage,Open[0] + StopLoss * MyPoint,Open[0],MyComment,16523,OrderExpiriation,Red) > 0)
       {
       Alert("Третий ордер отжахан");
       }else
       {
       Alert("Третий ордер не отжахан");
       }
//---- Sending fourth order - Sell
     if(OrderSend(Symbol(),OP_SELLLIMIT,Lot,Open[0] + 15 * MyPoint,Slippage,Open[0] + StopLoss * MyPoint,Open[0],MyComment,16523,OrderExpiriation,Red) > 0)
       {
       Alert("Четвертый ордер запущен");
       }else
       {
       Alert("Четвертый ордер не запущен");
       }

     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
Not in the log or anywhere else there is no error. If there are no errors in the code (well, maybe there are some bugs in the terminal), then it's more likely that I messed up with the timing.
 
The rsi period has never been changed.
 
kolyango:


The last one is the one that hasn't fully formed yet?

Thank you, that's helpful, but there's still a question, but I'll try to figure it out on my own.
 

If you do not have any problems, I cannot find a good programmer, I have written an EA with simple TS, but it does not work correctly!

So, look at the picture, the order opening at the intersection of 2 MAs, fast crosses a slow MA from bottom to top - buy and vice versa, the advisor has no idea how to open orders, a telling example in the picture:

1 - buy on 03.11.2011, no crossover nearby;

3 - sell on 04.11.2011, same thing;

5 - buy on 07.11.2011; it is unclear why this order is opened.

I have also seen the code itself:

extern int period_EMA = 85,
period_WMA = 5,
period_RSI = 14,
stoploss = 0,
takeprofit = 500,
risk = 10,
Magic = 777;
extern bool CloseCounter = false;
extern double Lot = 0.1;
extern int TrailingStop = 70; //если= 0, то трейлинг по фракталам или свечам
extern int Tip.Fr.or.Candl = 1; //если= 0, то трейлинг по фракталам 
//если= 1, то трейлинг по свечам
//--------------------------------------------------------------------
double SL,TP,LOT;
int TimeBar;
//--------------------------------------------------------------------
int start()
{
if (TimeBar==Time[0]) return(0);
double EMA0 = iMA(NULL,0,period_EMA,0,MODE_EMA, PRICE_OPEN,0);
double WMA0 = iMA(NULL,0,period_WMA,0,MODE_LWMA,PRICE_OPEN,0);
double EMA1 = iMA(NULL,0,period_EMA,0,MODE_EMA, PRICE_OPEN,1);
double WMA1 = iMA(NULL,0,period_WMA,0,MODE_LWMA,PRICE_OPEN,1);
double RSI = iRSI(NULL,0,period_RSI,PRICE_OPEN,0);
if (EMA0 < WMA0 && EMA1 > WMA1 && RSI > 50)
{
TimeBar=Time[0]; 
if (takeprofit!=0) TP = Ask + takeprofit*Point;
if (stoploss!=0) SL = Ask - stoploss* Point; 
LOT = LOT(risk,1);
if (CloseCounter) CLOSEORDER("Sell");
OPENORDER ("Buy");
}
if (EMA0 > WMA0 && EMA1 < WMA1 && RSI < 50)
{
TimeBar=Time[0]; 
if (takeprofit!=0) TP = Bid - takeprofit*Point;
if (stoploss!=0) SL = Bid + stoploss* Point; 
LOT = LOT(risk,1);
if (CloseCounter) CLOSEORDER("Buy");
OPENORDER ("Sell");
}
TrailingStop();
return(0);
}
//--------------------------------------------------------------------
void CLOSEORDER(string ord)
{
for (int i=0; i<OrdersTotal(); i++)
{ 
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol()!=Symbol()||Magic!=OrderMagicNumber()) continue;
if (OrderType()==OP_BUY && ord=="Buy")
OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
if (OrderType()==OP_SELL && ord=="Sell")
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
} 
}
}
//--------------------------------------------------------------------
void OPENORDER(string ord)
{
int error;
if (ord=="Buy" ) error=OrderSend(Symbol(),OP_BUY, LOT,Ask,2,SL,TP,"EMA WMA RSI",Magic,3);
if (ord=="Sell") error=OrderSend(Symbol(),OP_SELL,LOT,Bid,2,SL,TP,"EMA WMA RSI",Magic,3);
if (error==-1) ShowERROR(error,0,0);
return;
} 
//--------------------------------------------------------------------
void ShowERROR(int Ticket,double SL,double TP)
{
int err=GetLastError();
switch ( err )
{ 
case 1: return;
case 2: Alert("Нет связи с торговым сервером " ,Ticket," ",Symbol());return;
case 130: Alert("Error близкие стопы Ticket ", Ticket," ",Symbol());return;
case 134: Alert("Недостаточно денег ", Ticket," ",Symbol());return;
case 146: Alert("Error Подсистема торговли занята ", Ticket," ",Symbol());return;
case 129: Alert("Error Неправильная цена ", Ticket," ",Symbol());return;
case 131: Alert("Error Неправильный объем ", Ticket," ",Symbol());return;
default: Alert("Error ",err," Ticket ", Ticket," ",Symbol());return;
}
}
//--------------------------------------------------------------------
double LOT(int risk,int ord)
{
if (Lot!=0) return(Lot);
double MINLOT = MarketInfo(Symbol(),MODE_MINLOT);
LOT = AccountFreeMargin()*risk/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED)/ord;
if (LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT);
if (LOT<MINLOT) LOT = MINLOT;
if (MINLOT<0.1) LOT = NormalizeDouble(LOT,2); else LOT = NormalizeDouble(LOT,1);
return(LOT);
}
//--------------------------------------------------------------------
void TrailingStop()
{
int tip,Ticket;
bool error;
double StLo,OSL,OOP;
for (int i=0; i<OrdersTotal(); i++) 
{ if (OrderSelect(i, SELECT_BY_POS)==true)
{ tip = OrderType();
if (tip<2 && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
OSL = OrderStopLoss();
OOP = OrderOpenPrice();
Ticket = OrderTicket();
if (tip==OP_BUY) 
{
StLo = SlLastBar(1,Bid,Tip.Fr.or.Candl,TrailingStop); 
if (StLo <= OOP) continue;
if (StLo > OSL)
{ error=OrderModify(Ticket,OOP,NormalizeDouble(StLo,Digits),
OrderTakeProfit(),0,White);
Comment("TrailingStop ",Ticket," ",TimeToStr(TimeCurrent(),TIME_MINUTES));
Sleep(500);
if (!error) Comment("Error order ",Ticket," TrailingStop ",
GetLastError()," ",Symbol()," SL ",StLo);
}
} 
if (tip==OP_SELL) 
{
StLo = SlLastBar(-1,Ask,Tip.Fr.or.Candl,TrailingStop); 
if (StLo==0) continue; 
if (StLo >= OOP) continue;
if (StLo < OSL || OSL==0 )
{ error=OrderModify(Ticket,OOP,NormalizeDouble(StLo,Digits),
OrderTakeProfit(),0,White);
Comment("TrailingStop "+Ticket," ",TimeToStr(TimeCurrent(),TIME_MINUTES));
Sleep(500);
if (!error) Comment("Error order ",Ticket," TrailingStop ",
GetLastError()," ",Symbol()," SL ",StLo);
}
} 
}
}
}
}
//--------------------------------------------------------------------
double SlLastBar(int tip,double price, int tipFr, int tral)
{
double fr;
int jj,ii,delta=5;
if (tral!=0)
{
if (tip==1) fr = Bid - tral*Point; 
else fr = Ask + tral*Point; 
}
else
{
if (tipFr==0)
{
if (tip== 1)
for (ii=1; ii<100; ii++) 
{
fr = iFractals(NULL,0,MODE_LOWER,ii);
if (fr!=0) if (price-delta*Point > fr) break;
else fr=0;
}
if (tip==-1)
for (jj=1; jj<100; jj++) 
{
fr = iFractals(NULL,0,MODE_UPPER,jj);
if (fr!=0) if (price+delta*Point < fr) break;
else fr=0;
}
}
else
{
if (tip== 1)
for (ii=1; ii<100; ii++) 
{
fr = iLow(NULL,0,ii);
if (fr!=0) if (price-delta*Point > fr) break;
else fr=0;
}
if (tip==-1)
for (jj=1; jj<100; jj++) 
{
fr = iHigh(NULL,0,jj);
if (price+delta*Point < fr) break;
else fr=0;
}
}
}
/* if (tip== 1)
{
ObjectDelete("SL Buy");
ObjectDelete("SL-");
ObjectCreate("SL Buy",OBJ_ARROW,0,TIME,fr,0,0,0,0); 
ObjectSet ("SL Buy",OBJPROP_ARROWCODE,6);
ObjectSet ("SL Buy",OBJPROP_COLOR, Blue);
ObjectCreate("SL-",OBJ_ARROW,0,TIME,price-delta*POINT,0,0,0,0); 
ObjectSet ("SL-",OBJPROP_ARROWCODE,4);
ObjectSet ("SL-",OBJPROP_COLOR, Blue);
}
if (tip==-1)
{
ObjectDelete("SL Sell");
ObjectDelete("SL+");
ObjectCreate("SL Sell",OBJ_ARROW,0,TIME,fr,0,0,0,0);
ObjectSet ("SL Sell",OBJPROP_ARROWCODE,6);
ObjectSet ("SL Sell", OBJPROP_COLOR, Green);
ObjectCreate("SL+",OBJ_ARROW,0,TIME,price+delta*POINT,0,0,0,0); 
ObjectSet ("SL+",OBJPROP_ARROWCODE,4);
ObjectSet ("SL+",OBJPROP_COLOR, Green);
}*/
return(fr);
}
//--------------------------------------------------------------------



Thank you very much in advance!

 

Good afternoon, please advise what the error "2011.12.10 12:46:26 TestGenerator: unmatched data error (volume limit 2225 at 2011.11.29 11:00 is exceeded)" means and how it can be corrected....

Reason: