fxDreema

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

    ClosedProfit() function

    Questions & Answers
    3
    3
    353
    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.
    • R
      RajVoCash last edited by

      Can anyone help me build this function into my strategy. And how can this be done? It would be nice to find an example. I know that there are custom blocks or custom functions, but it’s not clear how to use them.

      double ClosedProfit()
      {
      uint totalNumberOfDeals = HistoryDealsTotal();
      long orderType, dealEntry;
      ulong tickerNumber =0;
      double orderProfit =0;
      double orderSwap =0;
      double PositionHistoryProfit =0;
      double CurrencyPairHistoryProfit =0;
      string mySymbol ="";
      string positionDirection ="";
      string myResult ="";
      HistorySelect(0,TimeCurrent());
      for(uint i=0; i < totalNumberOfDeals; i++)
      {
      if((tickerNumber = HistoryDealGetTicket(i))>0)
      {

      if((tickerNumber = HistoryDealGetTicket(i))>0)
      {
      orderProfit = HistoryDealGetDouble(tickerNumber,DEAL_PROFIT);
      orderSwap = HistoryDealGetDouble(tickerNumber,DEAL_SWAP);
      orderType = HistoryDealGetInteger(tickerNumber,DEAL_TYPE);
      mySymbol = HistoryDealGetString(tickerNumber,DEAL_SYMBOL);
      dealEntry = HistoryDealGetInteger(tickerNumber,DEAL_ENTRY);
      if(mySymbol == _Symbol)
      if(orderType == ORDER_TYPE_BUY || orderType == ORDER_TYPE_SELL)
      if(dealEntry == 1)
      {
      if(orderType == ORDER_TYPE_BUY)
      positionDirection = "SELL";
      if(orderType == ORDER_TYPE_SELL)
      positionDirection = "BUY";
      PositionHistoryProfit = orderProfit + orderSwap;
      CurrencyPairHistoryProfit = NormalizeDouble(CurrencyPairHistoryProfit + PositionHistoryProfit, _Digits);
      }
      }
      }
      return CurrencyPairHistoryProfit;
      }

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

        No mate because you would have gotten it on your 1st post, (you did get help on that post), call people like @roar without the need to duplicate threads. I am quite interested to see if we can use custom functions here, I don't think we can. As I said you can get all the needed info from pink blocks.

        Learn fxDreema Without the Wait!

        My comprehensive book, available on Amazon, is packed with examples and invaluable insights to help you fast-track your learning journey.

        The paperback and hardback editions include MT4 & MT5 QR codes for easy access to all prebuilt projects and robots, including my latest gold trading robot!

        Don’t miss out

        Click here➡️ https://mybook.to/fxDreema to get your copy today!

        Enjoy! 😊

        1 Reply Last reply Reply Quote 1
        • roar
          roar @RajVoCash last edited by roar

          @RajVoCash you have a block "For each closed position", very simple to get the closed profit using that block and "modify variables". No need to use custom code.

          Technically its possible to use custom functions by either

          • Making a custom block in the studio
          • Taking the inside part of the function (the stuff within {}) and putting that to custom mql block, and finally putting the result (that would normally be the "return" statement) into a standard fxdreema variable.

          These 2 methods will be 50x more difficult than using the standard blocks, but youre welcome to try if you like making things difficult lol

          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
          • 1 / 1
          • First post
            Last post

          Online Users

          A
          P
          I
          G
          M
          M
          J
          T
          S
          T
          M
          O
          R
          E
          P
          B
          G

          28
          Online

          146.7k
          Users

          22.4k
          Topics

          122.6k
          Posts

          Powered by NodeBB Forums | Contributors