[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 147

 

Professionals don't pass by, need your help. Bot is opening sell position, then this position should be closed below, see code and where sell position should be closed, buy position should be opened, number of open positions should be 1 (OrdersTotal()). The question is, how to make something like an order execution queue: first a sell position should close and then a buy position should open and the number of open positions should equal 1?

OrderSend(Symbol(),OP_BUY,Lots,Ask,4,0,0,"",0,0,Green);
    for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_SELL)   // long position is opened
           {
                 OrderClose(OrderTicket(),OrderLots(),Ask,4,Violet); // close position
                }
    }
 
bool flags
 
eddy:
I mean that it is only set to a buffer and not to an external variable

so use this indicator_colorN

 
eddy:
I mean that it is set only to a buffer, not to an external variable
You can't do it with MQL. But if you need it, of course, you can do it))))
 
alsu:
You can't do it in MQL. But if it is VERY, VERY necessary, of course it can be done)))

you don't even know what you need...

I'm sure that eddy's needs can be solved by MQL

 
sergeev:

You don't even know what you need...

I'm sure that eddy's needs are solved by MQLs

No, I got it... he needs to get the rendering colour from indicator buffer in the indicator code (right, eddy?). As far as I know, it's impossible in MQL.
 
alsu:
No, I got it... he needs to get the drawing colour from the indicator buffer programmatically in the indicator code (right, eddy?). As far as I know, this is not possible in MQL.
it is possible.
simply use the parameter indicator_colorN. You can say it's the same variable.
 
sergeev:
maybe.
just use parameter indicator_colorN. This can be said to be the same variable.

noooooo.

Suppose we have an indicator that draws a line. Suppose we want to draw a circle with this indicator. But we want to make it green if the indicator line is green, and red if it is red.

 

Gentlemen programmers, please advise how to close all orders correctly. Below is the problem to be solved and what has been advised to do. All in all, everything works, except for closing orders and setting flags to prohibit trading.

I am sure there are experienced programmers among you. Please help me to write the following conditions in my Expert Advisor:
1) С+=Profit on order(1)+Profit on order(2)+...+Profit on order(n) - total profit on all open orders in current time.
2) C-=(c+)loss on order(1)+loss on order(2)+...+loss on order(n) - sum of losses on all open orders at the current moment in time.
3) X=(c+)/(c-) - the current profit/loss ratio
4) If the equity (S) multiplied by the profit/loss ratio (X) is higher than the specified set value (K), you're good to trade. (If S*X>K, OK)
5) If the Equity (S) multiplied by the Profit/Loss (X) ratio is less than the defined Target (K), then all open orders at the current quotes will be closed and the Expert Advisor will be disabled until it is enabled manually again. (S*X<K, close all orders and off)

It seems to me this would be a good protection against losing money.

It looks like this. Let's create two functions that count profit and loss:
double CalculateProfitTotal()
{
double Result = 0;
for(int i = 0; i < OrdersTotal(); i++)
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if(OrderProfit() > 0)
Result = Result + OrderProfit();
return(Result);
}

double CalculateLossTotal()
{
double Result = 0;
for(int i = 0; i < OrdersTotal(); i++)
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if(OrderProfit() < 0)
Result = Result + MathAbs(OrderProfit());
return(Result);
}

In the start() function, write your conditions.
For example:
X = CalculateProfitTotal() / CalculateLossTotal();
if(AccountEquity() * X < K)
{
//Where we close all orders and
//set flag prohibiting trade
return(0);
}

 
alsu:

Suppose we want to draw a circle as indicator. But we want to make it green if the indicator line is green

so I want to create an object in blue)

sergeev, soindicator_color1 is a colour variable?