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

 

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==lSymbol()) // check for symbol
{

?

 

Help with the code plz! Why do I get 138 in this code, and what does it have to do with it? deals open, but when you close the price is somehow not the same, what is it? everything is simple. expert advisor in s candles should close the deal and open when the fractal is penetrated. thanks in advance for the tip

extern int s=5;



extern int stime=60;
extern int lots=1;
extern int slippage=5;
extern double sl=NULL;
extern double tp=NULL;
double upfr,dnfr=0.0;//levels of last fractals
double tClose=NULL;
double tOpen=NULL;
int flag=0;
int init()
{
//----



//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |

//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+

int start()//open on breakout and close after s candles
{
//----
upfr=iFractals(Symbol(),PERIOD_H1,MODE_UPPER,4)
dnfr=iFractals(Symbol(),PERIOD_H1,MODE_LOWER,4);
//OPPER ORDERS ON PROBIT
if(upfr>0 && High[1]>upfr && flag==0) //if the fractal is up and the fractal level is exceeded
{
tOpen=Time[0];
tClose=tOpen+s*stime*60;
OrderSend(Symbol(),OP_BUY,lots,Bid,slippage,sl,tp);
flag=1;
}
if(dnfr>0 && Low[1]<dnfr && flag==0)//if fractal is down and fractal level is down
{
tOpen=Time[0];
tClose=tOpen+s*stime*60;
OrderSend(Symbol(),OP_SELL,lots,Ask,sl, sl, tp);
flag=1;
}

// CLOSE ORDERS BY END OF TIME
if(Time[0]>=tClose )// if time before closing has passed
{
Print("CLOSE FUNCTION");
OrClose();
flag=0;
}


//----
return(0);
}
//+------------------------------------------------------------------+
//close all orders
void OrClose()
{
for(int i=OrdersTotal()-1;i>=1;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
OrderClose(OrderTicket(),lots,OrderOpenPrice(),0.0005);
}
}
return(0);
}
 
Qwertee:

Help with code plz! Why am I getting a 138 error in this code??? and what does it have to do with it? deals open, but when you close the price is somehow not the same, what is it?

OrderClose(OrderTicket(),lots,OrderOpenPrice(),0.0005);

change it to

         if(OrderType()==OP_BUY)
           {
            OrderClose(OrderTicket(),OrderLots(),Bid,slippage);
           }
         else
           {
            OrderClose(OrderTicket(),OrderLots(),Ask,slippage);
           }
 
Good afternoon. Professionals, who dealt with the Zigzag indicator, advise how to get the last two values of the tops: High and Low?
 

Good afternoon.

Please help me with opening orders. I am using an EA on a demo account, when I get a Buy or Sell condition, it shows 130 errors.

Here is the order opening function:

int NewOrder(int Cmd,double Lot)
{double TP=0; //тейкпрофит
 double SL=0; //стоплосс
 double PR=0; //Цена
 while(!IsTradeAllowed()) Sleep(100);
 RefreshRates ();
 if(Cmd==OP_BUY)
   {PR=Ask;
    if(TakeProfit>0) TP=NormalizeDouble(Ask+TakeProfit*Point,Digits);
    if(StopLoss>0) SL=NormalizeDouble(Bid-StopLoss*Point,Digits);}
 if(Cmd==OP_SELL)
   {PR=Bid;
    if(TakeProfit>0) TP=NormalizeDouble(Bid-TakeProfit*Point,Digits);
    if(StopLoss>0) SL=NormalizeDouble(Ask+StopLoss*Point,Digits);}
 int tic=OrderSend(Symbol(),Cmd,Lot,PR,20,SL,TP,"",0,0,CLR_NONE);
 if(tic<0) Print("Ошибка открытия ордера: ",GetLastError());
return(tic);}

I checked on other EA and found that all was ok with lot calculation.

Demo account at Alpari, Micro type. take and stop are 100p, soot. 10 pips, as Alpari has 5 sign

 
 
FAQ:
Normalize the opening price.


How do you normalize it?

Right?

PR=NormalizeDouble(Ask,Digits);

If so, nothing changes.

I don't have much experience in programming yet. Can you please explain how to normalize it?

 
Then check the size of the stop and profit beforehand, if it is bigger than your stop and profit - adjust them. if it is zero. then you need to set an order with zero stop and profit first, and then modify them to the right levels.
 

Good evening. Question: When I close part of a trade, the EA kind of opens a new trade with a new ticket. Does the magik of the new order remain the same?

 
Installed MetaTrader 4, opened a demo account. Tried to open/close orders. How can I now make the terminal itself trigger a sell order when the price goes up and a buy order when it goes down, using information like "you need a 2 candle difference to close the old order and open a new one"?
Reason: