Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 99

 

Dratuti. How do you make a panel like this?

 
Andrey Sokolov:

Dratuti. How do you make a panel like this?

Take the example from kodobase and redo it, there are plenty of advisors with panels for every taste. It starts with the background
 
Andrey Sokolov:

Dratuti. How do you make a panel like this?

With graphical objects.
 
 
Andrey Sokolov:
Vitaly Muzichenko,Artyom Trishkin thank you.
Nzt
 
trader781:

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.
I have problems with logic.

It's simple:

  1. open an order
  2. process the order
  3. close the order
  4. Check the condition and...
    • if true, then ExpertRemove()
  5. Again
 
Artyom Trishkin:
We have problems with logic.

Everything is simple:

  1. open an order
  2. process the order
  3. close the order
  4. check the condition and...
    • if true, then ExpertRemove()
  5. and do it again
Something seems wrong, if it's true - you have to chop a cabbage, not go to the bushes)
 
Vitaly Muzichenko:
Something doesn't seem right, if true - you should be chopping cabbage, not in the bushes)
Wrong. False. I don't know what the test is... Shit, there's still some logic to it.
Or do you just want to chat?
 

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;
}
}
}

//-------------------------------------------------------------------------------------------------------

 
trader781:

Yeah, it's simpler than that.

but what if we keep this as a fallback and do the following

check the condition and...
  • if true, then the bot hangs with minimal activity, preferably none at all

i.e. how then to block the input for further operation

return(0); but this is not desirable - it won't handle anything else.
Reason: