Hi everyone,
Just wondered if you could advise on few things.
- How to code trailing BUY orders based on a price difference from a previous order?
- How to code current remaining account balance or percentage from it?
Thanks.
Hello,
You can try these codes for trailing stop functions:
http://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-execution-mfe/
http://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
To retrieve the current balance of your account, you need first to set a variable with the balance amount at the launch of the algorithm, because it is not possible to get it with code. Then just add the strategy profit to it and you’ll get the current balance amount:
initialbalance = 9500 //set it one time at script launch
currentbalance = initialbalance + STRATEGYPROFIT
Thank you, much appreciated.
I looked at some examples of cumulative orders but not entirely sure how to translate them into a buying order such as:
Buying 1st order at price x, 2nd order at price x + variable, 3d order at the price of a previous order + variable
There are examples for shares but there is no equivalent for spreadbetting where position expressed as £pp
Example:
DEFPARAM CumulateOrders = True
If CountOfPosition < 2 THEN
Buy 1 shares at 2 Limit
Buy 1 shares at 3 Limit
Endif
You can find example of adding positions in the TRADEPRICE instruction page :
http://www.prorealcode.com/documentation/tradeprice/
Tried suggested code but system constantly adds positions at stated interval, how to limit them to 3 ?
IF c1 THEN
BUY Positionsize PERPOINT AT MARKET
ENDIF
If CountOfPosition < 2 then
ENDIF
IF BARINDEX-TRADEINDEX(1)>increment AND Close-TRADEPRICE(1)>increment*2 AND LongOnMarket THEN
BUY positionsize perpoint at market
ENDIF
Thank you.
Your ENDIF at line 5 should be at the end of the code otherwise your count of position test is doing nothing.
Done that. Still buying/selling orders continuously until exit. I need to limit them to 3 or 4 max. Any ideas? Thanks
Seems to be working now. Thank you for your advice.