Please use this to post code . . . it makes it easier to read.
- use SRC
- for LARGE postings - attach the file
- post ALL the code
int init(){ int iTotalTrades=1; // This definition hides the global variable, return(0); // so nothing is done here }
for(int pos=0; pos<iTotalTrades; pos++) { if(OrderSelect(pos, SELECT_BY_POS,MODE_TRADES)==false) continue; if( (( OrderSymbol() == Symbol() ) ) && (( OrderMagicNumber() == iMagicNumber ) ) ) {
No need for multiple indents and multiple statements. You want to 'select all EA's orders.' One sentence, so one statement is better codingfor(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and my pair.
Always count down in the presence of multiple orders (multiple charts)
- Of course I do. if (bool == true) is the same as if (bool) (true==true is the same as true) I posted if (orderSelect(...) && ...
- you have a global int iTotalTrades; Inside init you also have a local int iTotalTrade; which hides the global one. Just set iTotalTrade=1; (NO INT)
O by the way here is my complete code for the simplest entry signal, but it will not make a trade.
please help thanks.
- ray2955:Not making trade is not the same as
O by the way here is my complete code for the simplest entry signal, but it will not make a trade.When using test strat the chart doesnt move.There's nothing there at would hang the chart. Add print statements for your open criteria variable and find out why.
The EA has the capability to open more than one, yet on the first closeOrder, you return. Keep looping.
Hi, yes it s not hanging up now it was in my opening trade logic.
I removed it and I'm starting with as little as possible just to get it
to trade .As you can see I put many print fn, but I'm not getting
any print statements to guide me to my code problems.
I'm a newbe and so there are holes in what i know.
Are the print statements good? and reading them during runtime
is done in the expert log?
Also I need help on proper placement of the return; on a complex fn.
I purchased an E-book on programming mql and its not clear on placement.
Example:
if(OrderType() == OP_BUY )
{
bOrderCloseStatus = OrderClose( OrderTicket(), OrderLots(), Bid, iSlippage, Red );
if ( bOrderCloseStatus == false )
{
iErrorNumber = GetLastError();
strErrorMessage = ErrorDescription(iErrorNumber);
Print( "OrderClose Failed: ", strErrorMessage );
return; here or
}
return; here
}
Thanks for help.
If you are running your EA in the Strategy tester the Print statement output is seen in the Strategy Tester Journal tab . . .
Your example above is not a function . . . this is a function with a function definition . . void A_Funtion_Name()
void A_Funtion_Name() { if(OrderType() == OP_BUY ) { bOrderCloseStatus = OrderClose( OrderTicket(), OrderLots(), Bid, iSlippage, Red ); if ( bOrderCloseStatus == false ) { iErrorNumber = GetLastError(); strErrorMessage = ErrorDescription(iErrorNumber); Print( "OrderClose Failed: ", strErrorMessage ); } } return; // return here ! }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi i'm a newbe and i made an EA that compiled and loads successfully on to a chart.
When using test strat the chart doesnt move. I put print statements at the Start () and other
funtions() to see where it might be hanging up. But no displays at expert bar.
Is there any suggestions. Thanks.
Eample:
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net//"
#include <stderror.mqh>
#include <stdlib.mqh>
extern double dlots=0.1;
extern double iStopLoss=20;
extern double iTakeProfit=20;
extern int iSlippage=3;
extern int iMaxTrades=1;
extern int iMagicNumber=1400;
int iTradeSignal=0;
int iOpenBuySignal=100;
int iCloseBuySignal=-200;
int iOpenSellSignal=300;
int iCloseSellSignal=-400;
int iNoSignal=-1;
int ilastTradeType;
int iTotalTrades;
int iTotalSelectedTrades;
int iTotalBuyTrades;
int iTotalSellTrades;
int ilastTradeOpenTime;
bool bOrderCloseStatus;
double dTotalTradelots;
double dTotalTradeSwap;
double dTotalOpenProfit;
double dlastTradeOpenPrice;
double dlastTradeStoploss;
double dlastTradeTakeProfit;
double dlastTradeType;
double dlastTradeTicket;
string strLastTradeSymbol;
string strLastTradeComment;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
int iTotalTrades=1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
Print( " Start " );
//-----------------------------
fnGetOpenTradeInfo();
fnOpenBuyLogic();
fnOpenSellLogic();
bool b_Check_New_Bar=false;
b_Check_New_Bar = Function_New_Bar(); // Function call
fnCloseBuyLogic();
fnCloseSellLogic();
fnOpenOrders();
fnCloseOrders();
//-----------------------------
return(0);
}
//+------------------------------------------------------------------+
void fnGetOpenTradeInfo()
{
Print( " 1st function call " );
dTotalOpenProfit=0;
dTotalTradelots =0;
iTotalBuyTrades=0;
iTotalSellTrades=0;
dTotalTradeSwap=0;
iTotalSelectedTrades=0;
iTotalTrades=OrdersTotal();
for(int pos=0; pos<iTotalTrades; pos++)
{
if(OrderSelect(pos, SELECT_BY_POS,MODE_TRADES)==false)
continue;
if( (( OrderSymbol() == Symbol() ) ) && (( OrderMagicNumber() == iMagicNumber ) ) )
{
iTotalSelectedTrades++;
dTotalOpenProfit += OrderProfit();
dTotalTradeSwap += OrderSwap();
dTotalTradelots += OrderLots();
if( OrderType() == OP_BUY )
{
iTotalBuyTrades++;
ilastTradeType = OP_BUY;
}
if( OrderType() == OP_SELL )
{
iTotalBuyTrades++;
ilastTradeType = OP_SELL;
}
}
}
}
//========================================
void fnOpenBuyLogic()
{
Print( " Buy-logic Close1 Open1 ",Close[1]," ",Open[1] );