PDA

View Full Version : Need some help


mateo321
05-25-2008, 03:01 PM
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

Matt

NinjaTrader_Ray
05-25-2008, 05:53 PM
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.

mateo321
05-25-2008, 10:28 PM
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

mateo321
05-26-2008, 08:50 AM
Where exactly in the user guide I can find this info ? Also, sample crossover strategy is always in the market so how can it be of help here ? I'm wondering if I can fix my strategy using just wizard or some hardcoding will be nessesery here ?

NinjaTrader_Ray
05-26-2008, 08:55 AM
See post #2, I provide you an approach which you can use to filter out taking subsequent triggers. Ultimately this is a logic question.

mateo321
05-26-2008, 09:31 AM
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;
}
}

NinjaTrader_Ray
05-26-2008, 10:06 AM
You will have to try different things until you figure out how to get it to do what you want. I know this can be frustratinig but its part of programming/logic design.

mateo321
05-26-2008, 10:15 AM
I understand, just please tell me strategy wizard is sufficient tool for solving this problem or it requires hardcoding, playing with loops and nested conditions. Thanks

Matt

NinjaTrader_Ray
05-26-2008, 10:20 AM
Personally, I would manually program it.

mateo321
06-04-2008, 11:44 AM
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

NinjaTrader_Dierk
06-04-2008, 11:53 AM
Please make sure you are on latest 6.5.1000.3. Then delete this strategy and create it again. Please let us know if issue persists.

mateo321
06-04-2008, 12:12 PM
I'm running 6.5.0.4 version

NinjaTrader_Dierk
06-04-2008, 12:14 PM
Wow...this is outdated since months. Please update to 6.5.1000.3 (see download page in web site) and proceed as per below.

mateo321
06-05-2008, 12:09 AM
I downloaded newest version and I'm still getting the same kind of error :confused:. Can you please take a look at code and tell me where the mistake is ??

NinjaTrader_Dierk
06-05-2008, 12:11 AM
a) What do you see in Help->About?
b) Please delete your strategy and create it again.

mateo321
06-05-2008, 12:18 AM
I've already did that. It's still the same error :mad:.

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

NinjaTrader_Dierk
06-05-2008, 12:20 AM
There is a bug in the PSAR strategy implementation. Please remove this strategy or contact the author for a fix. Thanks

mateo321
06-05-2008, 12:43 AM
I'm the author and I don't know where the bug is. Where is a mistake in such statement ?

// Condition set 1
if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid()
&& Performance.AllTrades.Performance.Points.CumProfit < Variable0)


:confused::confused::confused:

NinjaTrader_Dierk
06-05-2008, 12:48 AM
NS editor intellisense and the docs will tell you that it should read:
Performance.AllTrades.TradesPerformance.Points.Cum Profit

mateo321
06-08-2008, 09:51 PM
I don't understand, what exactly you suggest I should do ? CS0117 error appears when I'm trying to use a method or access an exposed property that does not exist for your particular object.

NinjaTrader_Josh
06-08-2008, 10:41 PM
Not sure what the confusion is. You should have TradesPerformance and not Performance for your code is what Dierk is suggesting.

mateo321
06-09-2008, 08:34 AM
That's exactly waht I have, it doesn't changeanything

NinjaTrader_Dierk
06-09-2008, 08:52 AM
>> Strategy\PSAR.cs 'NinjaTrader.Strategy.TradeCollection' does not contain a definition for 'Performance' CS0117 - click for info 46 42
Please delete the PSAR strategy and try to compile -> should work.

mateo321
06-09-2008, 02:03 PM
publicclass PSAR1 : Strategy - Is this what you want me to remove ??

NinjaTrader_Dierk
06-09-2008, 02:05 PM
Tools->Edit NinjaScript->Strategy->Select PSAR strategy->press Delete button

mateo321
06-10-2008, 02:03 PM
Do you want me to delete the whole strategy and write it from the beginning ? How is this going to help ??

NinjaTrader_Dierk
06-10-2008, 02:04 PM
>> How is this going to help ??
Yes will help. Or edit the strategy and apply changes as per my post #19.

mateo321
06-11-2008, 10:27 AM
I can not delete the strategy. Pop up message says that file is likely referenced by other Ninja Script files and those dpendencies need to be removed first. How do I do this ?

NinjaTrader_Dierk
06-11-2008, 10:29 AM
Then edit the strategy according my post #19.

