PDA

View Full Version : Strategy Debugging, Entry Time, Max losers, profit target check



eaqeujuuni
06-18-2016,
I am trying to verify my strategy is executing all requests. It is also not following my set trading time, it is trading all hours. Can someone please verify the below code looks correct. It is running and generating results, just not running at set time periods. I want to check that the MaxConsecLoser and profit targets are working correctly. I know you use a print command but I'm a little unsure on how to code it & interpret results. Thanks

protected override void OnBarUpdate()
{
if ((ToTime(Time[0]) >= ToTime(8, 30, 0))||(ToTime(Time[0]) < ToTime(14, 45, 0))
&& (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit >= PrftGoal)
&& (Position.MarketPosition != MarketPosition.Flat)
&& (Performance.AllTrades.TradesPerformance.MaxConsec Loser < MaxLosers)
)
{
priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit - priorTradesCumProfit;
}
// At the start of a new session
if (Bars.FirstBarOfSession)
{
// Store the strategy's prior cumulated realized profit and number of trades
priorTradesCount = Performance.AllTrades.Count;
priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit;

egikuhuyui
06-18-2016,
Hello TOOLMachine462,

While I have not yet tested your code, I noticed your first condition block contains ambiguous logic. Where you have

ejleropuk
06-19-2016,
Please let us know if the above does not end up doing what you would like, or if you have any other questions we can help with.

emullujogic
06-21-2016,
Your time filter:
Code:
(ToTime(Time[0]) >= ToTime(8, 30, 0))||(ToTime(Time[0]) < ToTime(14, 45, 0))
is always true. It looks like you are looking for "&&" not "||" as your logic operator?

eleitojafu
06-21-2016,
Thanks for the catch.

However, I think we're both wrong. If the OP just uses && instead of ||, their condition will do the exact opposite of what I think this user wants, as it will only exit out of their strategy between 8:30 and 14:15, and NOT before or after hours.

So that block should be

! (ToTime(Time[0]) >= ToTime(8, 30, 0)) && (ToTime(Time[0]) < ToTime(14, 45, 0))

In short I think this needs to be a NAND