a little help with code
Page 1 of 732 12 LastLast
Results 1 to 10 of 313

Thread: a little help with code

  1. #1
    Ea that counts the amount of the wining trades in the initial.
    If (win) Winers ;

    today I would like it to count just from the last fifty transactions.
    And afer evry commerce, it'll updated to the new last fifty (like MA).

    IS THERE AN EASY WAY??

  2. #2
    Say you have an array that contains all of your Net profits over 100 transactions, call your Net_profit_Array,

    if you would like just the previous 50 trades from this variety, then you can create a new array, let's call it New_array, using https://docs.mql4.com/array/arraycopy and defining where you need to start copying from the original array by placing the src_start parameter to 50 as follows:

    ArrayCopy(New_array,Net_profit_Array,0,50,WHOLE_AR RAY);

    This may save the past 50 transactions of the original array into New_array, and then you can certainly do your computations as usual on this copied array.

    Naturally, you would want to set the src_start parameter to a factor if the size of the original Net_profit_Array keeps on changing.

    Good luck!

  3. #3
    Quote Originally Posted by ;
    Say you have an array that includes all your Net profits over 100 trades, call that your Net_profit_Array, if you would like only the last 50 trades from that array, then you may make a new array, let us call it New_array, by using https://docs.mql4.com/array/arraycopy and specifying where you want to start copying from the original array by placing the src_start parameter into 50 as follows: ArrayCopy(New_array,Net_profit_Array,0,50,WHOLE_AR RAY); This will store the last 50 trades of the first array into New_array, and then you...
    however how to make this Net_profit_Array, automaticly?

  4. #4
    Quote Originally Posted by ;
    quote but how to create this Net_profit_Array, automaticly?
    Where would you counting your winning transactions from in the first place? That is your Net_profit_Array. Glue all your code, and I'll attempt to explain.

    Good luck!

  5. #5
    Quote Originally Posted by ;
    quote Where would you counting your winning transactions from in the first loion? That's your Net_profit_Array. Glue of your code, and I will try and explain. Good luck!
    Once the ea closes a trade:
    (profit is the profit/loss of this trade, in $)

    if (profitgt;0) // winner trade
    Number_of_winners ;
    if (profitlt;0) // reduction
    number_of_losses ;

  6. #6
    Last_50_trades_result();


    // ------------------------------------------------------------------
    //Closing 50 trades result
    // ------------------------------------------------------------------
    void Last_50_trades_result()

    wins = 0;
    Sheds = 0;
    int depth_trades = 50;
    int total_trades = OrdersHistoryTotal();
    int limit;
    if(total_trades gt; depth_trades)
    Restrict = total_trades - depth_trades;
    else limit = 0;


    for(int I=total_trades; igt;=Limitation; I--)

    OrderSelect(I,SELECT_BY_POS,MODE_HISTORY);
    if(OrderProfit() gt; 0)
    wins ;
    if(OrderProfit() lt; 0)
    Sheds ;



    **** MODE_HISTORY Close the gap between HI and Also STORY

  7. #7
    Quote Originally Posted by ;
    Last_50_trades_result(); // ------------------------------------------------------------------ //Closing 50 trades result // ------------------------------------------------------------------ Emptiness Last_50_trades_result() Drops = 0; loses = 0; int depth_trades = 50; int total_trades = OrdersHistoryTotal(); int limit; if(total_trades gt; depth_trades) limit = total_trades - depth_trades; Otherwise limit = 0; for(int I=total_trades; igt;=Limitation; I--) OrderSelect(I,SELECT_BY_POS,MODE_HISTORY); if(OrderProfit() gt; 0) wins ; if(OrderProfit() lt; 0) loses ; ...
    THANK YOU VERY MUCH
    (and welcome to ff)

    if (Last_50_trades_result() ==true) anax =;

  8. #8
    Quote Originally Posted by ;
    Last_50_trades_result(); // ------------------------------------------------------------------ //Last 50 trades result // ------------------------------------------------------------------ emptiness Last_50_trades_result() drops = 0; loses = 0; int depth_trades = 50; int total_trades = OrdersHistoryTotal(); int limit; if(total_trades gt; depth_trades) limit = total_trades - depth_trades; else limit = 0; for(int I=total_trades; igt;=limit; I--) OrderSelect(I,SELECT_BY_POS,MODE_HISTORY); if(OrderProfit() gt; 0) wins ; if(OrderProfit() lt; 0) loses ; ...
    thank youit works alright.
    However, the OrdersHistoryTotal() counts expired pending orders.
    How can I prevent it from include them?

  9. #9
    Quote Originally Posted by ;
    quote thank you, it works fine. However, the OrdersHistoryTotal() counts expired pending orders. How can I stop it from include them?
    Attempt this

    Inserted Code // ------------------------------------ ------------------------------ //Last Minute trades lead // ------------------------------------ ------------------------------ int Last_N_trades_result(int depth_trades) { int wins = 0; int counted_trades=0; int total_trades = OrdersHistoryTotal(); for(int I=total_trades; igt;=0; I--)

  10. #10
    Quote Originally Posted by ;
    quote Try this // ------------------------------------ ------------------------------ //Last N transactions lead // ------------------------------------ ------------------------------ int Last_N_trades_result(int depth_trades) { int wins = 0; int counted_trades=0; int total_trades = OrdersHistoryTotal(); for(int I=total_trades; igt;=0; I--) if(! OrderSelect(I,SELECT_BY_POS,MODE_HISTORY)
    thank you
    but it doesnt works for me
    https://www.forexsoutheast.asia/atta...1174942499.mq4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.