[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 699

 
artmedia70:

Here you have

void OpenBuy() {

double dStopLoss = 0, dTakeProfit = 0;
double Lots_New = Lot;

if (isLossLastPos(NULL, -1, MAGIC))
Lots_New *= 2;
else if (!isLossLastPos(NULL, -1, MAGIC))

Lots_New = Lot;

It is a function, and at the very beginning of this function you assign to the Lots_New variable the value = Lot;

Think about how it will change afterwards if you always bring it back to its original state?

Where did I tell you to write it? In the external variables before the start function...

And normalize the lot value to the correct size:

Lots_New = NormalizeLot(Lot*2, False, "");




Thank you so much!

Can you also tell us if you can add a lot value to each subsequent losing order? You can use something like this

1 lot 0.01

2 lot 0.01

3 lot 0.02

4 lot 0.03

5 lot 0.07

.....

15 lot 1.2

To be able to change lot value in code.

And that in case a deal turned out to be profitable, everything would return to the beginning.

I will thank you in advance.

Thank you.

 
Necron:
Roger, thanks, but it still doesn't work correctly. I tried to add another trailing stop, but the error is still there :( Is there any difference between trailing stop for one position and trailing stop for several positions at once?

It makes no difference in principle.
Try my function, it's simple enough, pass as parameters, medjic, and desired trawl.
The call of this function is performed at start, in any place, as long as it "squirts" there at every tick.

//+------------------------------------------------------------------+
void trailing(int magic, int trailing){
   int index = 0;
   while(trailing > 0 && OrdersTotal() != 0 && OrderSelect(index, SELECT_BY_POS)){
      if(OrderMagicNumber() == magic){
         if(OrderType() == OP_BUY){
            if(Bid - OrderStopLoss() > Point*trailing){
               if(trailing >= MarketInfo(Symbol(), MODE_STOPLEVEL) && trailing > MarketInfo(Symbol(), MODE_FREEZELEVEL))
                  if(!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - (Point*trailing), OrderTakeProfit(), 0))Print(">>> ERROR ", GetLastError());
            }
            return;
         }
         if(OrderType() == OP_SELL){
            if(OrderStopLoss() - Ask > Point*trailing || OrderStopLoss() == 0){
               if(trailing >= MarketInfo(Symbol(), MODE_STOPLEVEL) && trailing > MarketInfo(Symbol(), MODE_FREEZELEVEL))
                  if(!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + (Point*trailing), OrderTakeProfit(), 0))Print(">>> ERROR ", GetLastError());
            }
            return;
         }
      }
      index++;
   }
}
//+------------------------------------------------------------------+

Obviously, orders should have different sliders.

 
Please tell me why it doesn't work:

OrderSelect(1,SELECT_BY_POS,MODE_TRADES);

error code 4051. There is one open OP_BUY order.
Files:
ma_1.mq4  3 kb
 
itum:

Help me solve a problem !


I search for orders which are open or pending. If they are available then I determine which order is buy or sell. Under certain conditions (if one is bigger than the other or smaller than the third), I want to close this order. Change its parameters and open it again.

The problem is that there is always a signal to close the order and to open it. That is why my order closes, then opens again, and so on, opens and closes ... )))

How to solve this problem ? Ga
I think it's deja vu... Am I the only one? You've already had several replies... Huh?
Put your code with opening and opening conditions here. We'll put our finger on it... :)
 
an11:
Please tell me why it doesn't work:

OrderSelect(1,SELECT_BY_POS,MODE_TRADES);

error code 4051. There is one open OP_BUY order.

The number count in the OrderSelect() function starts from zero. And you have 1, which means that you are looking for the second order, although you only have one in the market, which is why it doesn't work.

 
Vinin:
You can do this with parameters, but not with patterns. You have to define the criteria first. Similar, not similar. And if it is similar, then to what extent. At least by how much (percents). In one case the time component, in the other - the price one. How to correlate them with each other. Although I can attach a neuronics layer. The Kohonen layer does that very well.

I've got 12 variants of one pattern in one of my indicators, the pattern is the same but the values are always different and their ratio is different )), ....) I've never worked with neural networks, I think my experience in writing elementary algorithms using mql will not be enough, though it may help me fix it. I coped with this task earlier "barbarously" replacing Kohonen, by writing all parameters in Exxel at the moment of pattern occurrence and the result if the deal opened, then using Exxel analysis I had to search for more matches in correlation with profitability. Either way I got something and the system defined pattern wisely, but still it was not very smart.)
 
cyclik33: ...

I don't know what function you're using, but the general idea is this: since your pitch is not even, I suggest using an array, you write the volumes you need into it, and then use the function to go through its value.

Example on my code:

//+------------------------------------------------------------------+
double getMartinLot(double lot, double arrayLot[]){//ФУНКЦИЯ УПРАВЛЕНИЯ ОБъЕМОМ ТОРГОВ ПО СИСТЕМЕ МАРТИНГЕЙЛА
   static double balance_before, balance_after;    //ДЛЯ ХРАНЕНИЯ СОСТОЯНИЯ БАЛАНСА ДО И ПОСЛЕ СДЕЛОК
   static double save_Lot;   
   static int loop;
   if(loop == ArraySize(arrayLot))loop = 0;   
   balance_after = AccountBalance();               //СОХРАНЕНИЕ ТЕКУЩЕГО СОСТОЯНИЯ БАЛАНСА   
   if(balance_after >= balance_before){            //ПРОВЕРКА ИЗМЕНЕНИЯ БАЛАНСА
      save_Lot = lot;                              //ЕСЛИ ОН НЕ ИЗМЕНИЛСЯ ИЛИ СТАЛ БОЛЬШЕ, ТО СБРАСЫВАЕМ ЛОТ
      loop = 0;
   }else{
      save_Lot = arrayLot[loop];                   //ЕСЛИ СТАЛ МЕНЬШЕ ТО УВЕЛИЧИВАЕМ ЛОТ
      loop++;
   }
   balance_before = balance_after;                 //СОХРАНЯЕМ СОСТОЯНИЕ БАЛАНСА ПОСЛЕ РАБОТЫ
   return(save_Lot);
}
//+------------------------------------------------------------------+
Example function call:
//+------------------------------------------------------------------+
int start()
  {
   double volume[] = {0.1, 0.1, 0.2, 0.3, 0.7};   //создаем массив с объемами

   if(OrdersTotal() == 0){
      OrderSend(Symbol(), OP_BUY, getMartinLot(0.1, volume), Ask, 10, Bid - 25*Point, Bid + 25*Point, "", 777);
   }
}
//+------------------------------------------------------------------+
 
artmedia70:
I think it's De ja vu... Am I the only one? You've already had several people answer you... Huh?
Put your code with the condition for opening and opening the pose. We'll put our finger on it... :)
Me too :))) Valentin, for some reason does not want to show the code, probably does not want to show his ideas...
 
ToLik_SRGV:

I don't know what function you're using, but here's a general idea: since your pitch is not flat, I suggest using an array, you write the volumes you need into it, and then use the function to go through the values.

Example on my code:

Example function call:

Thank you very much!!!!!

I use your code too (and it works fine by the way), but I wanted to install Artemis code in another EA, first, because I had more problems with it, and there was a question of principle, why it didn't work properly.

Thank you so much again !!!! I will be trying it now!

 

The question may be trivial, the Expert Advisor is trading on M1, the signal to open an order came in, let's assume the stop is short and the order closed on the sl. but the condition to open still exists.

What is the best way to ensure that the order is not opened again at the same minute?