Universal Volume calculation + adjust StopLoss (in pips)

Created at 18 Jul 2022, 01:48
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MA

marktbs

Joined 18.07.2022

Universal Volume calculation + adjust StopLoss (in pips)
18 Jul 2022, 01:48


Hi! I have checked all the topics related to Volume calculations & StopLoss but got confused, not all of them return correct values for different types of instruments (no base unit conversions and can't get the US30 volume correctly)

    1.  I need to get the following formula / method:

  • Calculate position volume (normalized) from percentage of account total balance (GBPleveraged), ex: input: 20 (20% from total balance)
  • 1 formula that works with: USDCHF, EURJPY, US30, XTIUSD (note: all of them have different pip size/value etc.. + US30 has max leverage of 200)
  • + Get monetary value(in account currency) of this volume (used to check against available margin etc..)

I am using ExecuteMarketRangeOrder() to open position, and I have cAlgo.API.Extensions installed.

 

    2.  Adjust StopLoss periodically to lower it, if price goes in position's favour, until the point when StopLoss is even(commission*2 + additional predefined pips, ex +1.2)

  • Calculate new StopLoss (OnTick, in pips) then:
    • adjust if its smaller then previous and price has moved in position favour (to open position I have pre-defined StopLoss in pips (ex. 3.4)
  • use ModifyStopLossPips() to make position adjustments (for any position at USDCHF, ERUJPY, US30 or XTIUSD)

 

Any help appreciated, thank you!


@marktbs