Hello there. I just tried to buil a simple trailing sl cBot from your snippets shown in the following file:
https://drive.google.com/file/d/11H9eCh7llTgaA2qm2ZdF-TV5iSeWdRTV/view?usp=sharing
from this page:
https://clickalgo.com/code-a-trailing-stop
but there i get error notification can you help me maybe ?!?
this is the code copy:
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 my_tsl : Robot
{
[Parameter("Include Trailing Stop", DefaultValue = false)]
public bool IncludeTrailingStop { get; set; }
[Parameter("Trailing Stop Trigger (pips)", DefaultValue = 20)]
public int TrailingStopTrigger { get; set; }
[Parameter("Trailing Stop Step (pips)", DefaultValue = 10)]
public int TrailingStopStep { get; set; }
protected override void OnStart()
{
// Put your initialization logic here
}
protected override void OnTick()
{
if (IncludeTrailingStop)
{
SetTrailingStop();
}
// Put your core logic here
}
private void SetTrailingStop()
{
var sellPositions = Positions.FindAll(botName, Symbol, TradeType.Sell);
foreach (Position position in sellPositions)
{
double distance = position.EntryPrice - Symbol.Ask;
if (distance < TrailingStopTrigger * Symbol.PipSize)
continue;
double newStopLossPrice = Symbol.Ask + TrailingStopStep * Symbol.PipSize;
if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
{
ModifyPosition(position, newStopLossPrice, position.TakeProfit);
}
}
var buyPositions = Positions.FindAll(botName, Symbol, TradeType.Buy);
foreach (Position position in buyPositions)
{
double distance = Symbol.Bid - position.EntryPrice;
if (distance < TrailingStopTrigger * Symbol.PipSize)
continue;
double newStopLossPrice = Symbol.Bid - TrailingStopStep * Symbol.PipSize;
if (position.StopLoss == null || newStopLossPrice > position.StopLoss)
{
ModifyPosition(position, newStopLossPrice, position.TakeProfit);
}
}
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
the error description:
1)Severity Code Description Project File Line Suppression State
Error CS0103 The name 'botName' does not exist in the current context my TSL C:\Users\EX-Al\Documents\cAlgo\Sources\Robots\my TSL\my TSL\my TSL.cs 39 Active
2)Severity Code Description Project File Line Suppression State
Error CS0103 The name 'botName' does not exist in the current context my TSL C:\Users\EX-Al\Documents\cAlgo\Sources\Robots\my TSL\my TSL\my TSL.cs 56 Active
thank you.