| / | Forum |
|
kiwi06
2010.09.19 01:32
Hi I have this bit of code extern double Ratio=1.10; double StopLoss = (AccountEquity()/AccountBalance()>Ratio) *Point; I am trying to have a 10% StopLoss based on 10% of the equity. Am I on the right track or way off based to get this right. Any help would be great. |
|
Genetic Algorithms vs. Simple Search in the MetaTrader 4 Optimizer The article compares the time and results of Expert Advisors' optimization using genetic algorithms and those obtained by simple search. |
|
ubzen
2010.09.19 02:54
There are allot of examples Here.
|
|
kiwi06
2010.09.20 20:01
Not quite what I am looking for I am using a fixed lot. Balance 10010% SL 10 TickValue 9.5 Lot Size 0.01 TickSize 0.095 SL in pips 105.2632 I think the code would go like this double Cash= (AccountBalance()*0.1 ) / MarketInfo(Symbol(),MODE_LOTSIZE)/MarketInfo(Symbol(), MODE_TICKVALUE)/MarketInfo(Symbol(),MODE_TICKSIZE); Or something like that |
|
qjol
2010.09.20 20:18
you should use NormalizeDouble(...,...)
|
|
hasayama
2010.09.20 20:26
Let us think a little: 1. We want to risk 10% of our balance, so: risk = AccountBalance()*0.1; 2. We want to risk it with constant lot size: Lot = 0.01. 3. 1 Lot costs: lot_cost = MarketInfo( Symbol(), MODE_TICKVALUE ); 4. So, our lot costs: our_lot_cost = Lot*lot_cost = 0.01*lot_cost; 5. Basicaly, every pip that goes in the opposite direction we lose our_lot_cost amout. 6. So, 10% of balance will be lost in SL = risk/our_lot_cost pips. Or: extern int Risk_Percentage = 10; extern double Lot = 0.01; int GetSLinPips() { double risk = AccountBalance()*Risk_Percentage/100.0; //get how much it is ok to lose int SL = NormalizeDouble( risk/(Lot*MarketInfo( Symbol(), MODE_TICKVALUE )), 0 ); return(SL); } Hope I'm right=) |
|
kiwi06
2010.09.20 21:33
Well I will give it ago
|
|
1005phillip
2010.09.21 05:43
hasayama:
3. 1 Lot costs: lot_cost = MarketInfo( Symbol(), MODE_TICKVALUE ); That is true for only those few currency pairs for which the counter currency is also the account's denomination. EURUSD for a USD based account for example. Would be wrong for USDJPY with a USD based account. Would be wrong for all crosses. |
|
hasayama
2010.09.21 11:30
1005phillip: Ok, could you please recommend how to turn it into universal solution?
That is true for only those few currency pairs for which the counter currency is also the account's denomination. EURUSD for a USD based account for example. Would be wrong for USDJPY with a USD based account. Would be wrong for all crosses. |
|
1005phillip
2010.09.21 15:57
hasayama:
Ok, could you please recommend how to turn it into universal solution?
//+-------------------- //| SymbolType() //|==================== //| int SymbolType(bool verbose=false) //| //| Analyzes Symbol() to determine the SymbolType for use with Profit/Loss and lotsize calcs. //| The function returns an integer value which is the SymbolType. //| An integer value of 6 for SymbolType is returned in the event of an error //| //| Parameters: //| //| verbose - Determines whether Print messages are committed to the experts log. By default, print messages are disabled. //| //| Examples: //| //| SymbolType 1: Symbol() = USDJPY //| //| Base = USD //| Counter = JPY //| //| SymbolType 2: Symbol() = EURUSD //| //| Base = EUR //| Counter = USD //| //| SymbolType 3: Symbol() = CHFJPY //| //| Base = CHF //| Counter = JPY //| //| USD is base to the base currency pair - USDCHF //| //| USD is base to the counter currency pair - USDJPY //| //| SymbolType 4: Symbol() = AUDCAD //| //| Base = AUD //| Counter = CAD //| //| USD is counter to the base currency pair - AUDUSD //| //| USD is base to the counter currency pair - USDCAD //| //| SymbolType 5: Symbol() = EURGBP //| //| Base = EUR //| Counter = GBP //| //| USD is counter to the base currency pair - EURUSD //| //| USD is counter to the counter currency pair - GBPUSD //| //| SymbolType 6: Error occurred, SymbolType could not be identified //| //+-------------------- As you can see there are two currency types that involve the account's denomination - those for which the account's currency represents the base in the currency pair (USDJPY, USDCHF) and those for which is represents the counter-currency (EURUSD, GBPUSD). |