Good day... I recently started learning cAlgo and I am trying to build my first bot. The bot should always try to enter positions for as long as there is no exposed position. Only enter if the stoploss is above entry price for a buy and vice versa for a sell throughout all symbols
I wrote two functions to combine because I failed at my first attempt. Any corrections would be a great deal of help.
private bool areBuysSafe() {
var isSafe = true;
if (Positions.Count > 0) {
foreach(var position in Positions) {
if (position.TradeType == TradeType.Buy && position.StopLoss < position.EntryPrice) {
break;
isSafe = false;
}
}
}
return isSafe;
}
private bool areSellsSafe() {
var isSafe = true;
if (Positions.Count > 0) {
foreach(var position in Positions) {
if (position.TradeType == TradeType.Sell && position.StopLoss > position.EntryPrice) {
break;
isSafe = false;
}
}
}
return isSafe;
}
if (AreBuysSafe() && AreSellsSafe()) {
//enter position
}