wrong Symbol.pip value
Created at 05 May 2023, 09:54
wrong Symbol.pip value
05 May 2023, 09:54
when this robot run in euruusd and trade on audusd ,eurusd and gbpusd it works fine but when i trade on usdjpy it works wrong because symbol.pipvalue calcualted just for currency when robot start on it and doesn't update for other currency i couldn't find any solution for this problem
another problem with this code: if trader had many trade it runs too many i don't why because i add condition for each trade
using System;
using System.Linq;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWCPStep : Robot
{
[Parameter("Modify TP ", DefaultValue = true)]
public bool TpOption { get; set; }
[Parameter("Take Profit Percent", DefaultValue = 3.1)]
public double TpPercent { get; set; }
[Parameter("Modify Sl ", DefaultValue = true)]
public bool SlOption { get; set; }
[Parameter("Stop Loss Profit Percent", DefaultValue = 3.1)]
public double SlPercent { get; set; }
protected override void OnStart()
{
Settpsl();
Positions.Modified += PositionsOnModified;
Positions.Opened += PositionsOnOpened;
Positions.Closed += PositionsOnClosed;
PendingOrders.Filled += PendingOrdersOnFilled;
}
protected override void OnTick()
{
}
private void PositionsOnModified(PositionModifiedEventArgs obj)
{
Settpsl();
}
private void PositionsOnOpened(PositionOpenedEventArgs args)
{
Settpsl();
}
private void PositionsOnClosed(PositionClosedEventArgs args)
{
Settpsl();
}
private void PendingOrdersOnFilled(PendingOrderFilledEventArgs args)
{
Settpsl();
}
private void Settpsl()
{
foreach (var position in Positions)
{
double tpcalc = Math.Round(((Account.Balance * (1 + TpPercent / 100)) - Account.Balance) / (Symbol.PipValue * position.VolumeInUnits), 1);
double slcalc = Math.Round((Account.Balance - (Account.Balance * (1 - SlPercent / 100))) / (Symbol.PipValue * position.VolumeInUnits), 1);
if (position.TradeType == TradeType.Buy)
{
var tp = position.EntryPrice + tpcalc * Symbol.PipSize;
var sl = position.EntryPrice - slcalc * Symbol.PipSize;
if (TpOption && position.TakeProfit != tp)
{
ModifyPosition(position, position.StopLoss, tp);
}
if (SlOption && position.StopLoss != sl)
{
ModifyPosition(position, sl, position.TakeProfit);
}
}
if (position.TradeType == TradeType.Sell)
{
var tp = position.EntryPrice - tpcalc * Symbol.PipSize;
var sl = position.EntryPrice + slcalc * Symbol.PipSize;
if (TpOption && position.TakeProfit != tp)
{
ModifyPosition(position, position.StopLoss, tp);
}
if (SlOption && position.StopLoss != sl)
{
ModifyPosition(position, sl, position.TakeProfit);
}
}
}
}
}
}
m4trader4
06 May 2023, 16:41
Same issue has been reported check this thread
@m4trader4