Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1069
![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
CloseAllBuy() is called in a single place: in the OnTick() function by the condition if(Bid>buycloseprice) CloseAllBuy(); this condition did not occur at the new enablement and also did not occur during the disablement period, but the CloseAllBuy() function was triggered anyway when the EA was enabled again.
Here's a piece of code:
is not visible.
Question:could you please advise how exactly in this case to apply a global variable. I cannot figure it out. Thank you.
Read documentationGlobal variables of the terminal, check help of the meta-editor, it is more quick to update there.
Alternatively, you can save settings and values of important variables to a file and read them from there when loading.
But most of the time you can do without all this, just use your head and make the right logic in the code.
total=OrdersTotal();
if(total>0)
{
for(int i=0; i<=OrdersTotal(); i++)
if(OrderSelect(i,SELECT_BY_POS)==true)
{
if(OrderType()==OP_BUY && OrderMagicNumber()==magic)
{ RefreshRates();
if(Bid>buycloseprice) CloseAllBuy();
}
if(OrderType()==OP_SELL && OrderMagicNumber()==magic)
{ RefreshRates();
if(Ask<sellcloseprice) CloseAllSell();
}
}
}
if((total==0) || (total>0 && OrderSelect(1,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()!=Symbol())
{
Comment("No open positions");
if(condition && timeBar!=iTime(Symbol(),Period(),1))
{
Print("Criterion-1 for BAY has appeared");
int poz_1 = OrderSend(Symbol(),OP_BUY,lot,Ask,slip,0,0,NULL,magic,Blue);
Sleep(1000);
RefreshRates();
int poz_2 = OrderSend(Symbol(),OP_BUY,lot,Ask,slip,0,0,NULL,magic,Blue);
Sleep(1000);
RefreshRates();
int poz_3 = OrderSend(Symbol(),OP_BUY,lot,Ask,slip,0,0,NULL,magic,Blue);
Sleep(1000);
RefreshRates();
int poz_4 = OrderSend(Symbol(),OP_BUY,lot,Ask,slip,0,0,NULL,magic,Blue);
Sleep(1000);
RefreshRates();
int poz_5 = OrderSend(Symbol(),OP_BUY,lot,Ask,slip,0,0,NULL,magic,Blue);
timeBar=iTime(Symbol(),Period(),1);
double spread = (Ask-Bid);
buyopentime = iTime(Symbol(),Period(),0);
buycloseprice = NormalizeDouble((iOpen(Symbol(),Period(),0)+spread+75*Point),Digits);
Comment("Magic 510015 BAY");
Print("CLOSE PRICE = ",buycloseprice);
}
}
}
//+------------------------------------------------------------------+*/
void CloseAllBuy()
{
bool fc;
for (int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if (OrderType()==OP_BUY)
{
fc=OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),slip);
buycloseprice=0.0;
tc=OrderCloseTime();
}
}
}
Repeating in text:
It is still not clear where buycloseprice comes from, what happens to it before conditionif(Bid>buycloseprice) CloseAllBuy();. Because I see only this, after - buycloseprice = NormalizeDouble((iOpen(Symbol(), Period(), 0)+spread+75*Point), Digits);, but where thisbuycloseprice is declared and how is it initialized?
If this is the supposed closing price of a buy order, the logic breaks down here because the value is passed to the variable after it has been triggered and you haven't shown us what was in it before.
Now a bit of arithmetic, there is such a loop in the code:
for(int i=0; i<=OrdersTotal(); i++)
Let's say, there are 5 orders ranging from 0 to 4. The loop counts from 0 to 5. Does this loop work correctly?
Also, in the if(condition && timeBar!=iTime(Symbol(),Period(),1)) line, where do the condition and timeBar come from?