[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 548

 
harvest:
Gentlemen, could you give me an example of the function which moves an open position to breakeven (work on tick), my Expert Advisor has a trawl, the start of this trawl is only after the function of rollover to buy. Thank you in advance.


See the trailer - the library of trawls by Yury Dzyuban - in particular, how it solves the question if only trawls from profit are activated, i.e., if the value of the variable trlinloss = false, whether trawls are executed in the loss area. Edit your trawl function according to this example and that's it.

Files:
 

Friends, can you tell me why classic Martin doesn't work? It only opens deals to buy!!! For a month now I've been messing with it - zero emotion! It works fine in the Strategy Tester, but not on demo. Another interesting thing - when I set T/S and T/P 1000 - it opens only on Buy, and when I set 200 - on Buy and Sell... Man, what's the difference?

here's the code: help plz

//+------------------------------------------------------------------+ 
//| StMartin.mq4 | 
//| Sergey Kodolov | 
//| 84232676421@mail.ru | 
//+------------------------------------------------------------------+ 
#property copyright "Sergey Kodolov" 
#property link "84232676421@mail.ru" 

    extern int TP = 1000; 
    extern int TS = 1000; 
    extern double lots = 0.1; 

    double volumz; 
    int total,ticket; 
    int slip = 3; 
    int Magic = 7; 

 


//+------------------------------------------------------------------+ 
//| expert initialization function | 
//+------------------------------------------------------------------+ 
int init() 
  { 
//---- 

   ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slip,Bid-TS*Point,Bid+TP*Point,"First order",Magic,0,Yellow); //открываем первый ордер 
 
//---- 
   return(0); 
  } 
//+------------------------------------------------------------------+ 
//| expert deinitialization function | 
//+------------------------------------------------------------------+ 
int deinit() 
  { 
//---- 

//---- 
   return(0); 
  } 
//+------------------------------------------------------------------+ 
//| expert start function | 
//+------------------------------------------------------------------+ 
int start() 
  { 
//---- 



OrderOpenFunction(); 

//---- 
   return(0); 
  } 
//+------------------------------------------------------------------+ 

void OrderOpenFunction()
{
   total = OrdersTotal();
   if(total < 1) 
   { 
      OrderSelect(0,SELECT_BY_POS,MODE_HISTORY); 
      volumz = OrderLots(); 
      if(OrderProfit()<0) 
      { 
         if(OrderType() == OP_BUY) 
         { 
            double lot1 = volumz*2; 
            ticket = OrderSend(Symbol(),OP_SELL,lot1,Bid,slip,Ask+TS*Point,Ask-TP*Point,0,Magic,0,Red); 
         } 
         if(OrderType() == OP_SELL) 
         { 
            double lot2 = volumz*2; 
            ticket = OrderSend(Symbol(),OP_BUY,lot2,Ask,slip,Bid-TS*Point,Bid+TP*Point,0,Magic,0,Green); 
         } 
      } 
      if(OrderProfit()>0) 
      { 
         if(OrderType() == OP_BUY) 
         { 
            ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slip,Bid-TS*Point,Bid+TP*Point,0,Magic,0,Green); 
         } 
         if(OrderType() == OP_SELL) 
         { 
            ticket = OrderSend(Symbol(),OP_SELL,lots,Bid,slip,Ask+TS*Point,Ask-TP*Point,0,Magic,0,Red); 
         } 
      } 
   } 
}      
  
 
Alp:

Then it becomes even more unclear. Suppose I buy a euro for 1 000 000 (1k) dollars (broker multiplies this by 100 as a result the deal goes for 100k) chart jumps 100 points up and I sell them and I am on the plus side for 10 000 dollars well there broker's commission and spread as a result 6000 $ net in my pocket. (Well it is clear that after the sale, it will fall again by 100 points.) This is nonsense!!!! Maybe it will fall to the bottom after all? Otherwise very big players would make billions without doing anything.


Then I don't know...

