fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Monaco
    3. Topics
    • Profile
    • Following 4
    • Followers 3
    • Topics 8
    • Posts 58
    • Best 2
    • Controversial 5
    • Groups 0

    Topics created by Monaco

    • Monaco

      馃殌 Maximize Your EAs with fxDreema: Open Q&A Session 馃殌
      Questions & Answers • • Monaco

      39
      -1
      Votes
      39
      Posts
      3381
      Views

      l'andorr脿

      @legitimate They don't need to manipulate EAs. They manipulate price. That is far more effective regardless what the EA is doing and where it is.

    • Monaco

      Expert programmer gives solutions to any problem just ask me
      Questions & Answers • • Monaco

      49
      0
      Votes
      49
      Posts
      7238
      Views

      Monaco

      @Kevin0214

      Variables and Preparation
      Define the variables needed to identify the oldest trade or the one furthest from the current price:

      // Variables for tracking the furthest or oldest losing trade double max_distance = 0; // Max distance from current price, initialized to zero double lot_to_close = 0.1; // Lot size to close partially int selected_ticket = -1; // Ticket ID of the selected trade for partial close // Loop through all open trades to find the oldest or furthest losing trade for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { // Only consider trades on the current symbol and open positions if (OrderSymbol() == Symbol() && (OrderType() == OP_BUY || OrderType() == OP_SELL)) { double current_price = (OrderType() == OP_BUY) ? Bid : Ask; // Determine current price based on trade type double order_price = OrderOpenPrice(); double distance = MathAbs(current_price - order_price); // Calculate distance from current price // Check if the trade is in loss if (OrderProfit() < 0) { // Select the oldest or furthest trade in loss if (distance > max_distance || selected_ticket == -1) { max_distance = distance; selected_ticket = OrderTicket(); } } } } } // If a trade was found, proceed to partially close it if (selected_ticket != -1) { // Select the trade by ticket ID if (OrderSelect(selected_ticket, SELECT_BY_TICKET, MODE_TRADES)) { double remaining_lots = OrderLots() - lot_to_close; // Calculate remaining lots after partial close // Check if the remaining lot size is above the minimum allowed if (remaining_lots >= MarketInfo(Symbol(), MODE_MINLOT)) { bool close_result = OrderClose(selected_ticket, lot_to_close, OrderClosePrice(), Slippage, clrRed); if (close_result) { Print("Partial close successful for trade with ticket: ", selected_ticket); } else { Print("Error attempting partial close. Error code: ", GetLastError()); } } else { Print("Cannot partially close; remaining size would be below minimum lot size."); } } } else { Print("No eligible trade found for partial close."); }

      Function for Partial Close on Oldest/Furthest Losing Trade
      To make this process reusable, here鈥檚 a function that you can call whenever you want to perform this action.

      void PartialCloseOldestFurthestLoss(double lot_to_close, int slippage) { double max_distance = 0; // Max distance from current price int selected_ticket = -1; // Ticket ID of the selected trade for partial close // Loop through all open trades to find the oldest or furthest losing trade for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { // Only consider trades on the current symbol and open positions if (OrderSymbol() == Symbol() && (OrderType() == OP_BUY || OrderType() == OP_SELL)) { double current_price = (OrderType() == OP_BUY) ? Bid : Ask; // Determine current price based on trade type double order_price = OrderOpenPrice(); double distance = MathAbs(current_price - order_price); // Calculate distance from current price // Check if the trade is in loss if (OrderProfit() < 0) { // Select the oldest or furthest trade in loss if (distance > max_distance || selected_ticket == -1) { max_distance = distance; selected_ticket = OrderTicket(); } } } } } // If a trade was found, proceed to partially close it if (selected_ticket != -1) { // Select the trade by ticket ID if (OrderSelect(selected_ticket, SELECT_BY_TICKET, MODE_TRADES)) { double remaining_lots = OrderLots() - lot_to_close; // Calculate remaining lots after partial close // Check if the remaining lot size is above the minimum allowed if (remaining_lots >= MarketInfo(Symbol(), MODE_MINLOT)) { bool close_result = OrderClose(selected_ticket, lot_to_close, OrderClosePrice(), slippage, clrRed); if (close_result) { Print("Partial close successful for trade with ticket: ", selected_ticket); } else { Print("Error attempting partial close. Error code: ", GetLastError()); } } else { Print("Cannot partially close; remaining size would be below minimum lot size."); } } } else { Print("No eligible trade found for partial close."); } }

      Explanation of the Function
      Function Parameters:

      lot_to_close: The lot size you want to close from the selected trade.
      slippage: The allowable slippage for the close operation.
      Selecting the Trade:

      Loops through all open trades and finds the trade with the maximum distance from the current price that is also in loss.
      Updates selected_ticket with the ticket ID of this trade.
      Partial Close Execution:

      If a trade is found, the function attempts a partial close by calling OrderClose.
      Checks if the remaining lot size will be above the minimum allowed to ensure the trade remains valid.
      Usage Example
      To use this function, you can simply call it with the desired lot size to close and slippage:
      PartialCloseOldestFurthestLoss(0.1, 3); // Partially closes 0.1 lots with 3 pips of allowable slippage

    • Monaco

      I'm looking for programmers for work and earn money
      Questions & Answers • workgroup • • Monaco

      1
      0
      Votes
      1
      Posts
      769
      Views

      No one has replied

    • Monaco

      Declarar Funciones
      Questions & Answers • • Monaco

      3
      0
      Votes
      3
      Posts
      591
      Views

      Monaco

      Gracias por responder, y tienes raz贸n, deber铆a de haberlo puesto en ingles jeje.

    • Monaco

      Where to get my alert?
      Questions & Answers • • Monaco

      2
      0
      Votes
      2
      Posts
      587
      Views

      l'andorr脿

      Pues me temo que la cosa est谩 muy complicada si no tienes el indicador. Lo que pides es que una fuente de informaci贸n externa a tu EA (o sea, a tu MT4) actue sobre tu EA. Eso es para programaci贸n pura y dura de mql4. Hasta donde yo s茅, eso no es posible s贸lo usando bloques de fxdreema. Recuerdo que alguien pidi贸 algo as铆 hace mucho y no pudo solucionarlo por ese tema. Un programador te podr铆a preparar un c贸gigo que te permetiese atrapar la alerta en una variable. Entonces s铆 que podr铆as meterla en un blque de condici贸n de fxdreema. Si no es as铆, me temo que no es posible, lo siento.

    • 1 / 1