bool flowCondition = flowStats.Score[0] > avgFlowstats.UpperbandScore[0];
// SELL
if ( flowCondition && !upcandleCondition)
{
Print("$SELL signal ");
Print(flowStats.Score[0] + " score > " + avgFlowstats.LowerbandScore[0]);
Print(Volume[0] + " VOl > " + avgFlowstats.UpperbandVolume[0]);
Print(flowStats.NumTrades[0] + " # > " + avgFlowstats.UpperbandNumTrades[0]);
string entryName = "";
if (Position.MarketPosition != MarketPosition.Long)
{
entryName = "short" + (Position.Quantity + 1).ToString();
PrintA("issuing " + entryName);
IOrder order = EnterShort(DefaultQuantity, entryName);
if (order != null)
{
Print("SELL:" + order.ToString());
ht.Add(entryName, DefaultQuantity);
}
else
Print(Time[0].ToString() + "--EnterShort: NULL Order");
Print("setting stop and target for " + entryName);
SetStopLoss(entryName, CalculationMode.Percent, 0.45, false);
SetProfitTarget(entryName, CalculationMode.Percent, 0.70);
}
else // long
{
entryName = "long" + Position.Quantity.ToString();
if (ht.ContainsKey(entryName))
{
PrintA("issuing " + "exit-" + entryName);
IOrder order = ExitLong(DefaultQuantity, "exit-" + entryName, entryName);
if (order != null)
{
//PrintA(order.ToString());
ht.Add("exit-" + entryName, DefaultQuantity);
}
else
PrintA(Time[0].ToString() + "--ExitLong: NULL Order");
}
else
Print(entryName + " doesn't exist");
}
}
flowCondition = flowStats.Score[0] < avgFlowstats.LowerbandScore[0];
// BUY
if ( flowCondition && upcandleCondition)
{
Print("$BUY signal ");
Print(flowStats.Score[0] + " score < " + avgFlowstats.LowerbandScore[0]);
Print(Volume[0] + " VOl > " + avgFlowstats.UpperbandVolume[0]);
Print(flowStats.NumTrades[0] + " # > " + avgFlowstats.UpperbandNumTrades[0]);
string entryName = "";
if (Position.MarketPosition != MarketPosition.Short)
{
entryName = "long" + (Position.Quantity + 1).ToString();
Print("issuing " + entryName);
IOrder order = EnterLong(DefaultQuantity, entryName);
if (order != null)
{
Print("BUY:" + order.ToString());
ht.Add(entryName, DefaultQuantity);
}
else
Print(Time[0].ToString() + "--EnterLong: NULL Order");
Print("setting stop and target for " + entryName);
SetStopLoss(entryName, CalculationMode.Percent, 0.45, false);
SetProfitTarget(entryName, CalculationMode.Percent, 0.70);
}
else // short
{
entryName = "short" + Position.Quantity.ToString();
if (ht.ContainsKey(entryName))
{
PrintA("issuing " + "exit-" + entryName);
IOrder order = ExitShort(DefaultQuantity, "exit-" + entryName, entryName);
if (order != null)
{
Print("Adding exit-" + entryName);
ht.Add("exit-" + entryName, DefaultQuantity);
}
else
PrintA(Time[0].ToString() + "--ExitShort: NULL Order");
}
else
Print(entryName + " doesn't exist");
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SetStopLoss/SetProfitTarget
Collapse
X
-
SetStopLoss/SetProfitTarget
I am using these 2 calls in the code below, where I take a position using an explicit name in the appropriate overload of EnterLong and on occasions exit that position using the corresponding overload of Exitlong. Somehow the Stop and ProfitTaget calls are not activating. For example, for the below code, my stop is 045% and profit is 0.70%. This is yielding traces that have a PnL > 2% and in MFE > ProfitTarget and MAE > StopLoss, that should not happen right?
Code:Tags: None
-
I am looking for 0.45% stop loss and 0.7% profit target.
Please sen me an example of how exactly I can specify the various calculation modes, the help section and documentation is insufficient. I appreciate your effort.Last edited by newworldguy; 05-29-2014, 03:55 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
67 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
36 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
59 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
62 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
53 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment