if ((Times[0][0].TimeOfDay == new TimeSpan(6, 00, 0))
|| (Times[0][0].TimeOfDay == new TimeSpan(10, 00, 0)))
{
TradeSwitch = false;
}
// Set 1
if ((Times[0][0].TimeOfDay >= new TimeSpan(6, 30, 0))
&& (Times[0][0].TimeOfDay < new TimeSpan(12, 45, 0))
&& (OBV1[0] > OBV1[1])
&& (Closes[0][0] > ATRTrailingStop1[1])
&& Position.MarketPosition == MarketPosition.Flat
&& BarsInProgress == 0
&& IsFirstTickOfBar == true
&& TradeSwitch == false)
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
TradeSwitch = true;
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Trade switch
Collapse
X
-
Trade switch
I only want to enter trades twice a day max. I found some information on the forum about making a bool trade switch, and incorporated that into my strategy. This morning I entered a trade manually because I was not able to log in until after my start time. Once the trade I entered manually was exited, the automated strategy immediately entered a new trade. I want to make sure the switch functions correctly, and also that I don't have to have the strategy enabled prior to the switch for it to work. I wondered if maybe since I wasn't running my charts in tick replay to save on processing that threw it off. The strategy bactests as expected, but I've been backtesting with tick replay. If someone would take a look at this snippet of code and let me know if they see any glaring errors, I'd appreciate it. Thanks.
Code:Tags: None
-
Hello zrobfrank,
Thank you for your post.
I suggest adding prints to better understand the behavior. Adding a print every time the TradeSwitch bool is changed to true or false could be especially helpful to gain a deeper understanding of your script. What I am seeing is if the time is between 6-10 then TradeSwitch is set to false. This means that even if a trade occurs between 6:30 and 10 from your other condition that would set TradeSwitch to true, the other condition between 6-10 would set it right back to false so that if the other condition became true again it would execute a trade.
Additionally, I don't think tick replay had any effect on the behavior, and tick replay is only really beneficial if you need intrabar data/actions in historical processing. For more information about tick replay:
What you may want to consider is what happened with the manual entry/exit and how that affected your account position vs. your strategy position and the behavior of your strategy based on the start behavior selected. For more details, please see the following pages:
Please let us know if we may be of further assistance.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
58 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
133 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment