Complicated and simple Mql4 codes i wrote myself
Logo

Login

Log in with
X
 
  • filter
  • Time
  • Show
Clear All
new posts
20
  • #1 Collapse

    Complicated and simple Mql4 codes i wrote myself
    "Complicated and simple Mql4 codes I wrote myself"
    After regards, I created this thread to share with you my own programmed simple and especially complicated parts of MQL4 codes, which have unique and priceless ideas and by combining them together you can create more advanced automatic trading robots "EA" to manage your trading strategies in the best possible way.
    Guest's Avatar
    Last edited by ; 05-04-2022, 08:36 AM.
    *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
    *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself
  • <a href="https://www.instaforex.org/ru/?x=ruforum">InstaForex</a>
  • #2 Collapse

    Identifying &quot;previous&quot; closed order &quot;the one closed before last one it's Type Magic Number Result And Combine Them Into String (My own programmed)

    Identifying "previous" closed order "the one closed before last one it's Type,Magic Number and Result and Combine Them Into String (My own programmed)

    The blew mentioned code will allow you to achieve deeper and longer chart reading, the main purpose is reading the chart as a continues three levels leads to seeing the chart as a price a vertical or horizontal channels and/or trends, we will achieve that if we applying the blew code for an active trade and for the last closed one and passing through the one closed before the latest closed order, there are no one talked about "previous" closed order so today i will explaining how to " Identifying "previous" closed order "the one closed before last one by using count from up "latest closed order" to down "your first closed order" but as long as the code tries to only skip last closed order and dealing with the one closed before it so we have to force the code to stop the count after the count equals to 2 that's why you will find a calculation to count all orders then deducted one from it "refers to latest closed one" and if the result match 1 "refers to the previous order before latest closed one" that's mean the calculation was: 2 "already count last closed order and the one closed before it" - 1 "latest order we want to skip" = 1 "the previous order we want to deal with", then only after reach previous during the count the code will order few things related to that previous order it's: magic number, order type the order profits, then using them together we will have 5 cases, but first you have to count all closed orders in this function or outside to know if all counted orders number equals to or bigger than 2 that's means there will be latest closed order and another one before it at least "the one we dealing with" :

    1- All closed orders was 2 or bigger and the previous closed order hold 1 as a magic number for Buy "set in the line of send order in your code", and was profitable and it's type returns 0 "default for OP_BUY", the code will return "Buy Positive" as a string.
    2- All closed orders was 2 or bigger and the previous closed order hold 1 as a magic number for Buy, and was negative and it's type returns 0 "default for OP_BUY", the code will return "Buy Negative" as a string.
    3- All closed orders was 2 or bigger and the previous closed order hold 2 as a magic number for Sell, and was profitable and it's type returns 1 "default for OP_SELL", the code will return "Sell Positive" as a string.
    4- All closed orders was 2 or bigger and the previous closed order hold 2 as a magic number for Sell, and was negative and it's type returns 1 "default for OP_SELL", the code will return "Sell Negative" as a string.
    5- All closed orders was 1 or 0 that's means there are still no previous closed order as long as previous needs to have 2 closed orders at least to consider the second as previous, and the code return "No Previous Closed Order Yet" as a string.

    " The Code"


    string CalExpertPreviousClosedOrderTypeAndStatusInValue() // Expert Previous Closed Order Type And Status In Value // Previous: Identifies The Status Of The Closed Order Which Have Been Closed Before The Latest Closed Order.
    {
    double ExpertTotalClosedOrdersNumber = CalExpertTotalClosedOrdersNumber();
    int CountTotalClosedOrdersPre;
    for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) //:For Analyze Closed Orders From Up "Biggest Ticket" To Down,//(int i=0; i<OrdersHistoryTotal(); i++):For Analyze Closed Orders From Down "Lowest Ticket" To Up "Biggest Ticket".
    if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
    {
    if (OrderSymbol() == Symbol()) // Use Current Chart Symbol While Analyze
    {
    CountTotalClosedOrdersPre++; // Count ALl Closed Orders
    if (((CountTotalClosedOrdersPre - 1) == 1) && (CountTotalClosedOrdersPre != 0)) //The Rule Avoid Zero As a Result Of The Above Count And Only Accept 1 Or Bigger Number So When's Result Match 1 It Stops To Continue What's Below.
    {
    int ExpertPreviousClosedOrderMagicNumber = OrderMagicNumber(); // 1 For Buy ,2 For Sell
    double ExpertPreviousClosedOrderStatusInValue = OrderProfit();
    int ExpertPreviousClosedOrderType = OrderType(); // 0 = OP_BUY ,1 == OP_SELL
    // Based On What Have Been Identified Above To Combine Them Together And Return string Of Four Cases: "Buy Positive", "Buy Negative", "Sell Positive", "Sell Negative".
    if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 1) && (ExpertPreviousClosedOrderStatusInValue > 0) && (ExpertPreviousClosedOrderType == 0))
    string ExpertPreviousClosedOrderTypeAndStatusInValue = "Buy Positive";
    else if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 1) && (ExpertPreviousClosedOrderStatusInValue <= 0) && (ExpertPreviousClosedOrderType == 0))
    ExpertPreviousClosedOrderTypeAndStatusInValue = "Buy Negative";
    else if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 2) && (ExpertPreviousClosedOrderStatusInValue > 0) && (ExpertPreviousClosedOrderType == 1))
    ExpertPreviousClosedOrderTypeAndStatusInValue = "Sell Positive";
    else if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 2) && (ExpertPreviousClosedOrderStatusInValue <= 0) && (ExpertPreviousClosedOrderType == 1))
    ExpertPreviousClosedOrderTypeAndStatusInValue = "Sell Negative";
    else if ((ExpertTotalClosedOrdersNumber <= 1)
    ExpertPreviousClosedOrderTypeAndStatusInValue = "No Previous Closed Order Yet";
    }
    }
    }
    return(ExpertPreviousClosedOrderTypeAndStatusInVal ue);
    }

    Click image for larger version

Name:	Indentifying Previous Order Type And Financial Status As String.png
Views:	1
Size:	241.7 KB
ID:	17392027
     
    *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
    *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

    Comment

    Advanced mode
    • #3 Collapse

      Originally posted by Ahmed Taher Taher Awad View Post
      Identifying "previous" closed order "the one closed before last one it's Type,Magic Number and Result and Combine Them Into String (My own programmed)

      The blew mentioned code will allow you to achieve deeper and longer chart reading, the main purpose is reading the chart as a continues three levels leads to seeing the chart as a price a vertical or horizontal channels and/or trends, we will achieve that if we applying the blew code for an active trade and for the last closed one and passing through the one closed before the latest closed order, there are no one talked about "previous" closed order so today i will explaining how to " Identifying "previous" closed order "the one closed before last one by using count from up "latest closed order" to down "your first closed order" but as long as the code tries to only skip last closed order and dealing with the one closed before it so we have to force the code to stop the count after the count equals to 2 that's why you will find a calculation to count all orders then deducted one from it "refers to latest closed one" and if the result match 1 "refers to the previous order before latest closed one" that's mean the calculation was: 2 "already count last closed order and the one closed before it" - 1 "latest order we want to skip" = 1 "the previous order we want to deal with", then only after reach previous during the count the code will order few things related to that previous order it's: magic number, order type the order profits, then using them together we will have 5 cases, but first you have to count all closed orders in this function or outside to know if all counted orders number equals to or bigger than 2 that's means there will be latest closed order and another one before it at least "the one we dealing with" :

      1- All closed orders was 2 or bigger and the previous closed order hold 1 as a magic number for Buy "set in the line of send order in your code", and was profitable and it's type returns 0 "default for OP_BUY", the code will return "Buy Positive" as a string.
      2- All closed orders was 2 or bigger and the previous closed order hold 1 as a magic number for Buy, and was negative and it's type returns 0 "default for OP_BUY", the code will return "Buy Negative" as a string.
      3- All closed orders was 2 or bigger and the previous closed order hold 2 as a magic number for Sell, and was profitable and it's type returns 1 "default for OP_SELL", the code will return "Sell Positive" as a string.
      4- All closed orders was 2 or bigger and the previous closed order hold 2 as a magic number for Sell, and was negative and it's type returns 1 "default for OP_SELL", the code will return "Sell Negative" as a string.
      5- All closed orders was 1 or 0 that's means there are still no previous closed order as long as previous needs to have 2 closed orders at least to consider the second as previous, and the code return "No Previous Closed Order Yet" as a string.

      " The Code"


      string CalExpertPreviousClosedOrderTypeAndStatusInValue() // Expert Previous Closed Order Type And Status In Value // Previous: Identifies The Status Of The Closed Order Which Have Been Closed Before The Latest Closed Order.
      {
      double ExpertTotalClosedOrdersNumber = CalExpertTotalClosedOrdersNumber();
      int CountTotalClosedOrdersPre;
      for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) //:For Analyze Closed Orders From Up "Biggest Ticket" To Down,//(int i=0; i<OrdersHistoryTotal(); i++):For Analyze Closed Orders From Down "Lowest Ticket" To Up "Biggest Ticket".
      if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      {
      if (OrderSymbol() == Symbol()) // Use Current Chart Symbol While Analyze
      {
      CountTotalClosedOrdersPre++; // Count ALl Closed Orders
      if (((CountTotalClosedOrdersPre - 1) == 1) && (CountTotalClosedOrdersPre != 0)) //The Rule Avoid Zero As a Result Of The Above Count And Only Accept 1 Or Bigger Number So When's Result Match 1 It Stops To Continue What's Below.
      {
      int ExpertPreviousClosedOrderMagicNumber = OrderMagicNumber(); // 1 For Buy ,2 For Sell
      double ExpertPreviousClosedOrderStatusInValue = OrderProfit();
      int ExpertPreviousClosedOrderType = OrderType(); // 0 = OP_BUY ,1 == OP_SELL
      // Based On What Have Been Identified Above To Combine Them Together And Return string Of Four Cases: "Buy Positive", "Buy Negative", "Sell Positive", "Sell Negative".
      if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 1) && (ExpertPreviousClosedOrderStatusInValue > 0) && (ExpertPreviousClosedOrderType == 0))
      string ExpertPreviousClosedOrderTypeAndStatusInValue = "Buy Positive";
      else if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 1) && (ExpertPreviousClosedOrderStatusInValue <= 0) && (ExpertPreviousClosedOrderType == 0))
      ExpertPreviousClosedOrderTypeAndStatusInValue = "Buy Negative";
      else if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 2) && (ExpertPreviousClosedOrderStatusInValue > 0) && (ExpertPreviousClosedOrderType == 1))
      ExpertPreviousClosedOrderTypeAndStatusInValue = "Sell Positive";
      else if ((ExpertTotalClosedOrdersNumber >= 2) && (ExpertPreviousClosedOrderMagicNumber == 2) && (ExpertPreviousClosedOrderStatusInValue <= 0) && (ExpertPreviousClosedOrderType == 1))
      ExpertPreviousClosedOrderTypeAndStatusInValue = "Sell Negative";
      else if ((ExpertTotalClosedOrdersNumber <= 1)
      ExpertPreviousClosedOrderTypeAndStatusInValue = "No Previous Closed Order Yet";
      }
      }
      }
      return(ExpertPreviousClosedOrderTypeAndStatusInVal ue);
      }

      [ATTACH=CONFIG]311032[/ATTACH]
      - a little change regarding the fifth case so the blew code will better:

      string CalExpertPreviousClosedOrderTypeAndStatusInValue() // Expert Previous Closed Order Type And Status In Value // Previous: Identifying The Status Of The Closed Order Which Have Been Closed Before The Latest Closed Order.
      {
      int EATotalClosedOrdersNumber;
      for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) //:For Analyze Closed Orders From Up "Biggest Ticket" To Down,//(int i=0; i<OrdersHistoryTotal(); i++):For Analyze Closed Orders From Down "Lowest Ticket" To Up "Biggest Ticket".
      if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      {
      if (OrderSymbol() == Symbol()) // Use Current Chart Symbol While Analyze
      {
      EATotalClosedOrdersNumber++; // Count ALl Closed Orders
      if ((EATotalClosedOrdersNumber > 1) && ((EATotalClosedOrdersNumber - 1) == 1) && (EATotalClosedOrdersNumber != 0)) //The Rule Avoid Zero As a Result Of The Above Count And Only Accept 1 Or Bigger Number So When's Result Match 1 It Stops To Continue What's Below.
      {
      int ExpertPreviousClosedOrderMagicNumber = OrderMagicNumber(); // 1 For Buy ,2 For Sell
      double ExpertPreviousClosedOrderStatusInValue = OrderProfit();
      int ExpertPreviousClosedOrderType = OrderType(); // 0 = OP_BUY ,1 == OP_SELL
      // Based On What Have Been Identified Above To Combine Them Together And Return string Of Four Cases: "Buy Positive", "Buy Negative", "Sell Positive", "Sell Negative".
      if ((ExpertPreviousClosedOrderMagicNumber == 1) && (ExpertPreviousClosedOrderStatusInValue > 0) && (ExpertPreviousClosedOrderType == 0))
      string ExpertPreviousClosedOrderTypeAndStatusInValue = "Buy Positive";
      else if ((ExpertPreviousClosedOrderMagicNumber == 1) && (ExpertPreviousClosedOrderStatusInValue <= 0) && (ExpertPreviousClosedOrderType == 0))
      ExpertPreviousClosedOrderTypeAndStatusInValue = "Buy Negative";
      else if ((ExpertPreviousClosedOrderMagicNumber == 2) && (ExpertPreviousClosedOrderStatusInValue > 0) && (ExpertPreviousClosedOrderType == 1))
      ExpertPreviousClosedOrderTypeAndStatusInValue = "Sell Positive";
      else if ((ExpertPreviousClosedOrderMagicNumber == 2) && (ExpertPreviousClosedOrderStatusInValue <= 0) && (ExpertPreviousClosedOrderType == 1))
      ExpertPreviousClosedOrderTypeAndStatusInValue = "Sell Negative";
      }
      else if (EATotalClosedOrdersNumber <= 1)
      {
      ExpertPreviousClosedOrderTypeAndStatusInValue = "No Previous Closed Order Yet";
      }
      }
      }
      return(ExpertPreviousClosedOrderTypeAndStatusInVal ue);
      }

      Click image for larger version

