You have many " return(0) "
That exits the program.
Example:
... if the funtion IsTradeAllowed returns true or false, go no further, exit the program...
if(IsTradeAllowed()==false)
{
Print("Expert non abilitato");
Acc=0;
return(0);
}
else
{
Print ("Expert abilitato");
Acc=1;
return(0);
}
... the rest of your code is NEVER executed
You have many " return(0) "
That exits the program.
Example:
... if the funtion IsTradeAllowed returns true or false, go no further, exit the
program...
if(IsTradeAllowed()==false)
{
Print("Expert non abilitato");
Acc=0;
return(0);
}
else
{
Print ("Expert abilitato");
Acc=1;
return(0);
}
... the rest of your code is NEVER executed
Thank you very much.
I resolved the entry problem, but now My EA do not exit long position when i want - according to the intentions I expressed trought the code below "Exit...".
//+------------------------------------------------------------------+ //| ADX-Stoch-SAR.mq4 | //| Copyright © 2008, SimonTrader. | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, MetaQuotes Software Corp." #property link "https://www.metaquotes.net/" extern double StopLoss = 20; extern double Lots = 0.1; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double MyADX_Celeste, MyADX_Rosso, MyADX_Blu, MySTOC_Rosso, MySTOC_Celeste, MySAR; int ticket, cnt, total, quadro; bool Acc, CondADXPrimoLong, CondADXSecLong; // initial data check if(Bars<100) { Print("bars less than 100"); } MyADX_Celeste=iADX(NULL,0,100,6,0,0); MyADX_Rosso=iADX(NULL,0,100,6,2,0); MyADX_Blu=iADX(NULL,0,100,6,1,0); MySTOC_Rosso=iStochastic(NULL,0,21,7,2,1,1,1,0); MySTOC_Celeste=iStochastic(NULL,0,21,7,2,1,1,0,0); MySAR=iSAR(NULL,0,0.09,0.7,0); CondADXPrimoLong=0; CondADXSecLong=0; quadro=0; if(MyADX_Blu>MyADX_Rosso && MyADX_Celeste<MyADX_Rosso) { CondADXPrimoLong=1; } if(MyADX_Blu<MyADX_Rosso && MyADX_Celeste<MyADX_Rosso) { CondADXSecLong=1; } total=OrdersTotal(); if(total<1) { // no opened orders identified if(AccountFreeMargin()<(1000*Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); } // check for long position (BUY) possibility //Primo Long if(CondADXPrimoLong==1 && MySTOC_Celeste<80 && MySAR<Ask) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,0,"trend sample",16800,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); } //Exit First Long Attempt for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()==OP_BUY & OrderMagicNumber()==16800) // long position is opened { quadro = 1; } } if(quadro==1) if(MySTOC_Celeste>90 || MySAR>Ask) OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); { CondADXPrimoLong=0; } //Secondo Long if(CondADXSecLong==1 && MyADX_Celeste>=((MyADX_Rosso-MyADX_Blu)/2 + MyADX_Blu) && MySTOC_Rosso<=16 && MySTOC_Celeste<=10 && MySAR<Ask) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,0,"swing sample",16300,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); } //Exit Second Long Attempt for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()==OP_BUY & OrderMagicNumber()==16300) // long position is opened { quadro = 2; } } if(quadro==2) if(MyADX_Celeste>=MyADX_Rosso || MyADX_Celeste<=MyADX_Blu || MySTOC_Celeste>90) OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); { CondADXSecLong=0; } } return(0); } //---- //---- //+------------------------------------------------------------------+
You now, I intended to exit the first long when Or parabolic SAR settles above the price line Or when Stochastic gets into overbought. Simply, my code doesn't recognize when to exit.
You're so gentle,
SimonTrader
You need to study your logic:
total=OrdersTotal();
if(total<1) {
...do a lot of stuff
What will happen when you have an open trade, that is, when total is equal to 1
?

- 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,
Can you please show me the conceptual errors in the code below. My aim was to try two long patterns on a ADX, Stochastic and SAR basis.
The matter is that - although the compilation returns no errors - no orders are processed/sent.
Many Thanks in advice.
SimonTrader
P.S: MyADX_Celeste means ADX MAIN LINE, MyADX_Rosso means ADX -DI LINE, MyADX_Blu means ADX +DI LINE, MySTOC_Rosso means Stochastic SIGNAL LINE, MySTOC_Celeste means Sthocastic MAIN LINE.