Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 99
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Dratuti. How do you make a panel like this?
Dratuti. How do you make a panel like this?
Dratuti. How do you make a panel like this?
Vitaly Muzichenko,Artyom Trishkin thank you.
Continuing to write another piggybacking on martingale, losing even in the tester, otherwise how are we supposed to grow a moose.
At the moment there is a desired parameter, which should be responsible for the possibility to open the next order after the previous one(s) is(are) closed
there are 2 scenarios
1) if the value is true
open an order
process
close
and reopen
2) if false
Open the order
Process
Close
and then do ExpertRemove
the whole problem is that these two conditions are mutually exclusive, but they have to be combined in 1 EA since
1) value is set at the start
2) the value is set in the input and processing conditions and accepted for processing (if true, open)
3) after closing, we set false
If anyone is interested in such things, I would be happy to hear my variants.It's simple:
We have problems with logic.
Everything is simple:
Something doesn't seem right, if true - you should be chopping cabbage, not in the bushes)
Please advise. The Expert Advisor does not open orders in the terminal. The compilation is going on, according to the charts the orders should be opened. But they are not. I am attaching the code.
double Lots=NormalizeDouble((AccountFreeMargin()/100*Percent)/MarketInfo(Symbol(),MODE_MARGINREQUIRED),1);//determine the number of lots
double MacdCurrent=iMACD(NULL,0,Fast_EMA_Period,Slow_EMA_Period,Signal_Period,PRICE_MEDIAN,MODE_MAIN,0);// MACD parameters of the current bar
double MacdPrevious1=iMACD(NULL,0,Fast_EMA_Period,Slow_EMA_Period,Signal_Period,PRICE_MEDIAN,MODE_MAIN,1);//the MACD parameters of the previous bar
double MacdPrevious2=iMACD(NULL,0,Fast_EMA_Period,Slow_EMA_Period,Signal_Period,PRICE_MEDIAN,MODE_MAIN,2);//the MACD parameters of the main line offset by 2 bars
double StopLoss=iSAR(NULL,Period(),Step_PSAR,Maximum_PSAR,0);//Parameters Trailing Stop by ParabolicSAR parameters of the current bar
double Previous_StopLoss=iSAR(NULL,Period(),Step_PSAR,Maximum_PSAR,1);//StopLoss parameters by ParabolicSAR parameters of the previous bar
double PSARCurrent=iSAR(NULL,Period(),Step_PSAR,Maximum_PSAR,0);//parameters ParabolicSAR of the current bar
double PSARPrevious=iSAR(NULL,Period(),Step_PSAR,Maximum_PSAR,1);//ParabolicSAR parameters of the previous bar
//+------------------------------------------------------------------+
//| Expert tick function|
//+------------------------------------------------------------------+
void OnTick()
{
static datetime New_Time=TimeCurrent();// Time of the current bar
bool New_Bar=false; // Flag new bar
int ticket,total,cnt;
//---------------------------------------------------------------------------
{
New_Bar=false; // No new bar
if(Time[0]==New_Time) // Compare times
{
New_Bar=true; // New_Bar is caught
if(New_Bar==false) // If a bar is not new
return; // ...then exit
}
}
total=OrdersTotal();// Determination of the number of orders
if(total<1)
{
//---no open orders
if((AccountFreeMargin()/100*Percent)<MarketInfo(Symbol(),MODE_MARGINREQUIRED)*(MarketInfo(Symbol(),MODE_MINLOT))
//Check for availability of funds to open the minimum lot
{
Print("Not enough funds. Free funds = ",AccountFreeMargin());
return;
}
//---condition for long position opening (BUY)
if((MacdCurrent>0 && MacdPrevious1<=0 && MacdPrevious2<0)
&&
PSARCurrent<iOpen(NULL,0,1))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,StopLoss,0,NULL,MAGICNUMBER,0,Green);
if(ticket>0)//check position opened
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order open : ",OrderOpenPrice());
else
Print("BUY order open error : ",GetLastError());
return;
}
}
//---condition for opening a short position (SELL)
if((MacdCurrent<0 && MacdPrevious1>=0 && MacdPrevious2>0)
&&
PSARCurrent>iOpen(NULL,0,1))
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,StopLoss,0,NULL,MAGICNUMBER,0,Red);
if(ticket>0)//check position opened
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order open : ",OrderOpenPrice());
else
Print("Error opening SELL order : ",GetLastError());
return;
}
}
//--- exit the "no open orders" block
}
//---it is important to enter the market correctly but it is more important to exit it correctly
for(cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MAGICNUMBER && // check the magic number of the order
OrderSymbol()==Symbol()) // check for the order symbol
{
//--- long position opened
if(OrderType()==OP_BUY)
{
//--- must be closed?
if((MacdCurrent<0 && MacdPrevious1>=0 && MacdPrevious2>0)
&&
PSARCurrent>iOpen(NULL,0,1))
{
//--- order close and exit
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
Print("OrderClose error ",GetLastError());
return;
}
//------------------Modify order by StopLoss
if(StopLoss>Previous_StopLoss && StopLoss<iOpen(NULL,0,0))
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Previous_StopLoss,0,0,Blue))
Print(" Ordermodification error. Error code=",GetLastError());
else
Print("Stop Loss price of the order has been successfully modified;)
return;
}
}
else // go short
if(OrderType()==OP_SELL)
{
//--- must be closed?
if((MacdCurrent>0 && MacdPrevious1<=0 && MacdPrevious2<0)
&&
PSARCurrent<iOpen(NULL,0,1))
{
//--- order close and exit
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
Print("OrderClose error ",GetLastError());
return;
}
//-----------------Modify order by StopLoss
if(StopLoss<Previous_StopLoss && StopLoss>iOpen(NULL,0,0))
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Previous_StopLoss,0,0,Blue))
Print("Order modification error. Error code=",GetLastError());
else
Print("Stop Loss price of the order has been successfully modified;)
return;
}
}
}
//-------------------------------------------------------------------------------------------------------
Yeah, it's simpler than that.
but what if we keep this as a fallback and do the following
check the condition and...i.e. how then to block the input for further operation