Name:	Indentifying Previous Order Type And Financial Status As String.png
Views:	1
Size:	231.3 KB
ID:	17392029
         
      *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
      *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

      Comment

      Advanced mode
      • #4 Collapse

        &quot; Identifying account currency (My own programmed)&quot;

        " Identifying account currency (My own programmed)"


        The Blew code is dentifying account currency as a symbol such as USD in case of it was Us Dollar, EUR in case of it was European Zone currency and so on.

        "The Code"

        string CalAccountCurrency() // Account Currency
        {
        string ExtractAccountCurrency = AccountInfoString(ACCOUNT_CURRENCY); // Returns currency name of the current account.
        return(ExtractAccountCurrency);
        }

        Click image for larger version

Name:	account currency.png
Views:	1
Size:	168.8 KB
ID:	17392034
           
        *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
        *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

        Comment

        Advanced mode
        • #5 Collapse

          &quot; Identifying account currency and giving it a short symbol (My own programmed)&quot;

          " Identifying account currency and giving it a short symbol (My own programmed)"


          The Blew code is identifying account currency as giving it a short name "not ready as is in mql4 language" so based on the currency name function "which is exist" and which i shared it in the previous post the currency short name will be given as follow : $ for USD, Alt+0162 for US Cent, € Or Alt+0128 for Euro, Alt+0163 for British Pound, Alt+0165 for Japanese yen, and if the account currency doesn't match any of the previously mentioned currencies then it will be showed as is, using the short name generated from this function is useful specially if you want to follow your chart's financial numbers with the currency name but as a symbol as long as it make it's line more unique than the lines calculated and end with the word "point" as an example.

          "The Code"


          Click image for larger version

