Expert programmer gives solutions to any problem just ask me
-
@Kevin0214 I already replied to your question in the other thread. Please don't duplicate threads.
-
Hello,
how to create this rule in fxdreema blocks:
A long position is closed when it has moved ATR3 down from its highest closing price since the position was opened.
I mean highest closed price since the position was open. Every closed bar should be controlled if is highest from open price and if yes then trailling -ATR3 should be checked. Number of bars from open bar is not defined, continuous process.
Thanks -
@rforeign Could you please open a new thread for your question instead of using this one?
-
........
-
@Monaco I created a Bot with fxdreema that sells and buys based on the condition I gave it. So, I want to create another bot to manage the trades based on the following conditions:
The bot should check the last closed trade, if it was a loss, then enter the opposite direction immediately using same stoploss pips and take profit pips and
double the lotsize.Can you help me please? Thanks.
-
@Monaco hi i have this error
how can i find that the error belongs to which block?
Compilation errors
'CurrentSymbol' - function not defined
'CurrentSymbol' - constant expected -
@biztet
Sorry for the delay, I didn't quite understand when you wanted it to activate. -
@EA-NEL Hola lo que entiendo es que primero debes controlar el uso de como tienes la condicion, un cruce de MA es sencillo pero a la misma ves "complejo"

Asi estrictamente estarias definiendo un cruce bajista
existe este (x>) pero nunca lo he usado. Es por esa razon que recibes notifiaciones siempre, por que quizas no esta bien condicionado -
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’s 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