- 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
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 !!