Name:	account currency short name.png
Views:	1
Size:	183.6 KB
ID:	17392035
             
          *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
          *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

          Comment

          Advanced mode
          • #6 Collapse

            &quot; Identifying Zero Spread feature ( My Own Programmed ) &quot;

            " Identifying Zero Spread feature ( My Own Programmed ) "


            The Blew code is identifying account spread, is there are a deference between Ask and Bid prices?, if yes then this account type have a spread and the code will return zero spread feature as string as follows : "Absent", otherwise if Ask and Bid prices are the same then the code will return zero spread feature as string as follows : "Supported", identifying Zero Spread feature is important if you would like to trade on specific account type and/or as additional step you can add a spread counter then only apply send orders if it was at specific level and avoid trading at another spread level.

            "The Code"

            string CalZeroSpreadFeautureStatus()
            {
            //double DifferBetweenAskAndBid = MarketInfo(Symbol(),MODE_SPREAD); //Alternative
            double DifferBetweenAskAndBid = (Ask - Bid);
            if (DifferBetweenAskAndBid == 0 )
            string ZeroSpreadFeautureExistStatus = "Supported";
            else if (DifferBetweenAskAndBid > 0 )
            ZeroSpreadFeautureExistStatus = "Absent";
            return(ZeroSpreadFeautureExistStatus);
            }

            Click image for larger version

Name:	zero spread feature.png
Views:	1
Size:	174.6 KB
ID:	17392036
               
            *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
            *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

            Comment

            Advanced mode
            • #7 Collapse

              &quot; Identifying what we trade on as a Category and return it as a string (My own programmed) &quot;

              " Identifying what we trade on as a Category and return it as a string (My own programmed) "

              The Blew code is identifying what we trade on which category exactly which is "located in market watch section" and return the category name as a string so we can later showed it on the chart, the category returns as a number, 0 refers to "Forex", 1 refers to "CFD", 2 refers to "Futures", so we can string a word for each result " default number" so we can easily monitor it, knowing the category is highly important specially to using the suitable lot size without negatively impact on your free margin because sometimes Forex category lot doesn't match other categories lots like CFD and/or Futures lots, also there are an expiration date for CFD so you must know is what you trade holds an expiration date or not to better arrange your next step "re-new the contract manually as an example to keep it running targeting your targets".

              "The Code"

              string WhatWeTradeProfitCalculationMode() // Profit Calculation Mode //
              {
              string ProfitCalculationMode;
              int WhatWeTradeProfitCal = MarketInfo(Symbol(),MODE_PROFITCALCMODE);
              if (WhatWeTradeProfitCal == 0)
              ProfitCalculationMode = "Forex";
              else if (WhatWeTradeProfitCal == 1)
              ProfitCalculationMode = "CFD";
              else if (WhatWeTradeProfitCal == 2)
              ProfitCalculationMode = "Futures";
              return(ProfitCalculationMode);
              }

              Click image for larger version

Name:	Identifying what we trade on as a Category.png
Views:	1
Size:	177.3 KB
ID:	17392037
                 
              *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
              *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

              Comment

              Advanced mode
              • #8 Collapse

                &quot; Identifying Expiration Date and using it to create fourth string cases (My own programmed) &quot;

                " Identifying Expiration Date and using it to create fourth string cases (My own programmed) "


                The Blew code is identifying Expiration Date of what we trade on, it's important to know about it to arrange the future steps "re-new the deal", closing it before last day to avoid huge market volatility and so on, first of all we have to extract the local time and transfer it to from time string, then we have to extract the expiration date and transfer it to from time string as well, then by using StringCompare we will compare the two strings local time and expiration date and the result of such comparing have only 3 possible results, -1 means the first string is lower than the second, 0 means the two strings are equals to each other, 1 means the first string is bigger than the second string, so by having the result as a number we will name and string case -1 as follows : "Still In The Future And Will Be At ( "+ExpirationDate+" )", as long as the compared local time "first string" is lower than the second string "Expiration Date" due to the result -1, otherwise if the result was 0 then we will consider the Expiration date as "Met" and will name a string holds that status, or otherwise if the third case happened "result of comparing was 1" that's means the local time is already bigger than the expiration date so we will name the string as follows "Already Passed And Was At ( "+ExpirationDate+" )", and as a forth result "did not explained in mql4 source" the ExpirationDate might shows 1970.01.01 00:00:00 in this case that symbol we examines does not usually have any expiration date such as forex as an example so we will name the string as "There Are No Expiration Date For Current "+WhatWeTradeProfitCalculationMode()+" Symbol", and finally we will return the function result to use it in a future steps separately and/or with other functions.

                "The Code"

                string CalExpirationDate() // Usage Expire Date
                {
                string CalLocalTimeUsageExpireDate = CalLocalTime();
                datetime ExpirationDatePre = (MarketInfo(Symbol(),MODE_EXPIRATION));
                string ExpirationDate = (TimeToString(ExpirationDatePre,TIME_DATE + TIME_MINUTES + TIME_SECONDS));
                if ((ExpirationDate > 0) && (ExpirationDate != "1970.01.01 00:00:00"))
                {
                int CompareLocalTimeVsExpireDate = StringCompare(CalLocalTimeUsageExpireDate,Expirati onDate);
                if (CompareLocalTimeVsExpireDate == -1)
                string ExpirationDateToShow = "Still In The Future And Will Be At ( "+ExpirationDate+" )";
                else if (CompareLocalTimeVsExpireDate == 0)
                ExpirationDateToShow = "Met";
                else if (CompareLocalTimeVsExpireDate == 1)
                ExpirationDateToShow = "Already Passed And Was At ( "+ExpirationDate+" )";
                }
                else if (ExpirationDate == "1970.01.01 00:00:00")
                ExpirationDateToShow = "There Are No Expiration Date For Current "+WhatWeTradeProfitCalculationMode()+" Symbol";
                return(ExpirationDateToShow);
                }

                Click image for larger version