mateo321
06-11-2008, 11:05 AM
Dierk, I did that - still doesn't work. Here's the code:

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, Variable1);
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()
&& Performance.AllTrades.TradesPerformance.Points.Cum Profit < Variable0)
{
ExitShort("", "");
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (ParabolicSAR(0.02, 0.2, 0.02)[0] > GetCurrentBid()
&& Performance.AllTrades.TradesPerformance.Points.Cum Profit < Variable0)
{
ExitLong("", "");
EnterShort(DefaultQuantity, "");
}

NinjaTrader_Dierk
06-11-2008, 11:56 AM
What compile error do you get where?

mateo321
06-11-2008, 12:04 PM
"Error on generating strategy" It's the same one I've already quoted in my post #16

Matt

NinjaTrader_Dierk
06-11-2008, 12:05 PM
Right. So what compile errors do you get where?

mateo321
06-11-2008, 12:25 PM
Error CS0117 in those two lines:

if (ParabolicSAR(0.02, 0.2, 0.02)[0] < GetCurrentBid()

as well as

if (ParabolicSAR(0.02, 0.2, 0.02)[0] > GetCurrentBid()

Message says: NinjaTrader.Strategy.TradeCollection' does not contain definition for Performance

NinjaTrader_Dierk
06-11-2008, 12:27 PM
These lines definitely will no throw these errors below. Double click on the error message to get to the erroneous line and fix the coding bugs there.

mateo321
06-11-2008, 12:44 PM
Sorry, those were not correct lines. After double clicking on error message word Performance gets highlighted in both of those lines (below):

&& Performance.AllTrades.Performance.Points.CumProfit < Variable0)


and this


&& Performance.AllTrades.Performance.Points.CumProfit < Variable0)

NinjaTrader_Dierk
06-11-2008, 12:47 PM
Right, you need to change these lines accordingly my post #19.

mateo321
06-11-2008, 12:59 PM
I did that, clicked compile botton and still the same errors come up :(

NinjaTrader_Dierk
06-11-2008, 01:07 PM
Of course. You need to edit the erroneous lines as per my post #19 before compiling.

mateo321
06-11-2008, 02:15 PM
Thanks Dierk, it works now, however I have two user defined variables in my strategy that need to be optimized. When I right click on product and click backtest I can't see those in the window with wizard settings. Do I have to declare them first somehow ? Thanks

NinjaTrader_Dierk
06-11-2008, 02:18 PM
http://www.ninjatrader-support.com/vb/showthread.php?t=5782

mateo321
06-12-2008, 09:34 AM
One more quick question Dierk. How do I reset value of my user defined imput at the end of the session ? From what I see there is no way to add condition (using wizard) like: if time value = 15:15 then Realized P/L =0.
Thanks for help

NinjaTrader_Dierk
06-12-2008, 09:37 AM
I suggest browsing the available tips and reference samples on this forum first in case you have NinjaScript related questions:
http://www.ninjatrader-support.com/vb/showthread.php?t=3226

mateo321
06-19-2008, 12:25 PM
Dierk, I checked all this stuff but still can't make it work. I'm trying to reset (at 3:14pm) a variable (pL) that calculates realized P/L so I added condition:
// Condition set 3
if (ToTime(Time[0]) >= 151400
set { pL = 0 }

which I guess is correct, however an error comes up few lines below:

#region Properties
[Description("")]
{[Category("Parameters")] - message says }expected
publicint TG

How do I correct it ?

NinjaTrader_Dierk
06-19-2008, 12:30 PM
Not sure what wanted to do but your code snippet below is not C#. I suggest reading a book on C# to understand the basic syntax concept (e.g. check on Amazon or free web ressources).

Unfortunately we can't provide support down to the level of C# coding basics. However here is a hint; your code below probably should read like
if (ToTime(Time[0]) >= 151400)
pL = 0;

mateo321
06-22-2008, 11:15 AM
Sorry Dierk, that was the wrong line. This one seems to be fine however the one below is not:

#region Properties
[Description("")]
{[Category("Parameters")]} - message says } expected
publicint TG
{
get { return tG; }
set { tG = Math.Max(1, value); }
}

This is weird because that part of code is generated by wizard, I didn't mess with it

Also, one more question. When creating strategy with a wizard is it possible to have orders generated intrabar however value of PSAR calculated on bar close ?

Thanks

NinjaTrader_Josh
06-22-2008, 01:05 PM
When it comes to brackets being missing it will most likely not find the correct location because all your brackets are offset. You will simply need to go back by hand and go through your code and match up every bracket with its counterpart. I am sure you will find one missing. Perhaps in the OnBarUpdate() method.

Multi-time frame strategy is currently not available through the Strategy Wizard.

mateo321
06-27-2008, 10:28 AM
I checked all the brackets but everything seems to be in order, yet it still shows an error in the line I marked below. Can you please look at my code once again ? Thanks




#region Properties
[Description("")]
{[Category("Parameters")]} - error message says } expected

publicint TG
{
get { return tG; }
set { tG = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
publicint PL
{
get { return pL; }
set { pL = Math.Max(1, value); }
}
#endregion
}
}

NinjaTrader_Dierk
06-27-2008, 11:44 AM
Unfortunately we can't provide support down to the level of plain C# programming.

However here is a hint: Remove the '{', '}' here
{[Category("Parameters")]}