expert advisor - miscellaneous questions - page 16

 

 Market closed! 

#1 - I never call Button Object by OnTick(), Start(), so is it normal?
#2
Can I apply to Button Object 'ANCHOR_RIGHT_UPPER'?
#3 - So, I still need help for my this concern #145, please.

Thanks! 

 

#1 - I never call Button Object by OnTick(), Start(), so is it normal?

Yes

#2Can I apply to Button Object 'ANCHOR_RIGHT_UPPER'?

No, the anchor point is fixed to ANCHOR_LEFT_UPPER

#3 - So, I still need help for my this concern #145, please.

Yes, you are correct - EventSetMillisecondTimer(250) 

 
honest_knave:

Yes
No, the anchor point is fixed to ANCHOR_LEFT_UPPER
Yes, you are correct - EventSetMillisecondTimer(250) 

Much appreciate. Big thanks man.
 

#Profit Orders Counting - Open

I just try to get all profitable positions for calculate all in one value.
It gives me separately values.

I really lost my mind. I tried few ways, and researching a lot about it, but no good results.
Please, help me, if it is possible explain a bit more about profit calculation, much appreciate.

I hope I will get good answer soon. 

void profitcalcfnc()
{
    double trueprofit = 0;
    for ( int i = OrdersTotal() - 1; i >= 0; i-- )
    {
        if  ( ! OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) continue;
        if  ( closeothers == false && OrderSymbol() != Symbol() ) continue;
        trueprofit = OrderProfit() + OrderSwap() + OrderCommission();
        if  ( trueprofit >= 0 )
        {
            Print( "Profit: ", trueprofit );
            ObjectSetString  ( 0, "all profit counting object", OBJPROP_TEXT, DoubleToString( trueprofit, 2 ) );
        }
    }
    //---
    return;
}

Thanks in advance.

 
trueprofit = OrderProfit() + OrderSwap() + OrderCommission();

Your are overwriting the value of trueprofit on each iteration of the loop, rather than adding to the value.

Remember this: 

profit = OrderProfit();

was changed to this: 

profit_buy += OrderProfit();
You need to be clear between what you want to happen on each iteration of the loop (each order) and what you want to happen after the loop (after you have checked all the orders).
 
honest_knave:
You need to be clear between what you want to happen on each iteration of the loop (each order) and what you want to happen after the loop (after you have checked all the orders).

Thanks for your quickly reply. 
Maybe I am so tired, so sorry. ( Just I can't understand what I could do. )

I need to describe a bit more my concern ( how much I can ).
So, I have 2 functions:

  1. I use first of them for Button function - which one when I click it all Profitable positions will close. It works good so far. ( I can't test it enough - my broker is disabled trades )
  2. I use second of them for Label function - which one it could shows me all profitable values in just one Label Object. ( But I can't do it )

Finally, I would like to this ( my latest comment code ) profit calculate function could calculate both types of Orders " OP_SELL and OP_BUY " just profitable.

Thanks in advance. 

 

how are you trying to show all profitable values in one Label?

Do you mean all added up AcountProfit() or for each separate OrderProfit().

If you need something like this:


Please see this article:

https://www.mql5.com/en/articles/2723

Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
  • 2016.10.17
  • Anatoli Kazharski
  • www.mql5.com
The next version of the Easy And Fast library (version 3) is presented in this article. Fixed certain flaws and added new features. More details further in the article.
 

Thanks for your comment.
Sorry for the confusion. 

No, I think I need little different from it.
I will try to clarify my issue.

I have 3 positions for EURUSD. Two of them profitable positions, one of them loss position. So I just need to calculate two of them which is they are profitable.
eg: if each of them +1.00 ( 2 profitable positions = +2.00 ) just I need to get all profitable positions value.

Print( "Profit: ", 2.00 ); // absolutely no separately - I just need - could adds profitable values 1.00 + 1.00 = 2.00

I just quick made below tab for helps me what I am trying to say. ( at the below of this comment image file )
( English not my native language - sometimes I struggling with it )

All the best.

Trade Panel Tab image file 

 
double totalprofit=0;

// in your orderselect loop put
if(OrderProfit()>0)
{
  totalprofit=totalprofit+OrderProfit();
}
 

#Profit Orders Counting - Closed
 

Marco vd Heijden:
if(OrderProfit()>0)
{
  totalprofit=totalprofit+OrderProfit();
}

I solve my issue after your great example code.
Great man, big thanks!

 



honest_knave:

Your are overwriting the value of trueprofit on each iteration of the loop, rather than adding to the value.
Remember this:
You need to be clear between what you want to happen on each iteration of the loop (each order) and what you want to happen after the loop (after you have checked all the orders).

Just after finished below code script.
Once again I check your comment, then I know you explain it me. But my English prevent to understand it.

All the best to each of you men.

void calc()
{
    double trueprofit  = 0;
    double totalprofit = 0;

    for ( int i = OrdersTotal() - 1; i >= 0; i-- )
    {
        if  ( ! OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) continue;
        if  ( closeothers != true && OrderSymbol() != Symbol() ) continue;

        trueprofit = OrderProfit() + OrderSwap() + OrderCommission();
        if  ( trueprofit >= 0 )
        {
            totalprofit += OrderProfit() + OrderSwap() + OrderCommission();
            Print( "Profit: ", DoubleToString( totalprofit, 2 ) );
            ObjectSetString  ( 0, _Checkthisout_name_Label, OBJPROP_TEXT, "Total Profit: " + DoubleToString( totalprofit, 2 ) );
        }
    }
    //---
    return;
}

I hope this code script will work good. If something wrong in above code, please let me know.
Thanks for everything.