Topics
Replies
firemyst
10 Aug 2023, 00:31
-Catch the creation of the new brick
When the “OnBar” event happens.
Or write your own in the “OnTick” method:
_currentIndex = Bars.OpenTimes.GetIndexByTime(Bars.OpenTimes.LastValue);
if (_currentIndex != _previousIndex)
{
//Call your own OnBar method
OnBarForBot();
_previousIndex = _currentIndex;
}
-Get the color of the last brick
Do you mean actual color? Or is what you really want to know whether the bar closed up or down?
I'll assume the latter since most bots/indicators don't care about actual colors - just check if the previous close price is > or < the previous open price.
if (Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1))
///bullish bar
else
///bearish bar
@firemyst
firemyst
08 Aug 2023, 06:19
RE: RE: placelimitorder success
luca.tocchi said:
firemyst said:
What do you mean by “activated”? DO you mean when the order is actually executed? If so, just check the trade result:
TradeResult r = PlaceStopOrder(TradeType.Buy, SymbolName, volumeInUnits, Symbol.Bid + 15);
if (r.IsSuccessful) {
////
}
I mean when the pending order turns into position.
Then do what I suggested. If the trade result is successful, you know you have a position.
@firemyst
firemyst
07 Aug 2023, 23:58
If there's losing trades, you may want to consider leaving it as it is so you have to manually restart it. This does two things:
- makes sure your account doesn't blow up if it keeps continuously losing more than 3 trades
- gives you a chance to review the trades and what's happening.
If you really want it to start again the next day, you can try this:
- reset the losing count to 0
- keep track of the time. When your new day starts, allow the bot to proceed again. Something like this:
if (!allowTrades && Server.Time > 9am)
{
allowTrades = true;
}
In your OnTick method:
if (allowTrades)
{
////rest of method
}
else
return;
and you'd have to update your code:
if (losercount == 3)
{
allowTrades = false;
Stop();
}
@firemyst
firemyst
07 Aug 2023, 00:13
You might get your wish if you post in the correct forum:
https://ctrader.com/forum/suggestions
@firemyst
firemyst
11 Aug 2023, 00:31
I don't think you can check for that directly, however, what you can try is:
@firemyst