Hi when I Compile I get no errors or warnings but still wont work :( any help? I'm trying to get it to place a trade is the same direction if it was in profit or reverse if not. Based off last trade in history.
externdouble LotSize=0.01;
double pips;
externdouble My_Money_Profit_Target=1;
externdouble My_Money_Profit_Loss=-1;
int Slippage=5;
int b;
//int ticket;//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---double ticksize=MarketInfo(Symbol(),MODE_TICKSIZE);
if(ticksize==0.0001 || ticksize==0.001)
pips=ticksize*10;
else pips=ticksize;
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+int start()
{
bool ut;
if ((Orders()==True) && (UpTradeP()==True))ut=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,NULL,Red);
if ((Orders()==True) && (UpTradeL()==True))ut=OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,NULL,NULL,Green);
bool dt;
if ((Orders()==True) && (DownTradeP()==True))dt=OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,NULL,NULL,Red);
if ((Orders()==True) &&(DownTradeL()==True))dt=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,NULL,Green);
bool a;
if (AccountProfit()>= My_Money_Profit_Target|| AccountProfit()<= My_Money_Profit_Loss)
{
for(b=OrdersTotal()-1;b>=0;b--)
{
a=OrderSelect(b, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positionscase OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
break;
//Close opened short positionscase OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
}
if(result == false)
{
Sleep(3000);
}
}
Print ("Account Profit Reached. All Open Trades Have Been Closed");
return(0);
}
Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
"\nMy Account Profit Target: ",My_Money_Profit_Target);
return(0);
}
///////////////////////////////////////////////////////////////////////////////////////////////bool Orders()
{
if(OrdersTotal()==0)
return(true);
elsereturn(false);
}
//////////////////////////////////////////////////////////////////////////////////////////////////bool DownTradeP()
{
for(int dp=OrdersTotal()-1; dp >= 0; dp--)
{
if (OrderSelect(dp,SELECT_BY_POS,MODE_HISTORY))
if((OrderType()==OP_SELL)&& (OrderProfit()>0))
return(True);
elsereturn(False);
}
return(0);
}
////////////////////////////////////////////////////////////////bool DownTradeL()
{
for(int dl=OrdersTotal()-1; dl >= 0; dl--)
{
if (OrderSelect(dl,SELECT_BY_POS,MODE_HISTORY))
if((OrderType()==OP_SELL)&&(OrderProfit()<0))
return(True);
elsereturn(False);
}
return(0);
}
///////////////////////////////////////////////////////////////bool UpTradeP()
{
for(int up=OrdersTotal()-1; up >= 0; up--)
{
if (OrderSelect(up,SELECT_BY_POS,MODE_HISTORY))
if((OrderType()==OP_BUY )&&(OrderProfit()>0))
return(True);
elsereturn(False);
}
return(0);
}
///////////////////////////////////////////////////////////////bool UpTradeL()
{
for(int ul=OrdersTotal()-1; ul >= 0; ul--)
{
if (OrderSelect(ul,SELECT_BY_POS,MODE_HISTORY))
if((OrderType()==OP_BUY )&& (OrderProfit()<0))
return(True);
elsereturn(False);
}
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.
Hi when I Compile I get no errors or warnings but still wont work :( any help? I'm trying to get it to place a trade is the same direction if it was in profit or reverse if not. Based off last trade in history.