fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Stop Loss and close all order

    Questions & Answers
    3
    5
    1280
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      lindacho last edited by lindacho

      Hi, I have a question.

      IF.

      It has some orders (ex. 5 SELL and 1 BUY orders).

      only BUY order has Stop Loss(pips) and Take profit(pips).

      If BUY go to Stop Loss, I want to close ALL SELL order simultaneously.

      How to set?

      1 Reply Last reply Reply Quote 0
      • roar
        roar last edited by roar

        https://fxdreema.com/shared/8Ts9mzJ0e

        This example doesn't care if the trades are buy or sell, but
        it checks if there is any stop-loss, and
        when there suddenly isn't any stop-loss anymore (because that position closed)
        -> it closes all remaining trades

        You need couple variables with that setup, StopExisted which is used to "remember" that there was a stop-loss, and StopsNow

        Need small help? Tag me in your post
        Need big help? https://www.fiverr.com/big_algo/automate-your-winning-strategy-in-mql4-or-mql5

        1 Reply Last reply Reply Quote 0
        • L
          lindacho last edited by

          Thanks, But it doesn't work..
          is there other ways?

          1 Reply Last reply Reply Quote 0
          • roar
            roar last edited by

            I tested it with live account, works fine for me 😕

            There's surely other ways to do this, but thats the best I came up with

            Need small help? Tag me in your post
            Need big help? https://www.fiverr.com/big_algo/automate-your-winning-strategy-in-mql4-or-mql5

            1 Reply Last reply Reply Quote 0
            • J
              Jeson C. last edited by Jeson C.

              ********** I am replying to keep it in the archive.
              and this code closes the processes that are open at the same time **********

              //+------------------------------------------------------------------+
              //| CloseAll.mq5 |
              //| Copyright 2021, Omega Joctan |
              //| https://www.mql5.com/en/users/omegajoctan |
              //+------------------------------------------------------------------+
              #property copyright "Copyright 2021, Omega Joctan"
              #property link "https://www.mql5.com/en/users/omegajoctan"
              #property version "1.00"
              //---
              #include <Trade\Trade.mqh> //Instatiate Trades Execution Library
              #include <Trade\OrderInfo.mqh> //Instatiate Library for Orders Information
              #include <Trade\PositionInfo.mqh> //Instatiate Library for Positions Information
              //---
              CTrade m_trade; // Trades Info and Executions library
              COrderInfo m_order; //Library for Orders information
              CPositionInfo m_position; // Library for all position features and information
              //---
              input color OrdersColor = clrDodgerBlue; // Orders counter color on the chart
              input color PositionsColor = clrGreenYellow; //Positions counter color on the chart
              //+------------------------------------------------------------------+
              //| Script program start function |
              //+------------------------------------------------------------------+
              void OnStart()
              {
              //---

              ChartWrite("Positions", "Positions " + (string)PositionsTotal(), 100, 80, 20, clrGreen); // write number of positions on the chart
              ChartWrite("Orders", "Orders " + (string)OrdersTotal(), 100, 50, 20, clrDodgerBlue); //Write Number of Orders on the Chart

               {
                for(int i = PositionsTotal() - 1; i >= 0; i--) // loop all Open Positions
                   if(m_position.SelectByIndex(i))  // select a position
                     {
                      m_trade.PositionClose(m_position.Ticket()); // then close it --period
                      Sleep(100); // Relax for 100 ms
                      ChartWrite("Positions", "Positions " + (string)PositionsTotal(), 100, 80, 20, PositionsColor); //Re write number of positions on the chart
                     }
                 ObjectDelete(0, "Positions"); //delete a Position Object
               }
              

              //---
              {
              for(int i = OrdersTotal() - 1; i >= 0; i--) // loop all Orders
              if(m_order.SelectByIndex(i)) // select an order
              {
              m_trade.OrderDelete(m_order.Ticket()); // then delete it --period
              Sleep(100); // Relax for 100 ms
              ChartWrite("Orders", "Orders " + (string)OrdersTotal(), 100, 80, 20, OrdersColor); //Re write number of positions on the chart
              }
              ObjectDelete(0, "Orders");
              }
              }
              //+------------------------------------------------------------------+
              //| |
              //+------------------------------------------------------------------+
              void ChartWrite(string name,
              string comment,
              int x_distance,
              int y_distance,
              int FontSize,
              color clr)
              {
              ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
              ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
              ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
              ObjectSetString(0, name, OBJPROP_TEXT, comment);
              ObjectSetInteger(0, name, OBJPROP_FONTSIZE, FontSize);
              ObjectSetString(0, name, OBJPROP_FONT, "Lucida Console");
              ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
              ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x_distance);
              ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y_distance);
              }
              //+------------------------------------------------------------------+
              //| |
              //+------------------------------------------------------------------+

              Mechanical Engineer and Software Master
              Mr. Jeson C.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post

              Online Users

              R
              P

              8
              Online

              146.7k
              Users

              22.4k
              Topics

              122.6k
              Posts

              Powered by NodeBB Forums | Contributors