
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
1. Store order tickets in an array or 2 variables.
2. Select them one by one with OrderSelect (the array is more convenient here) .
3. Check the type for the current moment.
4. If type OP_BUY || OP_SELL -> OrderDelete for second ticket.
Please help me with a simple example, I understand many things, but the order select is a bit of a jam!
Here is the code where the error is ????? Doesn't delete second pendent when one pendent triggers ......
if (MA1<MA2)
{
if(n==0)
{
//==================================================================================================================//
tiket=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slip,slb,tpb,NULL,MagicNumber,0,CLR_NONE);
if(tiket<0) Alert("Error # - ",GetLastError()," On instrument ", Symbol()); //write error//
//================================================================================================================//
t2 = OrderSend(Symbol(), OP_BUYSTOP, Lots*Overlot,OtkrBS, Slip,0,tpb, 0, MagicNumber,expiration);
//================================================================================================================//
t1 = OrderSend(Symbol(), OP_SELLSTOP, Lots*Overlot+1,OtkrSS,Slip,0,slb, 0, MagicNumber,expiration);
//================================================================================================================//
//==================================================================================================================//
}
//==================================================================================================================//
else
//=================================================================================================================//
if (MA1>MA2)
{
tiket=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slip,sls,tps,NULL,MagicNumber,0,CLR_NONE);
if(tiket<0) Alert("Error # - ",GetLastError()," On instrument ", Symbol()); //write error//
//================================================================================================================//
t2 = OrderSend(Symbol(), OP_BUYSTOP, Lots*Overlot+1,OtkrSS1,Slip,0,sls, 0, MagicNumber,expiration);
//================================================================================================================//
t1 = OrderSend(Symbol(), OP_SELLSTOP, Lots*Overlot, OtkrBS1,Slip,0,tps, 0, MagicNumber,expiration);
//================================================================================================================//
}
//==================================================================================================================//
// if SELLSTOP has triggered, delete BUYSTOP
if(OrderSelect(t1, SELECT_BY_TICKET))
{
if(OrderType()==OP_SELL)
{
OrderDelete(t2);
}
}
//----
// if BUYSTOP has triggered, delete SELLSTOP
if(OrderSelect(t2, SELECT_BY_TICKET))
{
if(OrderType()==OP_BUY)
{
OrderDelete(t1);
}
}
You're confused about the conditions. I think you have {} brackets in the wrong place:
Or something like that.
What's amazing is that I have a similar EA. I checked everything with it, it's all the same in principle. It works, and this one doesn't...
The difference is that the other EA has only one pose for buy entry and two pendants.
tickets in global variables? (outside of start and other functions)
If not, they are reset every tick.
Insert more Print()-s at each step of the Expert Advisor, then you will understand where it crashes and what it does not do.
HOORAY AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Winner !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tickets in global variables? (outside of start and other functions)
If not, they are reset every tick.
Insert more Print()-s at each step of the Expert Advisor, then you will understand where it crashes and what it does not do.