//+------------------------------------------------------------------+//| Global Variables |//+------------------------------------------------------------------+#include <Trade\Trade.mqh>
CTrade trade;
//+------------------------------------------------------------------+//| Execute Once |//+------------------------------------------------------------------+voidOnInit()
{
//TestAlert("Expert Advisor has been launched");
//Order Setupint MagicNumber=123456; //--- set MagicNumber for your orders identification
trade.SetExpertMagicNumber(MagicNumber);
int deviation=10; //--- set available slippage in points when buying/selling
trade.SetDeviationInPoints(deviation);
trade.SetTypeFilling(ORDER_FILLING_RETURN); //--- order filling mode, the mode allowed by the server should be used
trade.LogLevel(1); //--- logging mode: it would be better not to declare this method at all, the class will set the best mode on its own
trade.SetAsyncMode(true); //--- what function is to be used for trading: true - OrderSendAsync(), false - OrderSend()//Trading Critera int x = 0;
if (x == 1){
HeraBuy();
}
else{
HeraSell();
}
}
//+------------------------------------------------------------------+//| End |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
Alert("Expert Advisor terminated");
}
//+------------------------------------------------------------------+//| Main Loop |//+------------------------------------------------------------------+ voidOnTick()
{
/*
double Bid;
Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
Alert("Your new Bid price is: " + string(Bid)); //Display the bid price continuously
*/
}
//+------------------------------------------------------------------+//| External Functions |//+------------------------------------------------------------------+int HeraSell(){
Alert("Hera is Selling");
//StopLoss & TakeProfit Setupdouble Bid;
double Ask;
double TakeProfit;
double StopLoss;
double TakeProfitLevel;
double StopLossLevel;
Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
TakeProfit = 60;
StopLoss = 60;
TakeProfitLevel = Bid - TakeProfit*Point(); //0.0001 // Take Profit value defined
StopLossLevel = Bid + StopLoss*Point(); // Stop loss value defined/*
//Code For 5-Digit Brokers
//Here we are assuming that the TakeProfit and StopLoss are entered in Pips
TakeProfitLevel = Bid + TakeProfit*Point*10; //0.00001 * 10 = 0.0001
StopLossLevel = Bid - StopLoss*Point*10;
*/if(!trade.Sell(0.1,_Symbol, Bid, StopLossLevel, TakeProfitLevel))
{
//--- failure messagePrint("Sell() method failed. Return code=",trade.ResultRetcode(),
". Code description: ",trade.ResultRetcodeDescription());
}
else
{
Print("Sell() method executed successfully. Return code=",trade.ResultRetcode(),
" (",trade.ResultRetcodeDescription(),")");
}
return(0);
}
int HeraBuy(){
Alert("Hera is Buying");
//StopLoss & TakeProfit Setupdouble Bid;
double Ask;
double TakeProfit;
double StopLoss;
double TakeProfitLevel;
double StopLossLevel;
Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
TakeProfit = 60;
StopLoss = 60;
TakeProfitLevel = Ask + TakeProfit*Point(); //0.0001 // Take Profit value defined
StopLossLevel = Ask - StopLoss*Point(); // Stop loss value defined/*
//Code For 5-Digit Brokers
//Here we are assuming that the TakeProfit and StopLoss are entered in Pips
TakeProfitLevel = Bid + TakeProfit*Point*10; //0.00001 * 10 = 0.0001
StopLossLevel = Bid - StopLoss*Point*10;
*/if(!trade.Buy(0.1,_Symbol, Ask, StopLossLevel, TakeProfitLevel))
{
//--- failure messagePrint("Buy() method failed. Return code=",trade.ResultRetcode(),
". Code description: ",trade.ResultRetcodeDescription());
}
else
{
Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(),
" (",trade.ResultRetcodeDescription(),")");
}
return(0);
}
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.
we have notices that when you remove StopLossLevel and TakeProfitLevel the error will go back to
10021
TRADE_RETCODE_PRICE_OFF
There are no quotes to process the request
then when you finally remove "Bid" from the parameters the code will work and execute a buy order
the only thing wrong with this is that there is obviously no stop loss, take profit or execution price where:
bool Buy( double volume, // position volume
const string symbol=NULL, // symbol double
price=0.0, // execution price
double sl=0.0, // stop loss price
double tp=0.0, // take profit price
const string comment=" " // comment )
my guess is that it does not like the variable bid, even though it works for other purposes and this is causing it to effect
the stop loss and take profit variable values which there causing the error 10016
10016
TRADE_RETCODE_INVALID_STOPS
Invalid stops in the request
WORKING NOW!
dont know how but its working now ?!!!
Corrected version: