![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
|
Hi please help me code my strategy
Last edited by SLASH; 04-23-2012 at 08:25 PM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Looks correct ninja hattori, but you have actually 2 bars of rising volume in those setup. What issues do you see? Do they work as you would expect or not?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Bertrand for this post: |
|
|
|
#3 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
ninja hattori, unfortunately we would not offer coding or code modification services here, for those the certified NinjaScript consultants listed on my link below could be tasked -
http://www.ninjatrader.com/partners#...pt-Consultants
Bertrand
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Bertrand for this post: |
|
|
|
#4 |
|
Member
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
|
deleted previous codes ,as they were causing confusion
![]() I want to set my stop below current day open - 10 ticks ,Why am I not getting desired result ![]() HTML Code:
{
#region Variables
private int stoplossticks = 10;
private int profittargetticks = 20;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
/* There are several ways you can use SetStopLoss and SetProfitTarget. You can have them set to a currency value
or some sort of calculation mode. Calculation modes available are by percent, price, and ticks. SetStopLoss and
SetProfitTarget will submit real working orders unless you decide to simulate the orders. */
SetStopLoss(CalculationMode.Ticks, stoplossticks);
SetProfitTarget(CalculationMode.Ticks, profittargetticks);
CalculateOnBarClose = false;
Add(CurrentDayOHL());
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, stoplossticks);
}
// If a long position is open, set stoploss below current day open - 10 ticks
else if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price set stoploss below current day open
if (High[0] > (Position.AvgPrice-CurrentDayOHL().CurrentOpen[0] )+ 10 * TickSize)
{
SetStopLoss(CalculationMode.Ticks, (Position.AvgPrice-CurrentDayOHL().CurrentOpen[0] )+ 10 * TickSize);
}
}
// Condition set 1
if (Close[0] > CurrentDayOHL().CurrentOpen[0]
&& High[0] > High[1])
{
EnterLong();
}
// Condition set 2
if (Close[0] < CurrentDayOHL().CurrentOpen[0]
&& Low[0] < Low[1])
{
EnterShort();
}
}
#region Properties
#endregion
}
}
|
|
|
|
|
|
#5 |
|
Member
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
|
Hi as per condition i am getting Dots at the correct bars why am i getting long signal on the next bar
http://i.imgur.com/39blV.jpg HTML Code:
protected override void OnBarUpdate()
{
// Condition set 1
if (Close[1] > CurrentDayOHL().CurrentOpen[0]
&& Close[1]>Open[1]
&& High[0]>Open[0]
&& High[0] > High[1])
{
Print("");
DrawDot("My Dot"+ CurrentBar,false,0,High[0],Color.Blue);
EnterLong();
}
// Condition set 2
if (Close[1] < CurrentDayOHL().CurrentOpen[0]
&& Close[1]<Open[1]
&& Low[0]<Open[0]
&& Low[0] < Low[1])
{
Print("");
DrawDot("My Dot"+ CurrentBar,false,0,Low[0],Color.Red);
EnterShort();
}
}
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Sorry, perhaps I'm not following you, however after the blue dot you show with your arrow you see a long entry to reverse the position. The trade will be entered on the next bar after your condition to enter evaluated to 'true'.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Bertrand for this post: |
|
|
|
#7 |
|
Member
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
|
plz see pic below marked with arrow ,why am I getting lot size everywhere as 100@,when I have not given this in my strategy, how can I change it ? I want target 1=50,target2=25 and target3=25
http://i.imgur.com/lJD7v.png |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
Ninja,
This is a plot of some execution that occurred in the past. If you want to see the live orders with stop loss and take profits, I would suggest opening a new chart, and then enabling chart trader on this chart. You cannot have chart trader on a chart that has a strategy active on it.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_AdamP for this post: |
|
|
|
#9 |
|
Member
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
|
Thanks for helping me
I want to break even by partially booking some lots for that my calculation is this private int target1 = 4; ( I am considering for commission etc) private int stop =2; ( the stop value ,below current day open for long and above current day open for short) so if current day open is at 5000 and my Position.AvgPrice is 5005 my risk in this trade is : 5005-5000= 5 so total points 4+2+5 =11 points if lot size is 50 and I buy 10 lots so risk is (50*10)=500*11= 5500 INR To cover this risk I have sell 60% out of total 500 lots so 5500/300=18.33 points Now how can I SetProfitTarget to cover these 18.33 points HTML Code:
SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice+(Position.AvgPrice-current day open+stop) + (Target1*TickSize));
plz look at the codes below HTML Code:
public class test3 : Strategy
{
#region Variables
private int target1 = 4;
private int target2 = 10;
private int target3 = 10;
private int stop =2;
#endregion
protected override void Initialize()
{
Add(CurrentDayOHL());
CalculateOnBarClose = true;
EntryHandling = EntryHandling.UniqueEntries;
}
private void GoLong()
{
SetStopLoss("target1", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false);
SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice+(Position.AvgPrice-stop)) + (Target1*TickSize));
SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
EnterLong("target1");
EnterLong("target2");
EnterLong("target3");
}
private void GoShort()
{
SetStopLoss("target1", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false);
SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice-(stop-Position.AvgPrice)) - (Target1*TickSize));
SetProfitTarget("target2", CalculationMode.Price, Close[0] - ((Target1+Target2)*TickSize));
SetProfitTarget("target3", CalculationMode.Price, Close[0] - ((Target1+Target2+Target3)*TickSize));
EnterShort("target1");
EnterShort("target2");
EnterShort("target3");
}
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;
if (Position.MarketPosition != MarketPosition.Flat) return;
// Condition set 1
if ( (Close[1] > CurrentDayOHL().CurrentOpen[0]
&& Close[1]>Open[1]
&& High[0]>Open[0]
&& High[0] > High[1])
||
// Condition set 2
(CrossAbove(High, CurrentDayOHL().CurrentOpen, 1))
&& Close[1]>Open[1]
&& High[0]>Open[0]
&& High[0] > High[1]
)
{
GoLong();
{
PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\OrderFilled.wav");
}
}
// Condition set 3
else if ((Close[1] < CurrentDayOHL().CurrentOpen[0]
&& Close[1]<Open[1]
&& Low[0]<Open[0]
&& Low[0] < Low[1])
||
// Condition set 4
(CrossBelow(Low, CurrentDayOHL().CurrentOpen, 1))
&& Close[1]<Open[1]
&& Low[0]<Open[0]
&& Low[0] < Low[1]
)
{
GoShort();
{
PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\OrderFilled.wav");
}
}
}
Last edited by SLASH; 05-08-2012 at 01:18 PM.
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
ninja hattori,
Sorry, I had a difficult time following your question. What is it that you're looking to accomplish in NinjaScript?
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
|
scaling out ,by partially booking some lots to get risk free
Last edited by SLASH; 05-08-2012 at 09:35 PM.
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
ninja hattori, the scale out of a position you would need to scale in first it the desired quantities -
http://www.ninjatrader.com/support/f...ead.php?t=3751 For the target value needed to get 'risk free' you can dynamically calculate either a price or tick value in your OnBarUpdate and adjust the SetProfitTarget to it - http://www.ninjatrader.com/support/f...ead.php?t=3222
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A little code help? | jjlamb24 | Strategy Analyzer | 7 | 02-12-2011 01:47 PM |
| Converting EL code to Ninja code | anatop | Indicator Development | 1 | 10-18-2010 02:23 PM |
| NEED Help For Code | Frasva | General Programming | 3 | 02-15-2009 06:43 AM |
| multi-time frame code and entry code | Mark_486 | General Programming | 1 | 05-15-2008 11:54 AM |
| Code->test/debug->change code->retest ... cycle process | bbarroux | Strategy Development | 3 | 10-02-2007 12:44 PM |