Thank you.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy to include manual action at start
Collapse
X
-
Strategy to include manual action at start
I am trying to adapt my automatic strategy to include a manual action when starting the strategy to open a long or short position and from that point the automatic trading in the startegy must take over. I have been looking at the different synchronize possibilities, but that does not give me the wanted result. Among the problems I encountered are the fact that my automatic trading is with CalculateOnBarClose = true and the fact that I limit the buy or sell signal to a single event with a crossover signal. But I need to keep both these conditions for my strategy to work as required. Any help will be much appreciated. I have attached an example of the autotrading part.
Thank you.Tags: None
-
Hello Sylvestro,
You can add a button in your strategy which you can further custom code for any manual control. Please refer to this code which demonstrates how to add custom buttons in your strategy http://ninjatrader.com/support/forum...atid=5&lpage=1JoydeepNinjaTrader Customer Service
Comment
-
One problem I am thinking of integrating the buttons in my strategy is that my strategy works with CalculateOnBarClose = true. Since I want an immediate reaction pushing the button, how could I solve this?
Is making 2 separate strategies a solution? Is it then sufficient to use the same iOrder names in both strategies?
Comment
-
If I put CalculateOnBarClose = true in the button program it does not react immediatelly, because the action is started under OnBarUpdate. I did the EnterLong as shown below.
protectedoverridevoid OnBarUpdate()
{
.............
///
/// Now Make Your Make Your Entry Here
//
if (btnManual.Text != "LONG"
&& (Low[0] < Low[1] || High[0] > High[1]))
{
EnterLong();
}
Comment
-
JoydeepNinjaTrader Customer Service
Comment
-
I have integrated the buttons and all seem to work except for one "little?" problem.
I am using the iOrder like this:
Initialisation:
private IOrder fOrderLong = null;
private IOrder fStopLong = null;
private IOrder fOrderShort = null;
private IOrder fStopShort = null;
OnBarUpdate:
if (btnManual.Text != "LONG" && (Low[0] < Low[1] || High[0] > High[1]) && fOrderLong == null)
fOrderLong = EnterLong(futurecontracts,"fOrderLong");
if (btnEntry.Text != "SHORT" && (Low[0] < Low[1] || High[0] > High[1]) && fOrderShort == null)
fOrderShort = EnterShort(futurecontracts, "fOrderShort");
Communicating this with IB, for an enter long for example, it first closes an existing short position and then opens the long position. This is OK for my strategy (but I would prefer to handle the closing myself).
Starting a strategy I understand that the last position is calculated and allowing here only an opposite entry. Which is OK for the automatic trading part, but a problem with the manual buttons. Because I can only start with the button that trades against the last position. With a flat position I want to be able to start both a long or short trade with the buttons.
Hope this is clear enough. Thanks for helping.
Comment
-
I will try it, but as far as I used it before and using CalculateOnBarClose = true it delays opening a trade one bar, which is what I do not want.
Using the button example I now have an error message where I hope you can help. It gives the same error in the original when trying a back test:
Failed to call method 'Initialize' for strategy '_aaa_entry_at_good_price/eced24f3aa3045f2aec4546a7f8e5798': Object reference not set to an instance of an object.
Thanks for helping...
The error seems to exist in the initialize() part, but I can't see what it is.
I have also tested with Position.MarketPosition == MarketPosition.Flat, but as expected, the buy and sell signals are delayed with an extra bar, reducing the profit to 3 times less.
Is there no "simple?" way to say within the same OnBarUpdate(): close an existing position, wait for a confirmation that it is closed and then open the new position?
Comment
-
Hello Sylvestro,
Can you send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com
Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.
I look forward to assisting you further.
*The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.JoydeepNinjaTrader Customer Service
Comment
-
I have tried many different things now and still not getting what I want to do.
Clearly an automatic strategy that is started and not touched works fine.
But what I want to have and I assume many others with me is a strategy that I can interfere with for opening or closing a position manually while the automated strategy takes over after the manual action. I am not a specialist programmer, but ususally I manage to create what I want to do. But now I am lost...
I will keep trying and if I end up with something working I will post it here.
Is there somewhere a real working example of what I am looking for that can help me?
Thanks for helping...
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
573 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment