Hi Nicolas,
Can you tell me if it’s possible to get access to the fields “Gain Today” and “Latent Gain” from the Order Book area.
I’m trying to build into my system a piece of code which will allow me to set a profit level for the strategy so when “Gain Today” or “Latent Gain” reach a certain level all trades for the strategy are closed and the system stopped. Am I thinking along the correct lines here or is there another way to code this.
Many thanks
WingParticipant
Veteran
For daily gain or loss, see code snippet below. For total gain, just use strategyprofit. Adapt the code to your needs (exiting strategy for example.)
// ---parameters
MaxDailyProfit=1000 //Max daily profit allowed (in money)
MaxDailyLoss=1000 //Max daily loss allowed (in money)
// first time we launch the code, the trading is allowed
once TradeAllowed=1
// reset the current state of the strateygprofit each new day
If intradaybarindex=0 then
MyProfit=STRATEGYPROFIT
TradeAllowed=1
endif
// test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowed
If StrategyProfit>=MyProfit+MaxDailyProfit or Strategyprofit<=MyProfit-MaxDailyLoss then
TradeAllowed=0
endif
// initiate a new BUY order
if TradeAllowed=1 and buyconditions then
buy 1 lot at market
endif
Hi Wing,
Many thanks for your speedy response to my question. This gives me the information I need.
Regards