SetPendingOrders1(OP_BUYLIMIT,Lot,price,Slippage,StopLoss,TakeProfit,MagicLong,Walls); Alert ("error 1 is: ", GetLastError()); SetPendingOrders2(OP_BUYSTOP,Lot,price,Slippage,StopLoss,TakeProfit,MagicLong,Walls); Alert ("error 2 is: ", GetLastError());
since that i don't have all var. & i can't guess what it is i have to ask u what error u get (or maybe it is a compile error)?
SetPendingOrders2(OP_BUYSTOP,Lot,price,Slippage,StopLoss,TakeProfit,MagicLong,Walls); void SetPendingOrders2(int cmd,double Lot,double price,int slippage,double stoploss,int PS,int magic, int levels) { double sl = 0; for(int i=0;i<levels-1;i++) { while(IsTradeAllowed() == false) DoNothing(); if (UseStopLoss) { sl = price-((i+1)*PS*Point+stoploss*Point); } else { sl = 0; } OpenOrder(cmd,Lot,price+(i+1)*PS*Point,slippage,sl,price+i*PS*Point,magic,CLR_NONE); } return(0); }
cmd = OP_BUYSTOP
Lot = Lots Qty
price = Ask
PS = TakeProfit => 10
sl = StopLoss => False
levels is for looping how many BUYLIMIT or BUYSTOP i want to open. I set 4 for levels
i got error 130 for OP_BUYSTOP on journal
but the OP_BUYLIMIT is executed
i hope this information can help to solve my case.
since that i don't have all var. & i can't guess what it is i have to ask u what error u get (or maybe it is a compile error)?
@ brewmanz
i use 4 decimal prices. I already tried to increase TP but still error 130. Even if i use normal command like
SetPendingOrders1(OP_BUYLIMIT,Lot,Ask+Takeprofit*point,3,StopLoss,TakeProfit,MagicLong,Walls);
Something like that - Normal code by MQL4 - Nothing happened. Still Error 130, And the OP_BUYLIMIT is fine. And that what confused me.
When I had similar problems, I knew that something was not as I expected, so I used the following code (YMMV)
Print("Placing Open Long#", pThisSLMethodSeq, ",OSL=", DoubleToStr(pOptionalStopLoss, Digits), //",PACHATR=", DoubleToStr(PacHRange, Digits), "(", DoubleToStr(PacHRange*100 / RecentATR, 0), "%)", ",Magic=", Magic, ",L=", LotsThisTradeRounded, "@", DoubleToStr(Bid, Digits), "~", DoubleToStr(Ask, Digits), "[±", SlippageMax, ",SL=(", SLInPips, ")", DoubleToStr(SLPrice, Digits), "(Risk$=", DoubleToStr((Ask - SLPrice) * LotsThisTradeRounded * TickValue / Point, 2), ")", ",TP=(", TPInPips, ")", DoubleToStr(TPPrice, Digits)); Ticket = OrderSend(Symbol(), OP_BUY, LotsThisTradeRounded, Ask, SlippageMax, SLPrice, TPPrice, "Long SL" + pThisSLMethodSeq, Magic, Expiration, ArrowLong);
Hack it around to display the info you need
b_man:
i use 4 decimal prices. I already tried to increase TP but still error 130. Even if i use normal command like
Something like that - Normal code by MQL4 - Nothing happened. Still Error 130, And the OP_BUYLIMIT is fine. And that what confused me.
void SetPendingOrders(int cmd,double Lot,double price,int slippage,double stoploss,int PS,int magic, int Walls) { double sl = 15; for(int i=0;i<Walls-1;i++) { while(IsTradeAllowed() == false) DoNothing(); if (UseStopLoss) { sl = price-((i+1)*PS*Point+stoploss*Point); } else { sl = 0; } RefreshRates(); OpenOrder(cmd,Lot,price-(i+1)*PS*Point,slippage,sl,price-i*PS*Point,magic,CLR_NONE); Print("Placing Open Limit#",cmd, "Lot = ",Lot," Price = ",price-(i+1)*PS*Point," Slippage = ", slippage," TakeProfit = ",price-i*PS*Point," MagicLong = ",magic," Walls = ",i); Print ("Error SetPendingOrders = ",GetLastError()); } return(0); }
@brewmanz, I put the print command like you recommended in SetPendingOrders function after opening an order. But it doesn't print anything. the next Print command to print error is executed and print error 0. I haven't use it to print the OP_BUYSTOP. Do i put it wrong?
@WHRoeder, i only having problem with Buy Stop command and it still doesn't open any position even if I put TP for 20 pips or more. But the buy limit command is executed very fine.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I tried to modify some EA.
I want to add some Buy_Stop
But it failed
Could someone help me??
if(BuyQty < Walls)
{
cmd = OP_BUY;
price = Ask;
colour = Green;
takeprofit = Ask +GridPip*Point;
if(UseStopLoss == true) StopLoss = Ask - StopLoss*Point;
if(OpenNew)
{
ticket1=OpenOrder(cmd, Lot, price, Slippage, stoploss,Ask + TakeProfitLevel1*Point, MagicLong, colour);
SetPendingOrders1(OP_BUYLIMIT,Lot,price,Slippage,StopLoss,TakeProfit,MagicLong,Walls);
SetPendingOrders2(OP_BUYSTOP,Lot,price,Slippage,StopLoss,TakeProfit,MagicLong,Walls);
if (ticket1 == 0) return(0);
}
}
//---------------------------------------Fungtion Start----------------------------------------------------\\
void SetPendingOrders1(int cmd,double Lot,double price,int slippage,double stoploss,int PS,int magic, int levels)
{
double sl = 0;
for(int i=0;i<levels-3;i++)
{
while(IsTradeAllowed() == false) DoNothing();
if (UseStopLoss) { sl = price-((i+1)*PS*Point+stoploss*Point); } else { sl = 0; }
OpenOrder(cmd,Lot,price-(i+1)*PS*Point,slippage,sl,price-i*PS*Point,magic,CLR_NONE);
Print (" TP ", i," - ", PS);
}
return(0);
}
//---------------------------------------Fungtion End------------------------------------------------------\\
//---------------------------------------Fungtion Start----------------------------------------------------\\
void SetPendingOrders2(int cmd,double Lot,double price,int slippage,double stoploss,int PS,int magic, int levels)
{
double sl = 0;
for(int i=0;i<levels-1;i++)
{
while(IsTradeAllowed() == false) DoNothing();
if (UseStopLoss) { sl = price-((i+1)*PS*Point+stoploss*Point); } else { sl = 0; }
OpenOrder(cmd,Lot,price+(i+1)*PS*Point,slippage,sl,price+i*PS*Point,magic,CLR_NONE);
}
return(0);
}
//---------------------------------------Fungtion End------------------------------------------------------\\