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
here is my function for mt4 ecn, ndd, stp ...
Not a single error in a year
//+----------------------------------------------------------------------------+
//| Order opening function (BeerGod) |
//+----------------------------------------------------------------------------+
//| Parameters: |
//| sy - instrument name ("" - current symbol) |
//| op - operation |
| //| ll - lot |
//| sl - stop level |
//| tp - take level |
//| mn - MagicNumber |
//+----------------------------------------------------------------------------+
bool OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, int MagicNumber=0)
{
double MinLl = MarketInfo(Symbol(),MODE_MINLOT);
double MaxLl = MarketInfo(Symbol(),MODE_MAXLOT);
ll = NormalizeDouble(ll,2);
if (ll < MinLl) ll = MinLl; else ll = ll;
if (ll > MaxLl) ll = MaxLl; else ll = ll;
if (op == 0) // BUY opening
{
// Check if free funds are available
if((AccountFreeMarginCheck(sy,OP_BUY,ll)<=0) || (GetLastError()==134))
{
Print(sy," ",ll," It is impossible to open the order Buy, not enough money.");
return(0);
}
RefreshRates();
// Open order
int ticketbuy = OrderSend(sy,OP_BUY,ll,MarketInfo(sy,MODE_ASK),Slippage,0,0,Comments,MagicNumber,0,BuyColor);
if(ticketbuy<0)
Print(sy," OpenPosition. OrderSend Buy fail #",GetLastError());
else
Print(sy," OpenPosition. OrderSend Buy successfully");
// Sleep (Pause);
// Modify the order (set take profit and stop loss)
if (sl !=0 || tp !=0)
{
//--- Calculated SL and TP prices must be normalized
double BSLoss = NormalizeDouble(MarketInfo(sy,MODE_ASK)-sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS))
double BTProfit = NormalizeDouble(MarketInfo(sy,MODE_ASK)+tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
//--- If the input value is zero, replace the modification price with zero
if (sl == 0) BSLoss = 0;
if (tp == 0) BTProfit = 0;
bool resbuy = OrderModify (ticketbuy,OrderOpenPrice(),BSLoss,BTProfit,0,StopColor);
if(!resbuy)
Print(sy," OpenPosition. OrderModify Buy fail #",GetLastError());
else
Print(sy," OpenPosition. OrderModify Buy successfully");
}
}
if (op == 1) // Open Sell.
{
// Check availability of free funds
if((AccountFreeMarginCheck(sy,OP_SELL,ll)<=0) || (GetLastError()==134))
{
Print(sy," ",ll," It is impossible to open the order Sell, not enough money.");
return(0);
}
RefreshRates();
// Open order
int ticketsell = OrderSend(sy,OP_SELL,ll,MarketInfo(sy,MODE_BID),Slippage,0,0,Comments,MagicNumber,0,SellColor);
if(ticketsell<0)
Print(sy," OpenPosition. OrderSend Sell fail #",GetLastError());
else
Print(sy," OpenPosition. OrderSend Sell successfully");
// Sleep (Pause);
// Modify the order (set take profit and stop loss)
if (sl !=0 || tp !=0)
{
//--- The calculated SL and TP prices must be normalized
double SSLoss = NormalizeDouble(MarketInfo(sy,MODE_BID)+sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS))
double STProfit = NormalizeDouble(MarketInfo(sy,MODE_BID)-tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
//--- If the input value is zero, replace the modification price with zero
if (sl == 0) SSLoss = 0;
if (tp == 0) STProfit = 0;
bool ressell = OrderModify (ticketsell,OrderOpenPrice(),SSLoss,STProfit,0,StopColor);
if(!ressell)
Print(sy," OpenPosition. OrderModify Sell fail #",GetLastError());
else
Print(sy," OpenPosition. OrderModify Sell successfully");
}
}
return(True);
}
//End
P.S. Moderators, the code cannot be inserted via the button.
I'm giving free (no charge) online Skype lessons on code insertion:)
I give free (no charge) online Skype lessons on code insertion:)
I give free (no charge) online Skype lessons on code insertion:)
Thank you!
Done, if you have any questions about the code write, also available in person or on Skype
ready, if you have any questions about the code, email or Skype
The Alert comes out with the message: No price. We wait for new tick...
I had a demo account that worked fine and opened a trade on the first try. I need more details.