Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

First independent community of traders

First independent community of traders Logo First independent community of traders Logo

First independent community of traders Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Buy Theme
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Questions/Q 5739
Next
In Process
vitaliy9999999
vitaliy9999999

vitaliy9999999

  • 4 Questions
  • 4 Answers
  • 0 Best Answers
  • 20 Points
View Profile
  • 0
vitaliy9999999
Asked: December 29, 20202020-12-29T10:04:06+00:00 2020-12-29T10:04:06+00:00In: Forex Expert Advisors

it is not possible to close the order with the opposite

  • 0

Good day! from the name of the problem, everything is clear. I take the standard code from the help and insert it. when closing, it returns an error. tell me the working code) here is the code from the help:

void OnStart()
  {
/ / - - - declaring the query and result of the
mqltraderequest request;
   MqlTradeResult  result;
   int total=positionstotal(); / / number of open positions
/ / - - - iterate through all open positions
for(int i=total-1; i>=>0; i--)
     {
      //--- parameters of the order
      ulong position_ticket=positiongetticket(i); / / position ticket
      string position_symbol=positiongetstring(POSITION_SYMBOL); / / character
      int digits= (int)symbolinfointeger(position_symbol,SYMBOL_DIGITS); / / number of decimal places
      ulong magic=positiongetinteger(POSITION_MAGIC); / / MagicNumber of the position
      double volume=positiongetdouble(POSITION_VOLUME); / / position volume
      double sl=positiongetdouble(POSITION_SL); / / Stop Loss of position
      double tp=positiongetdouble(POSITION_TP); / / Take Profit positions
      ENUM_POSITION_TYPE type= (ENUM_POSITION_TYPE)positiongetinteger(POSITION_TYPE); / / position type
      //--- display information about the position
      PrintFormat("#%I64u %s  %s  %.2f  %s  sl: %s  tp: %s  [%I64d]",
                  position_ticket,
                  position_symbol,
                  EnumToString(type),
                  volume,
                  DoubleToString(PositionGetDouble(POSITION_PRICE_OPEN),digits),
                  DoubleToString(sl,digits),
                  DoubleToString(tp,digits),
                  magic);
      //--- if the MagicNumber matches
      if(magic==EXPERT_MAGIC)
        {
         for(int j=0; jstring symbol=PositionGetSymbol(j); // the symbol of a new position
            / / - - - if the characters of the new and searched positions match
            if(symbol==position_symbol & & positiongetinteger(POSITION_MAGIC)==EXPERT_MAGIC)
{
//- - - setting the counter position type
               ENUM_POSITION_TYPE type_by=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
               / / - - - output if the source and counter position types are the same
               if(type==type_by)
                  continue;
               / / - - - resetting the query and result values
               ZeroMemory(request);
               ZeroMemory(result);
               / / - - - setting operation parameters
               request.action=TRADE_ACTION_CLOSE_BY; // type of a trade operation
               request.position=position_ticket; // position ticket
               request. position_by=positiongetinteger(POSITION_TICKET); / / counter position ticket
                                                                             //request.symbol     =position_symbol;
               request. magic=EXPERT_MAGIC; // MagicNumber of the position
               / / - - - output of information about closing the counter
               PrintFormat("Close #%I64d %s %s by #%I64d",position_ticket,position_symbol,EnumToString(type),request.position_by);
               / / - - - sending a request
               if(!OrderSend(request, result))
PrintFormat("OrderSend error %d",GetLastError()); // if the request failed, print the error code

               / / - - - information about the operation
               PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
              }
           }
        }
     }
  }

  • 3 3 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    3 Answers

    • Voted
    • Oldest
    • Recent
    1. nektomk

      nektomk

      • 2 Questions
      • 37 Answers
      • 0 Best Answers
      • 90 Points
      View Profile
      nektomk
      2020-12-29T10:04:24+00:00Added an answer on December 29, 2020 at 10:04 am

      Vladimir Karputov:

      Please use the hint when inserting the code: Correctly insert the code on the forum.

      I also recommend using a Code Styler (quick application in the MetaEditor editor: “Ctrl”+”,”).

      of course offtop, but gentlemen, on the programmer’s forum to start a separate instruction for inserting code on the forum..this is some kind of overkill, beyond good and evil.

      For how many years, the site and forum are replenished with features, features and features..Except for one thing-simple insertion, markup, and formatting of MQL code. Or do we have C# in the future and there is no need to waste webmaster resources ?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. barabashkakvn

      barabashkakvn

      • 7 Questions
      • 162 Answers
      • 0 Best Answers
      • 314 Points
      View Profile
      barabashkakvn
      2020-12-29T10:04:18+00:00Added an answer on December 29, 2020 at 10:04 am

      vitaliy9999999:

      Good day! from the name of the problem, everything is clear. I take the standard code from the help and insert it. when closing, it returns an error. tell me the working code) here is the code from the help:

      Please use the hint when inserting the code: Correctly insert the code on the forum.

      I also recommend using a Code Styler (quick application in the MetaEditor editor: “Ctrl”+”,”).

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. starij

      starij

      • 0 Questions
      • 14 Answers
      • 0 Best Answers
      • 48 Points
      View Profile
      starij
      2020-12-29T10:04:12+00:00Added an answer on December 29, 2020 at 10:04 am

      vitaliy9999999:

      Good day! from the name of the problem, everything is clear. I take the standard code from the help and insert it. when closing, it returns an error. tell me the working code)

      open two counter orders. Take the code from the help and put it in the script. Throw out all the secondary things. Add the output of intermediate values with the Alert function …

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Sidebar

    Ask A Question

    Stats

    • Questions 504
    • Answers 2k
    • Posts 5
    • Comments 0
    • Best Answers 0
    • Users 681
    • Popular
    • Comments
    • Tags
    • forexcommunity

      Highlighting what’s important about questions & Answers on Discy Community!

      • 0 Comments
    • forexcommunity

      Introducing Keyboard Shortcuts, our first Labs feature

      • 0 Comments
    • forexcommunity

      Defining quality on Discy Engine — what a helpful answer ...

      • 0 Comments
    • forexcommunity

      Organizational and company accounts on Discy Engine the next step

      • 0 Comments
    • forexcommunity

      Hello world!

      • 0 Comments

    Related Questions

    • Brus Agell

      Правельный выбор

      • 0 Answers
    • pinupcasinoo

      Pin Up Casino

      • 0 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 2 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 0 Answers
    • c00l777

      Optimization results differ on different accounts

      • 3 Answers

    Users

    Leonardcig

    Leonardcig

    • 0 Questions
    • 0 Answers
    DennisByday

    DennisByday

    • 0 Questions
    • 0 Answers
    Haroldmeary

    Haroldmeary

    • 0 Questions
    • 0 Answers

    Footer

    First independent community of traders

    About

    An independent community of forex traders. This is where traders communicate. You can ask your questions and you will receive an answer to your question.
    • Terms of Use
    • Privacy Policy
    • Cookie Policy
    • Knowledge Base
    • Support

    © 2021 Forexcommunity.net. All Rights Reserved