![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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);
Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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];
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 3
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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);
Joydeep M.
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |