| / | Forum |
|
n8937g
2010.01.15 17:52
Can anyone point me to information that will help me.. I'm trying to loop thru all the open orders and get the Profit for all the Buy Orders only.... and the profit for all the Sell orders only. I want to use the info to close Buys and or Close Sells at some point....I also want to show them with "Comment"...but I'm having trouble looping and adding all the sells or all the buys using OrderProfit() Should be easy but....I must be missing something obvious. |
|
MQL4 Language for Newbies. Custom Indicators (Part 1) This is the fourth article from the series "MQL4 Languages for Newbies". Today we will learn to write custom indicators. We will get acquainted with the classification of indicator features, will see how these features influence the indicator, will learn about new functions and optimization, and, finally, we will write our own indicators. Moreover, at the end of the article you will find advice on the programming style. If this is the first article "for newbies" that you are reading, perhaps it would be better for you to read the previous ones. Besides, make sure that you have understood properly the previous material, because the given article does not explain the basics. |
|
cloudbreaker
2010.01.15 18:53
n8937g:
Can anyone point me to information that will help me.. I'm trying to loop thru all the open orders and get the Profit for all the Buy Orders only.... and the profit for all the Sell orders only. I want to use the info to close Buys and or Close Sells at some point....I also want to show them with "Comment"...but I'm having trouble looping and adding all the sells or all the buys using OrderProfit() Should be easy but....I must be missing something obvious. Show your loop and we'll fix. CB |
|
Matutin
2010.01.15 18:53
Hi try something like this double Calcul_Profit_Achat() if(OrderSelect(pos,SELECT_BY_POS)==false) continue; } // for(pos=0;pos<total;pos++)
} // double Calcul_Profit() |
|
n8937g
2010.01.15 23:25
Here's what I have...how can it be improved? When I have no, either Buy or Sell Orders..., BuyProfit or SellProfit still remain at their last value, not zero. They don't go to zero...even though there is no profit(or loss)... When I try to allow for the condition no sell or buy order present ...zero profit condition the whole thing goes up in smoke.... double xx= 0.00; //============================= if (1==1) |
|
meikel
2010.01.15 23:32
xx=OrderProfit(); BuyProfit= xx+OrderProfit(); xx=0; // that code makes no sense, it is equal to BuyProfit= OrderProfit()*2; // it should be something like this BuyProfit= BuyProfit+OrderProfit(); dont know what you want to do... if (1==1) makes no sense too.. if(true) is the same |
|
meikel
2010.01.16 00:13
n8937g:
i use something like if (true) { } regularly for debugging, but i have had never the idea to use if ((50*20*30/3)==(50*20*30/3)) {} for this purpose... ;-) |
|
n8937g
2010.01.16 00:26
You can ignore the if(1==1)..LOL I just use that when I'm trouble shooting something....and want to not have any other qualifiying conditions for a piece of code to run...The problem is not there.... Re. BuyProfit=BuyProfit+OrderProfit(); It looks right but when I run it that way it just keeps adding and adding.... when I use the xx or yy it just acts like a buffer that gets reset to zero every loop cycle. I'm trying to get the total profit(or loss) from only all the open Buy orders...and the total profit (or loss) from only all the open sell orders. ie Comment ("\nBuyProfit ",BuyProfit, "\nSellProfit ",SellProfit) What/how should I reset BuyProfit or SellProfit to zero if there are no open either buy or sell orders...as BuyProfit and SellProfit will retain their last value even if there are no orders . I'd like to do this without another loop...if possible. Thanks |
|
meikel
2010.01.16 00:45
define BuyProfit global outside start and init (after the extern etc) in start, write BuyProfit=0; immidiatly after the start funtion starts then start your loop this should work |
|
n8937g
2010.01.16 00:59
meikel wrote >>
define BuyProfit global outside start and init (after the extern etc) in start, write BuyProfit=0; immidiatly after the start funtion starts then start your loop this should work WOW That worked GREAT...I was looking for a complicated solution...sometimes somethings are so obvious, but you can't see them....LOL Thank you soooo much!! |
|
meikel
2010.01.16 01:15
n8937g:
WOW That worked GREAT...I was looking for a complicated solution...sometimes somethings are so obvious, but you can't see them....LOL Thank you soooo much!! thanks for the thanks - nice to read this from time to time LOL i think the issue is, that if you define a variable in a function and in the same line give this variable a value, the compiler runs this line only once, and therefore the value is only given to the variable at the first run. nice that it is working now. have a nice weekend... |