Break even problem
Break even problem
22 Jun 2016, 16:31
Hello, I have a problem witch cAlgo bots.
How can I add a Breakeven SL when its gain, lets say 50 pips. I don't want to use normal SL when I open position. I want that this robot will create/set SL at open level when my pisition will gain 50 pips, and that SL will not fallow the price like trailing SL.
Any ideas?
Thanks for help
Replies
kricka
22 Jun 2016, 17:16
Position without a stop loss
Market Order 3.0 do have move to breakeven and add additional pips ( optional ) if you have a desire to do that, so the stop loss can be positioned exactly right.
If your purpose is to not to show the stop loss to the liquid providers you can set it very high like 100-500 pips. A position without a hard stop loss is very risky though because it will practically mean you are risking 100% of your trading account on one trade, unless you hedge the position immediately.
Information link: Market Order 3.0
@kricka
kaliszczak1991
22 Jun 2016, 18:27
tmc, I was trying to put it into the robot but it doesn't work.
I have to crate a new parameter, but I don't know how.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Buyrsi : Robot
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Periods", DefaultValue = 25)]
public int Periods { get; set; }
[Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
public int Volume { get; set; }
private RelativeStrengthIndex rsi;
protected override void OnStart()
{
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
}
protected override void OnBar()
{
if (rsi.Result.LastValue > 50)
{
Open(TradeType.Sell);
}
if (rsi.Result.LastValue < 50)
{
Open(TradeType.Buy);
}
if (rsi.Result.LastValue < 50)
{
Close(TradeType.Sell);
}
if (rsi.Result.LastValue > 50)
{
Close(TradeType.Buy);
}
}
private void Close(TradeType tradeType)
{
foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType))
ClosePosition(position);
}
private void Open(TradeType tradeType)
{
var position = Positions.Find("SampleRSI", Symbol, tradeType);
if (position == null)
ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI");
}
}
}
@kaliszczak1991
Jiri
22 Jun 2016, 21:39
Add this anywhere in the class.
protected override void OnTick() { foreach (var position in Positions.FindAll("SampleRSI", Symbol)) { if (position.StopLoss != position.EntryPrice) { if (position.Pips >= 50) { ModifyPosition(position, position.EntryPrice, position.TakeProfit); } } } }
@Jiri
ctid241637
06 Sep 2016, 07:50
RE:
Hi tmc,
Just wanted to say thanks for your responses here. Not sure if they helped OP but they sure helped me, thank you!
tmc. said:
Add this anywhere in the class.
protected override void OnTick() { foreach (var position in Positions.FindAll("SampleRSI", Symbol)) { if (position.StopLoss != position.EntryPrice) { if (position.Pips >= 50) { ModifyPosition(position, position.EntryPrice, position.TakeProfit); } } } }
@ctid241637
Jiri
22 Jun 2016, 16:56
Hi, try following snippet.
@Jiri