NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 03-06-2012, 11:10 AM   #1
johnlucas
Member
 
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
Default Variable0 = SMA

Hi everyone,

When a set of conditions is true (already programmed) I would like to set a Variable0 equal to the value of a moving average and then use that value as profit target.

Is it possible to do that with the Strategy Wizard?

So far, I have set:

Variable0 = SMA in Set1

and then, in the Profit Target & Stoploss section:

Profit Target Mode = price
Value = Variable0

but it doesn't work,

thank you for your help,

John.
johnlucas is offline  
Reply With Quote
Old 03-06-2012, 11:23 AM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello John,
Thanks for writing in and I am happy to assist you.

You can set the value of the Variable0 to the SMA value but you cannot set it to SetStopLoss as it is defined in the Initialize region of the strategy.

You have to unlock the code and do it via the NinjaScript editor.

Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 03-06-2012, 11:55 AM   #3
johnlucas
Member
 
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
Default

Thank you for your reply,

at the moment I have in the Condition Set 1:

Variable0 = SMA(800)[0]; this is ok, if I have understood.

While in the Initialize () section I have:

SetProfitTarget("", CalculationMode.Ticks, Variable0); How this line should be modified to make sure that the profit target is equal to the SMA?

thank you,

John.
johnlucas is offline  
Reply With Quote
Old 03-06-2012, 01:11 PM   #4
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello John,
SetProfitTarget and the SetStopLoss are put in the initialize region of the code. At that time the value of Variable0 is 0 (zero). When the orders are placed then you have to reassign the Set() methods with the updated price. Unfortunately you cannot do that via the Strategy Wized.
You have to unlock the code and code it via the NinjaScript editor.
You can modify your code after placing the entry order as:
Code:
Variable0 = SMA(800);
SetProfitTarget("", CalculationMode.Price, Variable0);
The above will put an appropriate profit target.

Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 03-08-2012, 07:48 AM   #5
johnlucas
Member
 
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
Default

Hi,

thank you for your reply,

I have put the following code:

Variable0 = SMA(800);
SetProfitTarget("", CalculationMode.Price, Variable0);

in the conditions sets (I have 4 conditions sets, so I put it in each of them). When I run the simulation what happens is that the positions are immediately closed after being opened.
So the profit target is not appropriately set.

What could be missed?

thank you,

John.
johnlucas is offline  
Reply With Quote
Old 03-08-2012, 08:18 AM   #6
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello John,
Variable0 is a double while SMA(800) is a data series. You need to write the code as
Code:
Variable0 = SMA(800)[0];
Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 03-08-2012, 08:32 AM   #7
johnlucas
Member
 
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
Default

Hi Joydeep,

here is the code I have inserted in the condition set:

{
EnterLong(DefaultQuantity, "Trend LE");
Variable0 = SMA(800)[0];
SetProfitTarget("", CalculationMode.Price, Variable0);
}

but still no success,

what could be missing?

thank you,

John.
johnlucas is offline  
Reply With Quote
Old 03-08-2012, 09:10 AM   #8
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello John,
Your fromEntrySignal name varaiable is not set accordingly in the Set() method.

Please use this code
Code:
EnterLong(DefaultQuantity, "Trend LE"); 
Variable0 = SMA(80)[0]; 
SetProfitTarget("Trend LE", CalculationMode.Price, Variable0);
Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable0 Not working as a stop daven Automated Trading 2 12-02-2011 02:14 PM
indicator to plot the 50 period sma of the 5 sma brdnickel NinjaScript File Sharing Discussion 6 01-26-2011 01:03 PM
SMA Value fury661 Strategy Development 6 09-04-2010 02:12 PM
Using Variable0 as a stop loss value. daven Strategy Development 3 07-22-2010 02:13 PM
Draw a x minute SMA/SMA/WMA on another timeframe? ninjamouse Indicator Development 4 04-06-2009 06:54 AM


All times are GMT -6. The time now is 03:41 PM.