Topics
Replies
ac15x
22 Jul 2020, 16:47
RE:
PanagiotisCharalampous said:
Hi ac15x,
This is not the complete cBot code since I cannot just paste it and build it. Did you try to print the values? What SL and TP is set when the order is placed? Can you post an example?
Best Regards,
Panagiotis
Thanks I fixed it, the formula for stop loss is incorrect. I fixed this with this formula.
var stoploss = Math.Abs((entry - (Bars.LowPrices.Last(1) - (Symbol.PipSize * 3))) / Symbol.PipSize);
One last question with PlaceStopLimitOrder., if stop loss get hits first before entry, what is the best way to cancel the order?
Thanks,
@ac15x
ac15x
22 Jul 2020, 16:12
( Updated at: 21 Dec 2023, 09:22 )
RE:
PanagiotisCharalampous said:
Hi ac15x,
Can you provide the complete cBot code and an example of the issue? You need to explain what you expect the cBot to do and what does it do instead.
Best Regards,
Panagiotis
Thats the entire code basically im just coding automated entry 3 pips above the last bar high and stop loss 3 pips below the last bar low. Take profit is equal the number pips between entry and stop loss.
I think the error is calculating the number of pips between entry and stop loss.
var entry = Bars.HighPrices.Last(1) + (Symbol.PipSize * 3);
var stoploss = Math.Abs(entry - (Bars.LowPrices.Last(1) - (Symbol.PipSize * 3)) / Symbol.PipSize);
var takeProfit = stoploss;
@ac15x
ac15x
22 Jul 2020, 15:56
RE:
PanagiotisCharalampous said:
Hi ac15x,
You can use PlaceStopLimitOrder.
Best Regards,
Panagiotis
Thanks, that worked well. Still one issue remains seems like my pips calculation is wrong since it is not exiting position even after TP or SL reached.
protected override void OnBar()
{
if (LastResult== null ||( LastResult.PendingOrder == null && LastResult.Position == null))
{
SetEntry(trend);
}
}
private void SetEntry(Trend trend)
{
if (trend == Trend.Uptrend)
{
var entry = Bars.HighPrices.Last(1) + (Symbol.PipSize * 3);
var stoploss = Math.Abs(entry - (Bars.LowPrices.Last(1) - (Symbol.PipSize * 3)) / Symbol.PipSize);
var takeProfit = stoploss;
var result = PlaceStopLimitOrder(TradeType.Buy, SymbolName, 10000, entry, 5, InstanceName, stoploss, takeProfit);
}
}
@ac15x
ac15x
24 Jul 2020, 15:20 ( Updated at: 21 Dec 2023, 09:22 )
RE:
PanagiotisCharalampous said:
Hi made sure to do this but cannot seem to make it work
@ac15x