In general, the thing is probably that for a noticeable price movement it is necessary to buy or sell for a very large amount, VERY large. For such sums the leverage is not 1/200, as I have, but 1/2 figuratively. Well, this is purely my personal. I can write such nonsense...

 
There is one thing that surprises me. I posted the code here earlier, there was a mistake, it helped me fix it, Sepulca helped, thanks to her, til now the code all works... But I still do not understand the puzzle: in the first loop the order selector selected an order, there was no error, and then, when I selected the same order in another line, below, the order selector showed error? If you can, take a look at it, I'm just curious.
for(  i=0;i<=OrdersHistoryTotal();i++){
    OrderSelect(i ,SELECT_BY_POS,MODE_HISTORY);
     if (OrderMagicNumber( )== magic) { if(OrderSymbol()== Symbol()) {





 current = OrderOpenTime();  Alert ( " current = OrderOpenTime(); ",  current);Alert ( " max ", max );
      
      if (current > max) 
      {                    
         max = current;      
         ticket = OrderTicket();   Alert ( " ticket = OrderTicket();  ", ticket );
      }}}}


       if (ticket>-1){
      OrderSelect( ticket,SELECT_BY_TICKET,MODE_HISTORY);Alert ("SELL Select error HISTORYticket ", GetLastError( )  ) ;
Dimka-novitsek:

No way! Why not? There were no open orders at the time of the overshoot! Maybe I don't understand.

The search cycle is also on history! That's where I assign it to the int ticket variable!

And it swears, excuse me, 2012.02.04 11:28:47 2011.12.06 16:35 GMT EURUSD,M30: Alert: SELL Select error HISTORYticket 4105

When it gets from MODE_HISTORY to MODE_TRADES?

And most importantly, I select the same order on the history with the help of order select, and it is selected first, otherwise I wouldn't be able to work with it! There's no logic!!!!!!I'm shocked.


 
Can you tell me where I can find such an EA or script... There is a group of orders (9-11) placed on either side of the price at a distance of 5-7 pips from it. the time to trigger them is strictly limited. therefore, very often the orders do not get caught and they are removed. orders are placed in early morning, as a rule, the market is heavily flat. i want the second group of orders to follow the price as it approaches one of the order groups. simply put, a pending order trail with tp and sld. is this possible? thanks a lot in advance.
 

Need Help!

I have the following block in my EA (Event Counter):

if (isCloseLastPosByStop()==True) //If the last order was closed by Stop

{
N=N+1;
Alert(N, " moose");
} else N=0;

QUESTION: how to write the data into a file (excel) instead of displaying it on the screen?

 

Good afternoon.

Please advise why the arrows are not drawn, code:

ObjectCreate("miniDown", OBJ_ARROW, 0, Time[1], Open[1]);
ObjectSet("miniDown", OBJPROP_ARROWCODE, 241);
ObjectSet("miniDown", OBJPROP_COLOR, Yellow);

 

Suppose EURUSD=1.44757, GBPUSD=1.63366, you want them to be close to each other.

Let me explain:

a=GBPUSD/EURUSD=1.12855336874901 approximately 1.12855 ,

i.e. if I want to buy/sell a currency so that the deal is approximately equal in value, then

I need to buy/sell EURUSD*a, but there is no such a lot, so my question is how to implement it, lot calculation?

I don't have such a lot, so my question is how to do it?

 
T-G:
i want to share the function for calculating the maximum allowable lot, taking into account the open positions, in other words, using equity. The standard function calculates the risk, but if i have trades, i don't have enough money to open them

I used to write it for a custom EA:

//+----------------------------------------------------------------------------+
double CorrectLots(double lt, int Part=2) {
   double ltcorr, Money, MoneyCorr;
   double dig      = MarketInfo(Symbol(),MODE_DIGITS);
   double MaxLot   = MarketInfo(Symbol(),MODE_MAXLOT);
   double MinLot   = MarketInfo(Symbol(),MODE_MINLOT);
   double StpLot   = MarketInfo(Symbol(),MODE_LOTSTEP);
   double OneLot   = MarketInfo(Symbol(),MODE_MARGINREQUIRED);
   double TradeMrg = NormalizeDouble(AccountFreeMargin()/Part,dig);    // Свободные средства, разрешенные к торговле
   
   lt=MathAbs(lt);
   ltcorr=lt;                                      // Зададим начальное значением ltcorr равным значению lt
   if (lt>=MaxLot) ltcorr=MaxLot;                  // Проверим превышение допустимых ...
   if (lt<=MinLot) ltcorr=MinLot;                  // ... значений лота
   Money=lt*OneLot;                                // Вычисляем стоимость открываемой позы
   if (Money<TradeMrg) return(ltcorr);             // Если свободных средств больше, чем цена позиции -  возвращаем неизменённый лот
   else if (Money>=TradeMrg) {                     // Если цена позиции равна или больше, чем есть свободных средств, то ...
      ltcorr=MathAbs(MathFloor(TradeMrg/OneLot/StpLot)*StpLot);         // ... рассчитаем допустимый лот
      MoneyCorr=ltcorr*OneLot;                      
      Print("Func CorrectLots: лот ",lt," скорректирован до ",DoubleToStr(ltcorr,2),
            " Стоимость до корректировки = ",DoubleToStr(Money,dig),
            " Стоимость после корректировки = ",DoubleToStr(MoneyCorr,dig)
            ); 
      return(ltcorr);                                                   // ... и вернём его значение
      }
   Print("Func CorrectLots: лот вернули без изменений");
   return(ltcorr);                                 // Возврат изначального лота в непредусмотренных случаях с сообщением
}
//+----------------------------------------------------------------------------+

In order to correct the lot, you need to call the function by inserting as parameter lt the lot you want to open a position, and instead of parameter Part - the number by which the free funds used in the trade will be divided. I.e. to trade only half of the free funds, Part should have a value of 2, if a third, then 3, a quarter - 4, etc.

double Lot=CorrectLots(0.1, 2);

After calling the function, insert Lot as a parameter of the OrderSend() function;

The function limits lots in an EA with a hard Martin and prevents losing lots. But profitability was falling too...

 
reply to my previous one, I don't understand what's wrong there =(
Reason: