I have developed a Forex Bot and tested in demo account it worked fine. But I deployed in the real account its not working properly.
I don't know what is wrong. While searching on internet its seems broker scam. Why is it working on demo account but not in real account?
#include<Trade\Trade.mqh>
CTrade trade;
CTrade m_trade; // Trades Info and Executions library
COrderInfo m_order; //Library for Orders information
CPositionInfo m_position; // Library for all position features and information
input double lot=0.01;
input double lots=0.02;
int EMA = iMA(_Symbol,PERIOD_CURRENT,_Period,200,MODE_EMA,PRICE_HIGH);
double TargetProfitPercentage = 5;
void OnTick() // it works on every tick
{
//---
buyOrder();
profitCalc();
}
void buyOrder() // to place buy order
{
//Get the Ask price
double GBPUSDAsk = NormalizeDouble(SymbolInfoDouble("GBPUSD",SYMBOL_ASK),_Digits);
//Get the Ask price
double EURUSDAsk = NormalizeDouble(SymbolInfoDouble("EURUSD",SYMBOL_ASK),_Digits);
//Get the Ask price
double USDJPYAsk = NormalizeDouble(SymbolInfoDouble("USDJPY",SYMBOL_ASK),_Digits);
//if we have no Open positions
if(PositionsTotal()==0)
{
{
//Open buy position
trade.Buy(lots,"USDJPY",USDJPYAsk,0,0,NULL);
//Open buy position
trade.Buy(lot,"GBPUSD",GBPUSDAsk,0,0,NULL);
//Open buy position
trade.Buy(lot,"EURUSD",EURUSDAsk,0,0,NULL);
}
Comment("BUY ORDER PLACED");
}
}
void profitCalc() // Profit calculations
{
//if positions for this currency pair exists
if(PositionSelect(_Symbol)==true)
// loop all Open Positions until zero
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
//Calculate the Ticket number
ulong PositionTicket = PositionGetTicket(i);
//Calculate the Curremcy pair
string PositionSymbol = PositionGetString(POSITION_SYMBOL);
//Calculate the Openprice
string PositionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
//Calculate the PositionProfit
string PositionProfit = PositionGetDouble(POSITION_PROFIT);
//Calculate the PositionSwap
string PositionSwap = PositionGetDouble(POSITION_SWAP);
//Calculate the currentposition Net profit
string PositionNetProfit = PositionProfit+PositionSwap;
//Get the account balance
double Balance = AccountInfoDouble(ACCOUNT_BALANCE);
//Get the Equity
double Equity = AccountInfoDouble(ACCOUNT_EQUITY);
//Get Real profit
double RealProfit = Equity - Balance;
//Get the Profit or Loss Percentage
double CurrectProfitOrLossPercentage = RealProfit/Balance*100;
if(PositionSymbol==_Symbol)
{
Comment(
"PositionOpenPrice : ", PositionOpenPrice + "\n",
"PositionProfit : ", PositionProfit + "\n",
"PositionSwap : ", PositionSwap + "\n",
"PositionNetProfit : ", PositionNetProfit + "\n",
"Balance : ", Balance + "\n",
"Equity : ", Equity + "\n",
"RealProfit : ", RealProfit + "\n",
"Currect Profit Or Loss Percentage : ", CurrectProfitOrLossPercentage + "\n"
);
}
if(CurrectProfitOrLossPercentage > TargetProfitPercentage)
{
OrderClose();
closePendingOrder();
}
}
}
void OrderClose() // To close the orders
{
for(int i = PositionsTotal() - 1; i >= 0; i--) // loop all Open Positions
if(m_position.SelectByIndex(i)) // select a position
{
m_trade.PositionClose(m_position.Ticket()); // then delete it --period
}
}
void closePendingOrder()
{
for(int i = OrdersTotal() - 1; i >= 0; i--) // loop all orders available
if(m_order.SelectByIndex(i)) // select an order
{
m_trade.OrderDelete(m_order.Ticket()); // delete it --Period
}
}