Indicator in the robot
Indicator in the robot
16 Jul 2013, 22:03
Hi.
How to implement Price Channel indicator in the robot, so I could set up length of periods, use it as stop loss and see indicator overlayed on the chart?
Thanks
Replies
iRobot
25 Jul 2013, 13:44
Although there is one thing you could me me a bit more.
I want to use price channels for stop loss in some cases. Let's say long position is opened and I want to fix lower band of price channel as a stop loss. If position is profitable, I want to change from "fixed" value of stop loss to a trailing stop.
Thanks.
@iRobot
atrader
25 Jul 2013, 14:55
RE:
Although there is one thing you could me me a bit more.
I want to use price channels for stop loss in some cases. Let's say long position is opened and I want to fix lower band of price channel as a stop loss. If position is profitable, I want to change from "fixed" value of stop loss to a trailing stop.
Thanks.
Hi, you can use the code from the cAlgo Sample Trailing.
@atrader
cAlgo_Fanatic
26 Jul 2013, 11:55
When the position is opened you can set the stop loss in pips.
var request = new MarketOrderRequest(tradeType, volume) { Label = LabelName, StopLossPips = StopLoss // This is a fixed value when the position is opened. TakeProfitPips = TakeProfit };
1. Create a method for trailing stop
2. Add a condition that checks if the position is profitable. You may check this in the OnBar or the OnTick events.
If the position is profitable call the method that implements trailing stop
@cAlgo_Fanatic
iRobot
31 Jul 2013, 23:13
Guys, sorry for stupid questions...
However, could you give suggestions on:
1) in a given robot, where to put other conditions for closing a profitable position (take profit, but not on specified pip size, but rather on conditions ment by other indicators);
2) how to make just one position opened at the time (now it opens new postions despite the number of curent positions).
Thank you very much.
@iRobot
cAlgo_Fanatic
06 Aug 2013, 11:33
RE:
Guys, sorry for stupid questions...
However, could you give suggestions on:
1) in a given robot, where to put other conditions for closing a profitable position (take profit, but not on specified pip size, but rather on conditions ment by other indicators);
2) how to make just one position opened at the time (now it opens new postions despite the number of curent positions).
Thank you very much.
1) The conditions may be in the OnTick event or in another method that is being called in the OnTick. See for instance the Sample Trend Robot in cAlgo.
2) Use a global field that is initialized in the OnPositionOpened event. There are examples in the samples included in cAlgo, e.g. Sample Trend Robot, Sample SAR Trailing Stop (the global field is "position").
@cAlgo_Fanatic
cAlgo_Fanatic
06 Aug 2013, 11:40
RE:
Although I have another question in this issue: how can I index price channel values? Let's say I need to have its values for for 3 periods in the past = should I use indexing or "foreach"?
You can use either one. The foreach statement traverses the whole list so you would need to add a break statement to stop once it reaches the last element you want to check.
The for loop uses indexing and you can specify how many elements it will traverse.
See also this c# loops tutorial.
@cAlgo_Fanatic
atrader
24 Jul 2013, 16:11
RE:
this is a robot that uses the price channels, but it is missing a lot of functionality since you have not described the trading logic.
You can use this as a starting point or you can share the rest of the trading logic, e.g. how are trading signals triggered, based on price channels as well? How many positions does the robot open simultaneously, etc.
This robot starts a trade based on an input parameter (Buy) and volume.
The stop loss is calculated based on the channels. There is Take profit as input parameter.
@atrader