Matt
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Need some help
Collapse
X
-
Need some help
I've tried to write a simple strategy (using wizard) that takes positions based on signals given by PSAR indicator and encountered one problem. I have mechanical target for each trade (fixe amount of ticks) and I wanted to limit number of signals per direction to just one, however after closing the first trade strategy immediately reenters position in the same direction and does it as long as the condition (PSAR > Last Price) is true. I don't want to have another position opened until PSAR changes from Buy to Sell or vice versa. Is there a simple way to fix this ? Thanks for help
MattTags: None
-
You will have to get a little clever with setting user defined variables under the action section. Once you go long, set some value, then check if this value is set when the condition to go long is true, if it is set to some value (maybe 1) ignore the entry condition, when psar goes short, reset this value.
Something like that.RayNinjaTrader Customer Service
-
Where is the loop ?
How do I make it stop checking if the condition is still true on the next bar (after closing the first trade) when there's no loop in the code generated by wizard. I'd have to exit that loop but such doesn't exist. Below is the code created by wizard:
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
///<summary>
/// Enter the description of your strategy here
///</summary>
[Description("Enter the description of your strategy here")]
publicclass PSAR : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
///<summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
///</summary>
protectedoverridevoid Initialize()
{
SetProfitTarget("", CalculationMode.Ticks, 4);
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid())
{
ExitShort("", "");
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (ParabolicSAR(0.02, 0.2, 0.02)[0] >= GetCurrentBid())
{
ExitLong("", "");
EnterShort(DefaultQuantity, "");
}
}
#region Properties
#endregion
Comment
-
Doesn't work
I tried to do it this way but it doesn't work:
namespace NinjaTrader.Strategy
{
///<summary>
/// Enter the description of your strategy here
///</summary>
[Description("Enter the description of your strategy here")]
publicclass PSAR1 : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
///<summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
///</summary>
protectedoverridevoid Initialize()
{
Add(ParabolicSAR(0.02, 0.2, 0.02));
SetProfitTarget("", CalculationMode.Ticks, 5);
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid()
&& Variable0 == 0)
{
ExitShort("", "");
EnterLong(DefaultQuantity, "");
Variable0 = 1;
}
// Condition set 2
if (ParabolicSAR(0.02, 0.2, 0.02)[0] >= GetCurrentBid())
{
Variable0 = 0;
}
// Condition set 3
if (ParabolicSAR(0.02, 0.2, 0.02)[0] >= GetCurrentBid()
&& Variable0 == 0)
{
ExitLong("", "");
EnterShort(DefaultQuantity, "");
Variable0 = 1;
}
// Condition set 4
if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid())
{
Variable0 = 0;
}
}
Comment
-
Realized P/L
How do I reference reailzed P/L from current trading session (as specyfied in the wizard) ?? Expression created by wizard seems to have some bug:
// Condition set 1
if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid()
&& Performance.AllTrades.Performance.Points.CumProfit < Variable0)
Message I get says:
Strategy\PSAR.cs 'NinjaTrader.Strategy.TradeCollection' does not contain a definition for 'Performance' CS0117 - click for info 46 42
What do I do with this ??
Thanks
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Conall, Today, 12:06 AM
|
0 responses
3 views
0 likes
|
Last Post
by Conall
Today, 12:06 AM
|
||
Started by proptradingshop, 03-21-2024, 09:50 AM
|
6 responses
27 views
0 likes
|
Last Post Today, 12:02 AM | ||
Started by mly916, Yesterday, 09:48 PM
|
1 response
11 views
0 likes
|
Last Post Yesterday, 11:54 PM | ||
Started by Mikey_, Yesterday, 09:21 PM
|
0 responses
11 views
0 likes
|
Last Post
by Mikey_
Yesterday, 09:21 PM
|
||
Started by cre8able, Yesterday, 05:53 PM
|
3 responses
14 views
0 likes
|
Last Post
by cre8able
Yesterday, 09:20 PM
|
Comment