I am trying to write an expert that places multiple limit and stop orders, but for some reason it will only open up buylimit and buystop and no sell orders. Why is this working for me:
I have a simple expert with both of these and it just keeps on opening up buys and no sells, here is the simple expert that should be opening up both buys and sells repeatedly:
//+------------------------------------------------------------------+
//| Test.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
extern double Lots = 0.1; //
extern bool WantShorts= true;
extern bool WantLongs= true;
double price1;
int entermode;
string Name = "Test";
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
////////////////////////////////
// Open trades
////////////////////////////////
price1 = (MathRound((Ask*100)+1)/100);
if (WantShorts==true)
{
if ( price1 > Bid )
{ entermode = OP_SELLLIMIT; }
else
{ entermode = OP_SELLSTOP ; }
OrderSend(Symbol(),entermode,Lots,price1,0,0,50,Name,1,0,Red);
}
if (WantLongs==true)
{
if ( price1 > Ask )
{ entermode = OP_BUYSTOP; }
else
{ entermode = OP_BUYLIMIT ; }
OrderSend(Symbol(),entermode,Lots,price1,0,0,50,Name,1,0,Green);
}
return(0);
}
// the end
Thanks for any help, I hope it is just something stupid that I am missing, but it is driving me nuts.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
if (WantLongs==true) { if ( price1 > Ask ) { entermode = OP_BUYSTOP; } else { entermode = OP_BUYLIMIT; } OrderSend(Symbol(),entermode,Lots,price1,0,0,50,GridName,1,0,Green); }and not this:
if (WantShorts==true) { if ( price1 > Bid ) { entermode = OP_SELLLIMIT; } else { entermode = OP_SELLSTOP; } OrderSend(Symbol(),entermode,Lots,price1,0,0,50,GridName,1,0,Red); }I have a simple expert with both of these and it just keeps on opening up buys and no sells, here is the simple expert that should be opening up both buys and sells repeatedly:
//+------------------------------------------------------------------+ //| Test.mq4 | //| | //| | //+------------------------------------------------------------------+ extern double Lots = 0.1; // extern bool WantShorts= true; extern bool WantLongs= true; double price1; int entermode; string Name = "Test"; //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //////////////////////////////// // Open trades //////////////////////////////// price1 = (MathRound((Ask*100)+1)/100); if (WantShorts==true) { if ( price1 > Bid ) { entermode = OP_SELLLIMIT; } else { entermode = OP_SELLSTOP ; } OrderSend(Symbol(),entermode,Lots,price1,0,0,50,Name,1,0,Red); } if (WantLongs==true) { if ( price1 > Ask ) { entermode = OP_BUYSTOP; } else { entermode = OP_BUYLIMIT ; } OrderSend(Symbol(),entermode,Lots,price1,0,0,50,Name,1,0,Green); } return(0); } // the endThanks for any help, I hope it is just something stupid that I am missing, but it is driving me nuts.