Robot on several chart
Robot on several chart
18 May 2022, 09:37
Hi, when I run this robot on one currency pair, it works properly. But when I run it on several charts at the same time, only one of them works
Thanks in advance for your guidance
And can you give a method in which the stop loss is at the entry point (after moving slightly in the direction of profit)
thank youu
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots37
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FractalsSample37 : Robot
{
private double _volumeInUnits;
private Fractals _fractals;
[Parameter("Max Spread", DefaultValue = 100, MinValue = 0, MaxValue = 300)]
public double MaxSpread { get; set; }
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 20)]
private double StopLossInPips { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 60)]
private double TakeProfitInPips { get; set; }
[Parameter("Label", DefaultValue = "Sample")]
public string Label { get; set; }
public Position[] BotPositions
{
get
{
return Positions.FindAll(Label);
}
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_fractals = Indicators.Fractals(5)
;
}
protected override void OnBar()
{
var cBotPositions = Positions.FindAll(Label);
if (_fractals.UpFractal.LastValue <Bars .ClosePrices .Last (1) )
{
ClosePositions(TradeType.Sell);
if (cBotPositions .Length ==0 ){
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits,Label, StopLossInPips, TakeProfitInPips);
}}
else if ( _fractals.DownFractal.LastValue >Bars.ClosePrices .Last (1) ) {
ClosePositions(TradeType.Buy);
if (cBotPositions.Length ==0 ){
ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits,Label , StopLossInPips, TakeProfitInPips);
}}
}
private void ClosePositions(TradeType tradeType)
{
foreach (var position in BotPositions)
{
if (position.TradeType != tradeType) continue;
ClosePosition(position);
}
}
}
}
Replies
hamijonz
05 Jun 2022, 20:55
( Updated at: 05 Jun 2022, 21:03 )
RE: thank you so much
amusleh said:
private void MoveStopLossToProfit(Position position, double profitInPips) { var positionSymbol = Symbols.GetSymbol(position.SymbolName); var profitInPipsSize = positionSymbol.PipSize * profitInPips; var newStopLossPrice = position.TradeType == TradeType.Buy ? position.EntryPrice + profitInPipsSize : position.EntryPrice - profitInPipsSize; ModifyPosition(position, newStopLossPrice, position.TakeProfit); }
@hamijonz
amusleh
30 May 2022, 10:20
Hi,
I tested your cBot and it works fine on multiple symbols, regarding the method for moving stop loss you can use:
@amusleh