Name:	Expiration Date.png
Views:	1
Size:	189.8 KB
ID:	17392046
                   
                *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
                *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

                Comment

                Advanced mode
                • #9 Collapse

                  &quot; Identifying Symbol's Digits Number After Decimal Point (My own programmed) &quot;

                  " Identifying Symbol's Digits Number After The Decimal Point (My own programmed) "

                  The below code is identifying symbol's digits number after the decimal point the result could leads to one of four results : 2, 4, 3, 5 based on the account type and the symbol, symbol digits is considered as an important element as long as it could be used to calculate other things such as an accurate spread points as an example and/or identifying the exist of JPY currency as a part of specific currency pair as long as the majority of currency pairs which contains the Japanese Yen are actually a three and/or two digits symbols and on the other hand the other currency pairs which doesn't contains the Japanese Yen are four and/or five digits symbols.

                  "The Code"

                  int CalWhatIsSymbolDigits() // Symbol Digits //
                  {
                  int CheckDigits = MarketInfo(Symbol(),MODE_DIGITS);
                  return(CheckDigits);
                  }

                  Click image for larger version

Name:	Symbol's Digits Number After The Decimal Point.png
Views:	1
Size:	165.2 KB
ID:	17399957
                     
                  *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
                  *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

                  Comment

                  Advanced mode
                  • #10 Collapse

                    Please be noticed that I rewrote, corrected, reformatted, and combined two previously shared original posts of my own programmed mql4 code together to make them participate in "Bonus for quality" system.

                    " Identifying local time (my own programmed) "

                    1- The code's description and its purpose of usage:

                    The below code is identifying "local time" which is located in the left corner of the Task Bar, we can use it to arrange our trading plan by setting it to be applied only if our local time is already matched and/or passed a specific time set in the variable section at the beginning of EA, and on a related point, in general, it's two steps, then the third is return the transferred the value as a string, but as a shortcut, you can skip the second step where you have to transfer time to string and only doing it while getting a return from the string itself.

                    2- The code as it must be written into mql4 language:

                    Code:
                    string CalLocalTime()
                    {
                    datetime LocalTime = TimeLocal();
                    return(TimeToString(LocalTime,TIME_DATE + TIME_MINUTES + TIME_SECONDS));
                    }
                    3- The code's screenshot while writing into meta editor:

                    The code's screenshot as it appeared after writing and compiling it successfully inside MetaEditor, please check it below.
                    Click image for larger version  Name:	local time.png Views:	0 Size:	154.4 KB ID:	17933335

                    " Identifying server time (my own programmed) "

                    1- The code's description and its purpose of usage:

                    The below code is identifying server time, while local time is used to check our local time located in Task Bar, server time, on the other hand, is referring to the server time of the trading platform we use, server time is located in "Market Watch" section, usage of "server time" can be useful at some point if we compared it to "local time", such as in case of the difference between our "local time" and "server time" due to time zone.

                    To avoid such situation we can simply count on "server time" and not "local time" to make sure that all the operations our EA try to apply will be successfully applied, on of those operations is closing a trade based on local time, supposed than it's Friday and local time is 23:15 but in this case, server time will be Saturday and the time will be 00:15 so if we tried to close a trade based on local time 23:15 as it remains smaller than the weekly closing the trade won't be closed because it's close is allowed during working trading hours and long as the server time is 00:15 and not 23:15 so that means the market was closed 15 minutes ago, that's why it's better to count on Server Time if we would like to close a trade because in this case the "targeted specific server time for close" we set in the "variables section" of our EA will match the "server time" of the trading platform and will even automatically updated when time zone changed too so we won't need to add and/or deduct an hour in the setting field if the time zone is changed.

                    2- The code as it must be written into mql4 language:

                    Code:
                    string CalServerTime()
                    {
                    datetime ServerTime = TimeCurrent();
                    return(TimeToString(ServerTime,TIME_DATE + TIME_MINUTES + TIME_SECONDS));
                    }
                    3- The code's screenshot while writing into meta editor:

                    The code's screenshot as it appeared after writing and compiling it successfully inside MetaEditor, please check it below.
                    Click image for larger version  Name:	server time.png Views:	0 Size:	154.9 KB ID:	17933336
                       
                    Guest's Avatar
                    Last edited by ; 01-04-2022, 04:01 AM.
                    *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
                    *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

                    Comment

                    Advanced mode
                    • #11 Collapse


                      Please be noticed that I rewrote, corrected, reformatted, and combined two previously shared original posts of my own programmed mql4 code together to make them participate in "Bonus for quality" system.

                      " Identifying current chart symbol name (my own programmed) "

                      1- The code's description and its purpose of usage:

                      The below code is identifying the current chart symbol name, in another word it displays the current chart's currency pair name which is highly important if you would like to limit the EA to only running when it's applied or attached to specific currency pair, and in a related point the currency pair name will be displayed as it showed in the chart's upper frame.

                      2- The code as it must be written into mql4 language:


                      Please be noticed that hereafter the double slash you can add some explanation it won't impact the way the code's working, just an explanation like a short description of the function as an example.
                      Code:
                      string CalCurrentChartSymbolName()
                      {
                      string ExtractCurrentChartSymbolName = Symbol(); // Identifying current name of the current chart.
                      return(ExtractCurrentChartSymbolName); // Return current name of the current chart outside the function.
                      }
                      3- The code's screenshot while writing into MetaEditor:

                      The code's screenshot as it appeared after writing and compiling it successfully inside MetaEditor, please check it below.

                      Click image for larger version  Name:	11-current chart symbol name.png Views:	0 Size:	148.0 KB ID:	17936313

                      " Identifying minimum allowed lot by MetaTrader (my own programmed) "

                      1- The code's description and its purpose of usage:

                      The Below code is identifying the minimum allowed lot by MetaTrader, it's an important element we use each time while opening a trade that's why it's important to know what is the minimum allowed lot size which can help us to improve the trading strategy, especially those which are using compounded lot size to recover a previous occurred loss, so by knowing the minimum lot size we can send the right lot size to the server because sometimes it might be the common 0.01 but in some other cases due to the thing we trade on and/or the trading account type itself the minimum lot size could be different such as 0.10 as an example or even 1.00.

                      2- The code as it must be written into mql4 language:


                      Please be noticed that hereafter the double slash you can add some explanation it won't impact the way the code's working, just an explanation like a short description of the function as an example.
                      Code:
                      double CalculateMinimumAllowedLotByMetaTrader()
                      {
                      double MinimumAllowedLotByMetaTrader = (MarketInfo(Symbol(),MODE_MINLOT)); // Identifying minimum allowed lot set by MetaTrader.
                      return(MinimumAllowedLotByMetaTrader); // Return minimum allowed lot set by MetaTrader outside the function.
                      }
                      3- The code's screenshot while writing into MetaEditor:

                      The code's screenshot as it appeared after writing and compiling successfully it inside MetaEditor, please check it below.

                      Click image for larger version  Name:	12-minimum allowed lot by MetaTrader.png Views:	0 Size:	147.4 KB ID:	17936314
                         
                      *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
                      *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

                      Comment

                      Advanced mode
                      • #12 Collapse

                        Slots are the most lively and exciting games - both in the best online casinos and in real casinos, for example, in Las Vegas. Since the Internet boom, serious gaming casinos have come up with so many themes - https://casinobonustips.com/bonus/no-deposit-bonus/, bonus rounds and other features that players can lose count very quickly.

                        Comment

                        Advanced mode
                        • #13 Collapse

                          Originally posted by JamesNosss View Post
                          Slots are the most lively and exciting games - both in the best online casinos and in real casinos, for example, in Las Vegas. Since the Internet boom, serious gaming casinos have come up with so many themes - https://casinobonustips.com/bonus/no-deposit-bonus/, bonus rounds and other features that players can lose count very quickly.
                          Member: JamesNosss You shared a post related to an advertisement of something else different than InstaForex and in the wrong section of Investsocial, your acts are against the rules and against the main purpose of creating my thread which is only sharing my own programmed MQL4 codes, so kindly I hope you to take an action and delete your post.
                             
                          Guest's Avatar
                          Last edited by ; 05-04-2022, 12:05 PM.
                          *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
                          *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

                          Comment

                          Advanced mode
                          • #14 Collapse

                            " Identifying both of the latest opened and the latest closed order's ticket number "

                            " Identifying the latest opened order's ticket number " ( my own programmed )

                            The code's description and the purpose of usage:

                            The below-written code is identifying "latest opened order ticket number", as an important element while the trading process we can use it for many purposes such as: targeting this specific ticket number while closing an order among many, like in the case of the needy of putting an end to the latest opened order in case of it went into the negative price direction against the actual market price, the examination will start from the biggest ticket number which is located at the top of the terminal section until the smallest ticket number at the bottom of the terminal section.

                            The code as it must be written into mql4 language:

                            Please be noticed that I programmed the function myself and tested it successfully, you will find an explanation beside each line in the function right after the double slash, the explanation will describe what is that line achieves in this position of the function, how it works, and when it will continue to the other parts of the function and based on which elements.
                            Code:
                            // Hereafter the double slash you can add some explanation it won't impact the way the code's working, just an explanation like a short description of the function as an example.
                            int CalculateLatestOpenedOrderTicketNumber()            // Function's type and name: { Calculate the latest opened order ticket number, an integer will be returned }.
                            {
                             int CountOpenedOrders;                                 // An integer to be used for counting the opened orders, a step which will be done below.
                             int LatestOpenedOrderTicketNumber;                     // An integer that will be used as a final output step.
                             for (int i = OrdersTotal()-1; i >= 0; i--)             // Count from the latest "the biggest" opened ticket number to the first "the smallest" opened ticket number, in another word the count will start from up to down.
                             if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))        // Checking all opened orders and continue what's below:
                              {
                               if (OrderSymbol() == Symbol())                       // Checking if the examined symbol matches the currently opened chart symbol and if the matching met then continue what's below:
                                {
                                 CountOpenedOrders++;                               // Count all Opened Orders.
                                 if (CountOpenedOrders == 1)                        // Whenever the count reaches the value 1 then the counting process will be stopped to reflex what it's related to with taking into consideration this specific opened position.
                                                                                    // This specific opened trading position at count 1 will be the only one involved when asked for the final purpose of creating this function during the next step.
                                  {
                                   LatestOpenedOrderTicketNumber = OrderTicket();   // Request what we need from creating the function and in this case it is the Last Opened Order Ticket Number.
                                  }
                                }
                              }
                             return(LatestOpenedOrderTicketNumber);                 // The final step where the calculated element will be returned to be used in other ways outside this function.
                            }
                            The code's screenshot:

                            The code's screenshot as it appeared after writing and compiling it inside meta editor, please check it below.
                            Click image for larger version  Name:	13-Latest opened order's ticket number.png Views:	0 Size:	202.9 KB ID:	17952072

                            " Identifying the latest closed order's ticket number " ( my own programmed )

                            The code's description and the purpose of usage:

                            The below-written code is identifying "latest closed order ticket number", as an important element while the trading process we can use it for many purposes such as: targeting this specific ticket number while checking an order among many, like in the case of the needy of count if there was a closed order at least in the account history since the start of using this specific account, an important thing to know because sometimes we might need to make the first-ever lot size smaller as possible compared to the future lots due to the money management's plan, the examination will start from the biggest ticket number which is located at the top of account history to the smallest ticket number at the bottom of account history.

                            The code as it must be written into mql4 language:

                            Please be noticed that I programmed the function myself and tested it successfully, you will find an explanation beside each line in the function right after the double slash, the explanation will describe what is that line achieves in this position of the function, how it works, and when it will continue to the other parts of the function and based on which elements.
                            Code:
                            // Hereafter the double slash you can add some explanation it won't impact the way the code's working, just an explanation like a short description of the function as an example.
                            int CalculateLatestClosedOrderTicketNumber()            // Function's type and name: { Calculate the latest closed order ticket number, an integer will be returned }.
                            {
                             int CountClosedOrders;                                 // An integer to be used for counting the closed orders, a step which will be done below.
                             int LatestClosedOrderTicketNumber;                     // An integer that will be used as a final output step.
                             for (int i = OrdersHistoryTotal()-1; i >= 0; i--)      // Count from the latest "the biggest" closed ticket number to the first "the smallest" closed ticket number, in another word the count will start from up to down.
                             if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))       // Checking all closed orders and continue what's below:
                              {
                               if (OrderSymbol() == Symbol())                       // Checking if the examined symbol matches the currently opened chart symbol and if the matching met then continue what's below:
                                {
                                 CountClosedOrders++;
                                 if (CountClosedOrders == 1)                        // Whenever the count reaches the value 1 then the count process will be stopped to reflex what it's related to with taking into consideration this specific closed position.
                                                                                    // This specific closed trading position at count 1 will be the only one involved when asked for the final purpose of creating this function during the next step.
                                  {
                                   LatestClosedOrderTicketNumber = OrderTicket();   // Request what we need from creating the function and in this case it is the Latest closed order ticket number.
                                  }
                                }
                              }
                             return(LatestClosedOrderTicketNumber);                 // The final step where the calculated element will be returned to be used in other ways outside this function.
                            }
                            The code's screenshot:

                            The code's screenshot as it appeared after writing and compiling it inside meta editor, please check it below.
                            Click image for larger version  Name:	13-Latest closed order's ticket number.png Views:	0 Size:	201.5 KB ID:	17952073
                               
                            Guest's Avatar
                            Last edited by ; 24-04-2022, 05:44 AM.
                            *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
                            *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

                            Comment

                            Advanced mode
                            • <a href="https://www.instaforex.org/ru/?x=ruforum">InstaForex</a>
                            • #15 Collapse


                              Please be noticed that I rewrote, corrected, reformatted, and combined two previously shared original posts of my own programmed mql4 code together to make them participate in "Bonus for quality" system.

                              " Identifying both of contract size and trade's first allowed trading date "

                              1- " Identifying contract size (my own programmed) "

                              1- The code's description and its purpose of usage:

                              The below code is identifying "Contract Size" which refers to the units of 1 lot of the thing we trade on, it's located in a separated section called "Specifications" which we can examine its content by doing a right-click on the symbol of the thing we trade on where its located in the left side of the trading platform in "Market Watch" section and then we will be able to explore the symbol's Specifications.

                              And in a related point Forex as an example has 3 possible contract size based on the account type and the company as follow:

                              A- If contract size equals 1000 that's the common number for a cent account where 0.01 lot size makes 1 point value equals 0.001 USD.

                              B- Contract size which equals 10000 on the other hand making 1 point value equals 0.01 USD otherwise.

                              C- If the contract size carries the number 100000 that means it refers to the standard lot size where 0.01 lot means the point value will equal 0.10 USD.

                              So knowing the contract size makes us determine what will be the value of 1 point of the thing we trade on which give us the chance to free enough free margin and/or doing related other money management steps to protect the trading balance.

                              2- The code as it must be written into MQL4 language:

                              Please be noticed that hereafter the double slash you can add some explanation it won't impact the way the code's working, just an explanation like a short description of the function as an example.
                              Code:
                              double CalculateExtractContractSize()
                              {
                              double ExtractContractSize = (MarketInfo(Symbol(),MODE_LOTSIZE));
                              return(ExtractContractSize);
                              }
                              3- The code's screenshot while writing into MetaEditor:

                              The code's screenshot as it appeared after writing and compiling it successfully inside MetaEditor, please check it below.
                              Click image for larger version  Name:	13-Contract Size.png Views:	0 Size:	150.9 KB ID:	17955763


                              2- " Identifying trade's first allowed trading date (my own programmed) "

                              1- The code's description and its purpose of usage:

                              The below code is identifying "
                              Trade's first allowed trading date", while MODE_EXPIRATION refers to the expiration date of the current symbol "usually during a month", MODE_STARTING, on the other hand, refers to the starting allowed date when's you will be able to start trading that symbol.

                              Usually, it's applied for CFD and could be useful if you want to tell the code to check the current expiration date of the current month's symbol and then if it was near the "Starting Date" of the same symbol which will be applied next month then you can tell the code to stop trading on current month symbol and start trade on next month's symbol "sometimes depends on the symbol and the company the "Starting Date" might starts before the end of the current period so you can trade both periods if you would like too" as long as after expiration date you can not deal with the current month's symbol anymore.

                              So knowing the "Starting Date" is important to let the EA moves during the correct period "for receiving price ticks to apply check and other operations" to keep trading the same symbol but by making the transfer using its next month symbol.

                              And in a related point, the below code is making a comparison between "Local Time" and
                              "Trade's first allowed trading date" and based on 3 possible results -1, 0, or otherwise 1 the EA will string a status to let you know if the "Starting Date" is still in the future "case -1" or met "case 0" or otherwise has been already passed "case 1", also as a fourth case if there is no expiration date for the symbol you will see a function return's statement telling that as well.

                              2- The code as it must be written into MQL4 language:

                              Please be noticed that hereafter the double slash you can add some explanation it won't impact the way the code's working, just an explanation like a short description of the function as an example.
                              Code:
                              string CalFirstTradeDate() // Usage First Trade Date
                              {
                               string CalLocalTimeUsageFirstTradeDate = CalLocalTime();
                               datetime FirstTradeDatePre              = (MarketInfo(Symbol(),MODE_STARTING));
                               string FirstTradeDate                       = (TimeToString(FirstTradeDatePre,TIME_DATE + TIME_MINUTES + TIME_SECONDS));
                               if ((FirstTradeDate > 0) && (FirstTradeDate != "1970.01.01 00:00:00"))
                                {
                                 int CompareLocalTimeVsFirstTradeDate = StringCompare(CalLocalTimeUsageFirstTradeDate,Firs tTradeDate);
                                 if (CompareLocalTimeVsFirstTradeDate == -1)
                                  string FirstTradeDateToShow = "Still In The Future And Will Be At ( "+FirstTradeDate+" )";
                                 else if (CompareLocalTimeVsFirstTradeDate == 0)
                                  FirstTradeDateToShow = "Met";
                                 else if (CompareLocalTimeVsFirstTradeDate == 1)
                                  FirstTradeDateToShow = "Already Passed And Was At ( "+FirstTradeDate+" )";
                                }
                               else if (FirstTradeDate == "1970.01.01 00:00:00")
                                FirstTradeDateToShow = "There Are No First Trade Date For Current "+WhatWeTradeProfitCalculationMode()+" Symbol";
                               return(FirstTradeDateToShow);
                              }
                              3- The code's screenshot while writing into MetaEditor:

                              The code's screenshot as it appeared after writing and compiling successfully it inside MetaEditor, please check it below.

                              Click image for larger version  Name:	14-Trade's First Allowed Trading Date.png Views:	0 Size:	193.6 KB ID:	17955764
                               
                              Guest's Avatar
                              Last edited by ; 27-04-2022, 08:41 PM.
                              *You will be able to get back ONE point for each trade you have if you open new trading account through my Instaforex's partner website : http://ahmedtaher.insta-affiliate.com/en
                              *MQL4 : https://forum.mt5.com/showthread.php...i-wrote-myself

                              Comment

                              Advanced mode

                              Online

                              Loading...
                              X