Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 352

 
evillive:

A library is an option.

Thank you for the idea.
 
Trader7777:

there can only be one order in the market. At the moment this function doesn't work at all... for some reason. But if it will work properly, I understand that it will be triggered all the time, as long as the profit is greater than the set number of pips. Of course, we need it to close half of a position once, and that's it. But I wish it would work at least once.)


I agree with you in my heart that there should be only one order. And then, we partially close, when? In how many seconds or on other terms? Otherwise at some point everything will close and only the drool will be left to spit)))))

Your function should work, at least in the tester. Another question is when to call it....

 
Sepulca:


Deep down I agree with you that there should only be one order. And then, partly close, when? After how many seconds or by some other conditions? Otherwise at some point everything will close and all that will be left is drooling)))))

Your function should work, at least in the tester. Another question is when to call it....


extern int TP         = 200; // кол-во пунктов, после которых должно произойти частичное закрытие
extern int Magic      = 77;


void CloseHalfOrder(){ // функция вызывается в самом начале цикла Start

for (int i = 0; i<=OrdersTotal(); i++)
  {
    if (OrderSelect (i,SELECT_BY_POS,MODE_TRADES) == true)
      {
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
          {
            if (OrderProfit() >= TP*Point)
              {
                 if (OrderType() == OP_BUY) 
                 double Lots = OrderLots(); 
                 double HalfLot  = NormalizeDouble (Lots*0.5,2);
                 OrderClose(OrderTicket(),HalfLot,Bid,0,HotPink);
          
                 if (OrderType() == OP_SELL)
                 double Lots1 = OrderLots(); 
                 double HalfLot1  = NormalizeDouble (Lots*0.5,2);
                 OrderClose(OrderTicket(),HalfLot1,Ask,0,HotPink);
               }
          }
        }
      }
    }
it's not working. why?
 
Trader7777:




if (OrderProfit() >= TP*Point)

What is this?

if(Bid-OrderOpenPrice()>= TP*Point)//для покупок

if(OrderOpenPrice()-Bid>= TP*Point)//для продаж
Something like this.
 
Trader7777:


it doesn't work. Why not?

That's why:

if (OrderProfit() >= TP*Point)
Do you want points? You're looking at the money.
 
r772ra:

What is this?

Something like this

Ask for sales
 
artmedia70:
Ask for sales


That's right, the spread is taken into account.
 
artmedia70:

That's it:

Do you need points? And you're looking at the money.


r772ra:

What is this?

Something like this

thank you!!! programming for exactly the second week) inattentive beginner
 
Please advise me on this. Alpari is increasing the spread at the weekend to the extent that the EA is always losing. OK. I can set the spread manually in the Strategy Tester. But in what units? 100, 50, 30, 10 - what is it? Percentage, points, what? I thank you in advance.
 
Pyro:
Please advise me on this. Alpari is increasing the spread at the weekend to the extent that the EA is always losing. OK. I can set the spread manually in the Strategy Tester. But in what units? 100, 50, 30, 10 - what is it? Percentage, points, what? I thank you in advance.

In the tester, the spread is in points. Dealers usually have a floating spread. And on Friday at 23:00 it usually rises to unbelievable values. It is better not to trade during this time.
Reason: