Help with code please.

MaXimuS20
46
MaXimuS20  

Hi,

Please help me with this. I need to open a trade automatically with double lot size IF the previous trade close in loss.

Thanks in advance !!

Eugen Funk
188
Eugen Funk  

- Search all your previous positions

Print("Found "+IntegerToString(PositionsTotal())+" total positions");
   if(PositionsTotal() > 0)
   {
      //INITIALIZE TICKET VARIABLES
      int ticket_number, ticket_order_type, ticket_currency_digits, ticket_currency_multiplier;
      string ticket_order_type_name;
      double position_profit=0.0;
      
      //LOOK THROUGH ALL OPEN ORDERS
      for(int pos_counter = 0; pos_counter < PositionsTotal(); pos_counter ++)
      {
         //CURRENT OPEN ORDER MATCHES CURRENT SYMBOL
         if(PositionGetTicket(pos_counter) >0)
         {
            ticket_number = PositionGetTicket(pos_counter);
            PositionSelectByTicket(ticket_number);
            string symbol=PositionGetSymbol(pos_counter);
            double vol=PositionGetDouble(POSITION_VOLUME);
            position_profit=PositionGetDouble(POSITION_PROFIT);
            double open_price=PositionGetDouble(POSITION_PRICE_OPEN);
            double sl=PositionGetDouble(POSITION_SL);
            double tp=PositionGetDouble(POSITION_TP);
            double curr_price=PositionGetDouble(POSITION_PRICE_CURRENT);


            if (ticket_number==0)
            {
              res+="error";
              continue;
            }
....... and so on.........

- open a new position https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradebuy

William Roeder
24300
William Roeder  
MaXimuS20: need to open a trade automatically with double lot size IF the previous trade close in loss.
Same as Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
          Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum 2015.02.11

Why it won't work: Calculate Loss from Lot Pips - MQL5 programming forum 2017.07.11