Can you attach code file here?
--- Define some MQL5 Structures we will use for our trade MqlTick Last_Price; // To be used for getting recent/latest price quotes MqlTradeCheckResult CheckResult; MqlTradeTransaction mtrans; // To be used to get our trade transactions MqlTradeRequest mrequest; // To be used for sending our trade requests MqlTradeResult mresult; // To be used to get our trade results MqlRates mrate[]; // To be used to store the prices, volumes and spread of each bar bool success =OrderSend(mrequest,mresult); MqlTradeRequest request={0}; /* Let's make sure our arrays values for the Rates, ADX Values and MA values is store serially similar to the timeseries array */ // the rates arrays ArraySetAsSeries(mrate,true); // the ADX DI+values array ArraySetAsSeries(plsDI,true); // the ADX DI-values array ArraySetAsSeries(minDI,true); // the ADX values arrays ArraySetAsSeries(adxVal,true); // the MA-8 values arrays ArraySetAsSeries(maVal,true); //--- Get the last price quote using the MQL5 MqlTick Structure if(!SymbolInfoTick(_Symbol,Last_Price)) { Alert("Error getting the latest price quote - error:",GetLastError(),"!!"); return; } //--- Get the details of the latest 3 bars if(CopyRates(_Symbol,_Period,0,3,mrate)<0) { Alert("Error copying rates/history data - error:",GetLastError(),"!!"); return; } //--- Copy the new values of our indicators to buffers (arrays) using the handle if(CopyBuffer(adxHandle,0,0,3,adxVal)<0 || CopyBuffer(adxHandle,1,0,3,plsDI)<0 || CopyBuffer(adxHandle,2,0,3,minDI)<0) { Alert("Error copying ADX indicator Buffers - error:",GetLastError(),"!!"); return; } if(CopyBuffer(maHandle,0,0,3,maVal)<0) { Alert("Error copying Moving Average indicator buffer - error:",GetLastError()); return; } //--- we have no errors, so continue //--- Do we have positions opened already? bool Buy_opened=false; // variable to hold the result of Buy opened position bool Sell_opened=false; // variable to hold the result of Sell opened position if (PositionSelect(_Symbol) ==true) // we have an opened position { if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { Buy_opened = true; //It is a Buy } else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { Sell_opened = true; // It is a Sell } } /* 1. Check for a long/Buy Setup : MA-8 increasing upwards, previous price close above it, ADX > 22, +DI > -DI */ //--- Declare bool type variables to hold our Buy Conditions bool Buy_Condition_1 = (maVal[0]>maVal[1]) && (maVal[1]>maVal[2]); // MA-8 Increasing upwards bool Buy_Condition_2 = (p_close > maVal[1]); // previuos price closed above MA-8 bool Buy_Condition_3 = (adxVal[0]>Adx_Min); // Current ADX value greater than minimum value (22) bool Buy_Condition_4 = (plsDI[0]>minDI[0]); // +DI greater than -DI //--- Putting all together if(Buy_Condition_1 && Buy_Condition_2) { if(Buy_Condition_3 && Buy_Condition_4) { // any opened Buy position? if (Buy_opened) { Alert("We already have a Buy Position!!!"); return; // Don't open a new Buy Position } mrequest.action = TRADE_ACTION_DEAL; // immediate order execution mrequest.price = NormalizeDouble(Last_Price.ask,_Digits); // latest ask price mrequest.sl = NormalizeDouble(Last_Price.ask - STP*_Point,_Digits); // Stop Loss mrequest.tp = NormalizeDouble(Last_Price.ask + TKP*_Point,_Digits); // Take Profit mrequest.symbol = _Symbol; // currency pair mrequest.volume = Lot; // number of lots to trade mrequest.magic = EA_Magic; // Order Magic Number mrequest.type = ORDER_TYPE_BUY; // Buy Order mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type mrequest.deviation=100; // Deviation from current price //--- sending the order success =OrderSend(mrequest,mresult); Print("Return code of the trade server ",success); { // get the result code if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed { Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!"); } else { Alert("The Buy order request could not be completed -error:",GetLastError()); ResetLastError(); } if(!success) { Print("TradeLog: Trade request failed. Error = ",GetLastError()); return; } {The error massage is: Failed prices for 0.00 [Invalid Request] Please I need help to trade with this EA
Change this part :
MqlTick Last_Price; // To be used for getting recent/latest price quotes MqlTradeCheckResult CheckResult; MqlTradeTransaction mtrans; // To be used to get our trade transactions MqlTradeRequest mrequest={0}; // To be used for sending our trade requests MqlTradeResult mresult; // To be used to get our trade results MqlRates mrate[]; // To be used to store the prices, volumes and spread of each bar bool success =OrderSend(mrequest,mresult); MqlTradeRequest request={0};
MqlTradeRequest request; MqlTradeResult result; ZeroMemory(request); ZeroMemory(result);
please send all code for compile and test
What is the purpose of "={0}", and why the special brackets instead of the regular square brackets?
theDUDE:
It's from C, used to initialize a structure. What is the purpose of "={0}", and why the special brackets instead of the regular square brackets?
ugwubless:
Thanks I have made the changes but the compiler has this massage; The return value of OrderSend need to be checked. So what do I do next?
The compiler warning is harmless. But if you want to get rid of it, the simplest way is assign the result of OrderSend to a boolean variable, just like on the code you previously posted.
Thanks I have made the changes but the compiler has this massage; The return value of OrderSend need to be checked. So what do I do next?
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
My EA have this massage; Failed request for 0.00 [Invalid request]. What do I do?
--- Define some MQL5 Structures we will use for our trade
MqlTick Last_Price; // To be used for getting recent/latest price quotes
MqlTradeCheckResult CheckResult;
MqlTradeTransaction mtrans; // To be used to get our trade transactions
MqlTradeRequest mrequest; // To be used for sending our trade requests
MqlTradeResult mresult; // To be used to get our trade results
MqlRates mrate[]; // To be used to store the prices, volumes and spread of each bar
bool success =OrderSend(mrequest,mresult);
MqlTradeRequest request={0};
/*
Let's make sure our arrays values for the Rates, ADX Values and MA values
is store serially similar to the timeseries array
*/
// the rates arrays
ArraySetAsSeries(mrate,true);
// the ADX DI+values array
ArraySetAsSeries(plsDI,true);
// the ADX DI-values array
ArraySetAsSeries(minDI,true);
// the ADX values arrays
ArraySetAsSeries(adxVal,true);
// the MA-8 values arrays
ArraySetAsSeries(maVal,true);
//--- Get the last price quote using the MQL5 MqlTick Structure
if(!SymbolInfoTick(_Symbol,Last_Price))
{
Alert("Error getting the latest price quote - error:",GetLastError(),"!!");
return;
}
//--- Get the details of the latest 3 bars
if(CopyRates(_Symbol,_Period,0,3,mrate)<0)
{
Alert("Error copying rates/history data - error:",GetLastError(),"!!");
return;
}
//--- Copy the new values of our indicators to buffers (arrays) using the handle
if(CopyBuffer(adxHandle,0,0,3,adxVal)<0 || CopyBuffer(adxHandle,1,0,3,plsDI)<0
|| CopyBuffer(adxHandle,2,0,3,minDI)<0)
{
Alert("Error copying ADX indicator Buffers - error:",GetLastError(),"!!");
return;
}
if(CopyBuffer(maHandle,0,0,3,maVal)<0)
{
Alert("Error copying Moving Average indicator buffer - error:",GetLastError());
return;
}
//--- we have no errors, so continue
//--- Do we have positions opened already?
bool Buy_opened=false; // variable to hold the result of Buy opened position
bool Sell_opened=false; // variable to hold the result of Sell opened position
if (PositionSelect(_Symbol) ==true) // we have an opened position
{
if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
{
Buy_opened = true; //It is a Buy
}
else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
{
Sell_opened = true; // It is a Sell
}
}
/*
1. Check for a long/Buy Setup : MA-8 increasing upwards,
previous price close above it, ADX > 22, +DI > -DI
*/
//--- Declare bool type variables to hold our Buy Conditions
bool Buy_Condition_1 = (maVal[0]>maVal[1]) && (maVal[1]>maVal[2]); // MA-8 Increasing upwards
bool Buy_Condition_2 = (p_close > maVal[1]); // previuos price closed above MA-8
bool Buy_Condition_3 = (adxVal[0]>Adx_Min); // Current ADX value greater than minimum value (22)
bool Buy_Condition_4 = (plsDI[0]>minDI[0]); // +DI greater than -DI
//--- Putting all together
if(Buy_Condition_1 && Buy_Condition_2)
{
if(Buy_Condition_3 && Buy_Condition_4)
{
// any opened Buy position?
if (Buy_opened)
{
Alert("We already have a Buy Position!!!");
return; // Don't open a new Buy Position
}
mrequest.action = TRADE_ACTION_DEAL; // immediate order execution
mrequest.price = NormalizeDouble(Last_Price.ask,_Digits); // latest ask price
mrequest.sl = NormalizeDouble(Last_Price.ask - STP*_Point,_Digits); // Stop Loss
mrequest.tp = NormalizeDouble(Last_Price.ask + TKP*_Point,_Digits); // Take Profit
mrequest.symbol = _Symbol; // currency pair
mrequest.volume = Lot; // number of lots to trade
mrequest.magic = EA_Magic; // Order Magic Number
mrequest.type = ORDER_TYPE_BUY; // Buy Order
mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type
mrequest.deviation=100; // Deviation from current price
//--- sending the order
success =OrderSend(mrequest,mresult);
Print("Return code of the trade server ",success);
{
// get the result code
if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
{
Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
}
else
{
Alert("The Buy order request could not be completed -error:",GetLastError());
ResetLastError();
}
if(!success)
{
Print("TradeLog: Trade request failed. Error = ",GetLastError());
return;
}
{