[COLOR=red]if (Order == true)[/COLOR]
{
if (Input[0] > MonitorPrice + 1);
{
MonitorPrice = Input[0] - 1;
Print("Long Support @ " + MonitorPrice);
}
if (Input[0] <= MonitorPrice || (Input[0] - EntryPrice) >= (double)((Input[0] - PeakValue) * .5))
{
ExitLong();
Order = null;
if (Input[0] < PeakValue)
{
PeakValue = Input[0];
Print("Peak = " + Input[0]);
}
}
}
[COLOR=red]if (Order == false)[/COLOR]
{
if (Input[0] < MonitorPrice - 1);
{
MonitorPrice = Input[0] + 1;
Print("Short Support @ "+MonitorPrice);
}
if (Input[0] > MonitorPrice || (EntryPrice - Input[0]) >= (double)((Input[0] - PeakValue) * .5))
{
ExitShort();
Order = null;
if (Input[0] > PeakValue)
{
PeakValue = Input[0];
Print("Peak = " + Input[0]);
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Stop trace failing
Collapse
X
-
Stop trace failing
This is a snippet from my script that sets a reference as a stop on orders. It works fine on following the price when it should... but it also follows it the other way! I have stared at this code for hours now... and I just can't see it! Notice the code in red, "Order = true" indicates a long, while "Order = false" indicates a short... null indicates no order.
Code:Tags: None
-
The Highlighted area moves my stop reference to one point behind the current price. It's counterpart does the same for short orders. When in a long deal the stop follows the price up, but also follows it down. It does the same for a short.
Code:[COLOR=lime]if (Order == true){if (Input[0] > MonitorPrice + 1);[/COLOR] [COLOR=lime]{[/COLOR] [COLOR=lime]MonitorPrice = Input[0] - 1;[/COLOR] Print("Long Support @ " + MonitorPrice); } if (Input[0] <= MonitorPrice || (Input[0] - EntryPrice) >= (double)((Input[0] - PeakValue) * .5)) { ExitLong(); Order = null; if (Input[0] < PeakValue) { PeakValue = Input[0]; Print("Peak = " + Input[0]); } } } if (Order == false) { if (Input[0] < MonitorPrice - 1); { MonitorPrice = Input[0] + 1;Print("Short Support @ "+MonitorPrice); } if (Input[0] > MonitorPrice || (EntryPrice - Input[0]) >= (double)((Input[0] - PeakValue) * .5)){ExitShort(); Order = null; if (Input[0] > PeakValue){PeakValue = Input[0]; Print("Peak = " + Input[0]); } } }Last edited by Sleeping Troll; 03-30-2010, 03:29 PM.
Comment
-
Sorry, but I still can't see the issue here. Do you mean that the 'MonitorPrice' moves both up and down for each direction? If so, you'll have to code in some logic that will only change the variable if it is going in the right direction, just like a trailing stop.AustinNinjaTrader Customer Service
Comment
-
That is correct, it moves in both directions... The Conditional:
"if (Input[0] > MonitorPrice + 1);"
Should only allow this to happen if Input[0] is > Monitor price +1, yet it stays ahead of a falling price just as it trails a rising price!
Only thing I can figure is that the conditionals:
if(Order == true)
and
if(Order == false)
are not being respected.
Which indicate long and short orders (Order is nullable) it does however respect the "null" as there is no output when Order is null.Last edited by Sleeping Troll; 03-30-2010, 03:54 PM.
Comment
-
Sleeping Troll, using code from your script, I whipped up my own version to show how the trailing stop would trail for a long position:
And everything looks like it should. The stop doesn't go down when the price goes down. I suggest you start with a as-simple-as-possible version of what you're trying to do that works correctly and then slowly layer on complexity until you figure out where it breaks.Code:protected override void OnBarUpdate() { if (Historical) return; if (Close[0] > stop + 1) { stop = Close[0] - 1; } Plot0.Set(stop); }AustinNinjaTrader Customer Service
Comment
-
Your code:
if (Close[0] > stop + 1)
{
stop = Close[0] - 1;
My code:
if (Close[0] > MonitorPrice + 1);
{
MonitorPrice = Close[0] - 1;
";" DOH! (slap) thx for letting me bounce that one off of you!
Comment
-
I take all that back, I removed the ";" and I get the same results! Only thing that I can figure is that your compiler is doing something strange with nullables?
Comment
-
#region Variables
private int CanCount;
private double? macd;
private double? macdAvg;
private bool? Order;
private bool? Study;
private double MonitorLong;
private double MonitorShort;
private int HighBar;
private int LowBar;
private double EntryPrice;
private double? Support;
private bool? BollFlag;
private bool? MACDCrossAboveFlag;
private bool? MACDCrossBelowFlag;
private double PeakValue;
#endregion
Do you understand what the "?" means?
Last edited by Sleeping Troll; 03-30-2010, 04:54 PM.
Comment
-
This is not a new question, I have changed my code (Close[0] instead of Input[0]) and the only difference now is the var name and that it is a nullable type... I do not think the name is the problem... so it must be the nullable type.
I have since replaced my bool?'s (true, false, null) with String's ("Long", "Short", "none") and all is well... I guess...
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
657 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
373 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
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment