EA: Place order of 50 percent equity?

I’m not good to EA’s.

I’ve decided which to open, buy/sell.

How do I only open at 50% of my equity?

I’m guessing Equity * 0.5.

But that does not get me the amount of pips.

Thanks.‌

I’m trying

trade.Buy(((AccountInfoDouble(ACCOUNT_EQUITY)/ AccountInfoInteger(ACCOUNT_LEVERAGE)) * 0.5) / SymbolInfoDouble(_Symbol,SYMBOL_BID));
it's stating error:  failed exchange buy 47.5321 EURUSD at 1.05232 [Invalid volume]

what am I doing wrong to get the correct pips for 50% of my equity?‌

Thanks.‌

Using this function:

double VolumeValue(double volume)
{
   double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
   int ratio=(int)MathRound(volume/volume_step);
   return ratio*volume_step;
}

And this:

trade.Buy(VolumeValue(((AccountInfoDouble(ACCOUNT_EQUITY)/ AccountInfoInteger(ACCOUNT_LEVERAGE)) * 0.5) / SymbolInfoDouble(_Symbol,SYMBOL_BID)));

It’s stating not enough money, what’s wrong?‌

The volume is expressed in lot, not in dollars, euros, or pounds.

1 standard lot if 100,000 unit (whatever the currency).

Please read the documentation.‌

Thanks for the link. Working correctly now. :slight_smile:

No, it’s not working correctly, it works about right when currency is around the 1.0 mark but when for example AUDJPY at around 85.0 then it’s too low.

Here’s what I currently have:

double volume = VolumeValue(((AccountInfoDouble(ACCOUNT_MARGIN_FREE)) * 0.5  /  SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE)) * AccountInfoInteger(ACCOUNT_LEVERAGE) / SymbolInfoDouble(_Symbol,SYMBOL_ASK));

Please help me out here because I can’t work this out.‌

Seems to be near it.‌

You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
Do NOT use TickValue by itself - DeltaPerLot
You must normalize lots properly and check against min and max.
You must also check FreeMargin to avoid stop out