// Long Entry Conditions if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high { EnterLong((int)oneUnit, "LongPosition1"); // Long Exit Conditions SetStopLoss("LongPosition1", CalculationMode.Price, (int)trailingLongStopATR, true); DrawDot(CurrentBar.ToString(), true, 0, trailingLongStopATR, Color.Yellow);
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Draw at Entry Point
Collapse
X
-
Draw at Entry Point
I am trying to draw a dot at my entry point that represents my SetStopLoss immediately. However, it is drawing a dot at every point my entry condition is met. Find the code below. Thank you in advance for the help.
Code:Tags: None
-
Hello cfree5119,
Thanks for writing in and I am happy to assist you.
Please draw the dot from OnOrderUpdate and also make sure you are using an unique tag id like:
Code:protected override void OnOrderUpdate(IOrder order) { if (order.Name == "Stop loss") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow);
Last edited by NinjaTrader_Joydeep; 02-21-2012, 11:15 AM.JoydeepNinjaTrader Customer Service
-
However, the stop price does not reside at the stop price but at 0. See the attached image.
The sample code you gave me and I modified looks like this. I want the dot placed at my stoploss previously coded.
Code:// Long Entry Conditions if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high { EnterLong((int)oneUnit, "LongPosition1"); // Long Exit Conditions SetStopLoss("LongPosition1", CalculationMode.Price, (int)trailingLongStopATR, true); } if (Close[0] <= DonchianChannelATR(ExitPeriod).LowerLine[1]) // Exit Long position if close <= given low { ExitLong(); } } protected override void OnOrderUpdate(IOrder order) { if (order.Name == "LongPosition1") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow); }
Comment
-
Hello cfree5119,
You have set the Calculation mode as Price while have used an integer as the value. Please debug your code using the Print function and see whether the stop price is the value as per your desire http://www.ninjatrader.com/support/h...html?print.htm
For more on debugging please refer here http://www.ninjatrader.com/support/f...d.php?t=3418as
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
I have fixed that mistake yet the code you wrote is still yielding zero. Also, the print function shows my my desired value. Forgive me for my lack of programming experience. I am using the the string "LongPosition1" in the draw code that is both associated with my long entry and StopLoss. I can't think of anything else to try.
Comment
-
Hello cfree5119,
If you set the stop order as simulated then OnOrderUpdate will not be triggered as the order is not real. Set the same to false.
Also the order name will be Stop loss. Please find the below rectified code.
Code:// Long Entry Conditions if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high { EnterLong((int)oneUnit, "LongPosition1"); // Long Exit Conditions SetStopLoss("LongPosition1", CalculationMode.Price, (int)trailingLongStopATR, [B][COLOR="Blue"]false[/COLOR][/B]); } if (Close[0] <= DonchianChannelATR(ExitPeriod).LowerLine[1]) // Exit Long position if close <= given low { ExitLong(); } protected override void OnOrderUpdate(IOrder order) { if (order.Name == "[COLOR="blue"][B]Stop loss[/B][/COLOR]") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow); }
JoydeepNinjaTrader Customer Service
Comment
-
I made the corrections you suggested. Here is the updated code below. I would prefer to have the dot placed upon the long position entering not exiting. Also, see the screenshot to visualize what I am speaking of.
Code:// Long Conditions if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high { EnterLong((int)oneUnit, "LongPosition1"); SetStopLoss("LongPosition1", CalculationMode.Price, trailingLongStopATR, false); } if (Close[0] <= DonchianChannelATR(ExitPeriod).LowerLine[1]) // Exit Long position if close <= given low { ExitLong(); } } protected override void OnOrderUpdate(IOrder order) { if (order.Name == "Stop loss") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow); }
Comment
-
Hello cfree5119,
The dot is drawn when the entry was made. But it is subsequently changed when the stop is getting filled/cancelled upon exit since the tag name is the same.
Add an additional check to make sure the dot is drawn on the entry bar only.
Code:if (order.Name == "Stop loss" && BarsSinceEntry("LongPosition1") == 0) DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow);
JoydeepNinjaTrader Customer Service
Comment
-
I see, easy enough. Let say I wanted to draw a line wherever the dynamically changing stop is. Would it be best to use a plot function for this or draw a line from the entry and exit? The stop will only change upon another entry that scales in. Thanks again for the wonderful help.
Comment
-
Hello cfree5119,
You can use a Plot for the purpose or a line. Both has their own pros and cons and it depends on what exactly you want to do.
To assign plot values from a strategy please refer to this sample code http://ninjatrader.com/support/forum...ead.php?t=6651
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
4 responses
24 views
0 likes
|
Last Post Today, 08:19 AM | ||
Started by Brevo, Today, 01:45 AM
|
1 response
14 views
0 likes
|
Last Post Today, 08:14 AM | ||
Started by rjbtrade1, 11-30-2023, 04:38 PM
|
2 responses
74 views
0 likes
|
Last Post
by DavidHP
Today, 08:12 AM
|
||
Started by suroot, 04-10-2017, 02:18 AM
|
5 responses
3,022 views
0 likes
|
Last Post Today, 08:11 AM | ||
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
7 views
0 likes
|
Last Post Today, 07:37 AM |
Comment