[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 573

 
rigonich:

Here is the code, it works as you asked. At any close it opens two opposite positions.



Thank you.

But you have a different EA, it works differently.

I would like my EA to open positions in both directions if some of them are closed,

I don't know how to do it but I've seen it open some positions.

Files:
sellbuy_1.ex4  5 kb
 

I tried to add it, it almost worked, but it opens positions the way I need it to if price moves in one direction.

For example He closed a buy , then opened a new buy and sell , then again closed a buy , then opened again also buy and sell , but if he closed NOT buy and sell it does not open new (((((

Please take a look at it and see if it helps...

what a load of crap i wrote )) . But that's how it works I have these opening conditions...

I need another condition when it will open a position if price changes ...

Files:
 
did I get it right? NumberOfPositions(Symbol(),OP_BUY,Magic); is this how many open buy positions?
 
Frostr:
Did I get it right? NumberOfPositions(Symbol(),OP_BUY,Magic); is it how many open buy positions?


Your Expert Advisor does not define opening conditions. It just opens in the direction you specify (variables BUY and SELL). You can add a condition to check if the last deal was closed with profit or loss in this EA or in yours. But in my opinion, it already copes with its task - it shows most clearly the unprofitability of this strategy. Actually, we don't even need an Expert Advisor for this, it can be calculated in half an hour on the history even without a calculator. If Stop Loss is equal to Take Profit, the loss is equal to spread multiplied by the number of trades, in all other cases - spread plus one half of the difference between Stop Loss and Take Profit.

P.S. In general, although the code of owl is different, it does exactly what your EA will do, if you add to it the condition you want. That is, if price has changed and went in the other direction, it will open two opposite deals at each close. It was just easier for me to remove all "unnecessary" things from the code that are not related to the task at hand.

P.P.S.You got it right aboutNumberOfPositions(Symbol(),OP_BUY,Magic).

 
gheka:
which post office can text about incoming mail and its contents?

e.g. mail.ru
 
rigonich:

Your Expert Advisor has no conditions for opening, it just opens in the direction you set (the BUY and SELL variables). You can add a condition to check if the last deal was closed with profit or loss in this EA or in yours. But in my opinion, it already copes with its task - it shows most clearly the unprofitability of this strategy. Actually, we don't even need an Expert Advisor for this, it can be calculated in half an hour on the history even without a calculator. As soon as you add your condition to any Expert Advisor (opening two opposite trades and closing only by Stop Loss or Take Profit), the amount of loss becomes fixed and depends only on the number of trades.



For some reason I open 500-800 positions at once when testing the EA, I do not understand what the number of open positions depends on and I cannot regulate it(!

The only way to reduce the number of open positions is to increase the Lot. If you set the lot to the maximum, then it will open 1-3 positions at once

If you set the lot to a minimum, it will open 500-1500 positions at a time

 
Frostr:



I do not know why the number of open positions depends on it. I cannot adjust it(!

The only way to reduce the number of open positions is to increase the Lot. If you set the lot to the maximum, then it will open 1-3 positions at once

If you set the lot to a minimum, it will open 500-1500 positions at a time

1. Only a limited number of orders may be opened at a time.

2. If the lot is increased significantly, additional positions cannot be opened due to lack of funds.

 
Frostr:



My Expert Advisor, that you gave me during testing, for some reason I open 500-800 positions at once, I do not understand what determines the number of open positions and I can not adjust(

The only way to reduce the number of open positions is to increase the Lot, if you set the Lot to the full, then it will open 1-3 positions at a time.

If you set the lot to a minimum it will open 500-1500 positions at a time

Files:
 
rigonich:


 

I wrote something like trailing for my EA, but it doesn't work, depending on what I try to change to make it work, it generates error 1 when modifying, or just does not go further than the first print (Print("Leading Buy position"); )... what could be the reason, I would be glad to hear any suggestions, thanks in advance!

bool TrailingStop()
   {
   int MD0=MarketInfo(Symbol(),MODE_STOPLEVEL);
   if ((OrderMagicNumber()==11111)==true)
      {
      Print("Ведём позицию Buy");
      while(OrderCloseTime()==0)
         {
         if ((NormalizeDouble(Bid-OrderStopLoss()+StepStop*Point,Digits)>NormalizeDouble(StopLevel*Point,Digits))&&(NormalizeDouble(MD0,Digits)<NormalizeDouble(StopLevel*Point,Digits)))
               {
               RefreshRates();
               Print("текущий бид-",Bid,", текущий стоп-",OrderStopLoss(),", текуйщий тейк-",OrderTakeProfit(),", цена открытия-",OrderOpenPrice(),", расстояние от текущего стопа до текущего бида-",NormalizeDouble(Bid-OrderStopLoss(),Digits),", новый стоп-",NormalizeDouble(Bid-StopLevel*Point,Digits));
               if (OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-StopLevel*Point,Digits),OrderTakeProfit(),0)==true)
                  Print("Stop Loss ордера с номером ", OrderTicket(),", и магическим числом ",OrderMagicNumber(),", успешно изменён на ",OrderStopLoss());
               else Print("Не удалось переместить уровень Stop Loss ордера с номером ", OrderTicket(),", и магическим числом ",OrderMagicNumber(),". Ошибка ",GetLastError());
               }
         Sleep(1000);
         }
      if (OrderCloseTime()>0)
         {
         Print("Ордер с номером ", OrderTicket(),", и магическим числом ",OrderMagicNumber(),", закрыт по цене ",OrderClosePrice(),", с прибылью/убытком ",OrderProfit());
         return(true);
         }
      }
   else
      {
      if ((OrderMagicNumber()==22222)==true)
         {
         Print("Ведём позицию Sell");
         while(OrderCloseTime()==0)
            {
            if ((NormalizeDouble(OrderStopLoss()+StepStop*Point-Ask,Digits)>NormalizeDouble(StopLevel*Point,Digits))&&(NormalizeDouble(MD0,Digits)<NormalizeDouble(StopLevel*Point,Digits)))
               {
               RefreshRates();
               Print("текущий бид-",Ask,", текущий стоп-",OrderStopLoss(),", текуйщий тейк-",OrderTakeProfit(),", цена открытия-",OrderOpenPrice(),", расстояние от текущего стопа до текущего бида-",NormalizeDouble(OrderStopLoss()-Ask,Digits),", новый стоп-",NormalizeDouble(Ask+StopLevel*Point,Digits));
               if (OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+StopLevel*Point,Digits),OrderTakeProfit(),0)==true)
                  Print("Stop Loss ордера с номером ", OrderTicket(),", и магическим числом ",OrderMagicNumber(),", успешно изменён на ",OrderStopLoss());
               else Print("Не удалось переместить уровень Stop Loss ордера с номером ", OrderTicket(),", и магическим числом ",OrderMagicNumber(),". Ошибка ",GetLastError());
               }
            Sleep(1000);
            }
         if (OrderCloseTime()>0)
            {
            Print("Ордер с номером ", OrderTicket(),", и магическим числом ",OrderMagicNumber(),", закрыт по цене ",OrderClosePrice(),", с прибылью/убытком ",OrderProfit());
            return(true);
            }
         }
      else return(false);
      }
   }
Reason: