Daily Limit on loss and Win
Daily Limit on loss and Win
06 Aug 2024, 15:33
How can I implement an algo that will limit daily trading to loss and profit? Thanks for your help
Replies
firemyst
11 Aug 2024, 11:43
( Updated at: 11 Aug 2024, 15:29 )
There is a way to do it, but you have to code it into your bots. Here's an example:
//Get historical trade
Position p1 = args.Position;
//Running Totals
_runningTotalsPipsGainedLost += p1.Pips;
_runningTotalsNetGainLoss += p1.NetProfit
//Stop the bot if the running net gain/loss pips falls below our specified amount
if (_runningTotalsPipsGainedLost < StopBotWhenPipLossesFallBelow)
{
//stop bot
Stop();
}
//Stop the bot if the running net gain/loss total falls below our specified amount
if (_runningTotalsNetGainLoss < StopBotWhenLossesFallBelow)
{
//stop bot
Stop();
}
Note that this only works on each individual bot instance for each bot.
If you want the running totals to be across all instances of a particular bot, then you need to set static variables that are public that all bot code would have access to.
Have your bots check that value every time they start, and before entering any positions. If that global static amount is below a certain threshold, either stop your bot, or don't allow it to enter a new position.
@firemyst
PanagiotisCharalampous
12 Aug 2024, 05:15
RE: Daily Limit on loss and Win
firemyst said:
There is a way to do it, but you have to code it into your bots. Here's an example:
//Get historical tradePosition p1 = args.Position;//Running Totals_runningTotalsPipsGainedLost += p1.Pips;_runningTotalsNetGainLoss += p1.NetProfit//Stop the bot if the running net gain/loss pips falls below our specified amountif (_runningTotalsPipsGainedLost < StopBotWhenPipLossesFallBelow){ //stop bot Stop();}//Stop the bot if the running net gain/loss total falls below our specified amountif (_runningTotalsNetGainLoss < StopBotWhenLossesFallBelow){ //stop bot Stop();}
Note that this only works on each individual bot instance for each bot.
If you want the running totals to be across all instances of a particular bot, then you need to set static variables that are public that all bot code would have access to.
Have your bots check that value every time they start, and before entering any positions. If that global static amount is below a certain threshold, either stop your bot, or don't allow it to enter a new position.
I assume that the trader wants to block trading for the entire account.
@PanagiotisCharalampous
firemyst
12 Aug 2024, 05:34
RE: RE: Daily Limit on loss and Win
PanagiotisCharalampous said:
firemyst said:
There is a way to do it, but you have to code it into your bots. Here's an example:
//Get historical tradePosition p1 = args.Position;//Running Totals_runningTotalsPipsGainedLost += p1.Pips;_runningTotalsNetGainLoss += p1.NetProfit//Stop the bot if the running net gain/loss pips falls below our specified amountif (_runningTotalsPipsGainedLost < StopBotWhenPipLossesFallBelow){ //stop bot Stop();}//Stop the bot if the running net gain/loss total falls below our specified amountif (_runningTotalsNetGainLoss < StopBotWhenLossesFallBelow){ //stop bot Stop();}
Note that this only works on each individual bot instance for each bot.
If you want the running totals to be across all instances of a particular bot, then you need to set static variables that are public that all bot code would have access to.
Have your bots check that value every time they start, and before entering any positions. If that global static amount is below a certain threshold, either stop your bot, or don't allow it to enter a new position.
I assume that the trader wants to block trading for the entire account.
They don't make that clear, but their initial post does say “limit” as opposed to “block”.
@firemyst
stevenrm
12 Aug 2024, 07:06
( Updated at: 12 Aug 2024, 08:47 )
RE: Daily Limit on loss and Win
firemyst said:
There is a way to do it, but you have to code it into your bots. Here's an example:
//Get historical tradePosition p1 = args.Position;//Running Totals_runningTotalsPipsGainedLost += p1.Pips;_runningTotalsNetGainLoss += p1.NetProfit//Stop the bot if the running net gain/loss pips falls below our specified amountif (_runningTotalsPipsGainedLost < StopBotWhenPipLossesFallBelow){ //stop bot Stop();}//Stop the bot if the running net gain/loss total falls below our specified amountif (_runningTotalsNetGainLoss < StopBotWhenLossesFallBelow){ //stop bot Stop();}
Note that this only works on each individual bot instance for each bot.
If you want the running totals to be across all instances of a particular bot, then you need to set static variables that are public that all bot code would have access to.
Have your bots check that value every time they start, and before entering any positions. If that global static amount is below a certain threshold, either stop your bot, or don't allow it to enter a new position.
Hello, thank you for your assistance. I will test it with my bot and provide feedback. It's exactly what I need: preventing my bot from opening a new position if it surpasses a certain threshold.
@stevenrm
PanagiotisCharalampous
07 Aug 2024, 05:32
Hi there,
It is not possible to implement this. cBots cannot block an account from trading.
Best regards,
Panagiotis
@PanagiotisCharalampous