NexusFi: Find Your Edge


Home Menu

 





Call ATM Strategy on an automated strategy to control position


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one mrticks with 3 posts (2 thanks)
    2. looks_two harcesis with 2 posts (0 thanks)
    3. looks_3 zeller4 with 1 posts (0 thanks)
    4. looks_4 jsengxx with 1 posts (0 thanks)
    1. trending_up 7,731 views
    2. thumb_up 5 thanks given
    3. group 5 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 jsengxx 
POrtugal
 
Posts: 52 since Nov 2009

Hello,

How can I call an ATM Strategy on an automated ninjascript strategy to control my position?

I have a strategy (VervoortMACrossover) that is working realy good but I want to control my position so I can go breakeven + trailstop.

I have no idea how to doo that.

Can some one help me?

Best regards,
JJ


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
Double Deadlock: Rubio Calls Hormuz Tolls "Unfeasib …
Traders Hideout
400 Million Barrels to Address Middle East Supply Disruption
Commodities
Energy Futures Shatter All-Time Daily Volume: 8.3 Millio …
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #2 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 478 since Jun 2009
Thanks Given: 1,419
Thanks Received: 404

try the built-in SampleAtmStrategy


Reply With Quote
  #3 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10



jsengxx View Post
Hello,

How can I call an ATM Strategy on an automated ninjascript strategy to control my position?

I have a strategy (VervoortMACrossover) that is working realy good but I want to control my position so I can go breakeven + trailstop.

I have no idea how to doo that.

Can some one help me?

Best regards,
JJ

I submitted a template for this on the NT forums a while back. The link for the page is Links and Downloads Manager - NinjaTrader Support Forum and it's the one called "SampleATMCancelStrategy" near the bottom of the page.

Hope it helps!


Reply With Quote
Thanked by:
  #4 (permalink)
 
redratsal's Avatar
 redratsal 
Milan (I)
 
Experience: Advanced
Platform: Ninjatrader
Broker: Kinetick
Trading: FDAX,6E,CL,YM,NQ,ES
Posts: 1,648 since Oct 2010
Thanks Given: 1,215
Thanks Received: 2,090


jsengxx View Post
Hello,

How can I call an ATM Strategy on an automated ninjascript strategy to control my position?

I have a strategy (VervoortMACrossover) that is working realy good but I want to control my position so I can go breakeven + trailstop.

I have no idea how to doo that.

Can some one help me?

Best regards,
JJ

Try this

In Variables

privateint trailstop = 10;



protectedoverridevoid OnBarUpdate()

if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+ ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice - trailstop * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice - trailstop * TickSize);
}
}



In region properties

[Description("")]
[GridCategory(
"Parameters")]
publicint TrailStop
{
get { return trailstop; }
set { trailstop = Math.Max(1, value); }
}


adjust your trailstop accordingly for breakeven set it to 0


Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 harcesis 
Prague/Czech Republic
 
Experience: Intermediate
Platform: Ninjatrader
Trading: YM, RTY
Posts: 13 since Sep 2011
Thanks Given: 2
Thanks Received: 0


mrticks View Post
I submitted a template for this on the NT forums a while back. The link for the page is Links and Downloads Manager - NinjaTrader Support Forum and it's the one called "SampleATMCancelStrategy" near the bottom of the page.

Hope it helps!

Hello Mrticks,

I found your sample template on ninjatrader support forum and I would like to use it since I am not able to program some decent trailing stop loss strategy via strategy wizard.

I have three questions:
1. can I change name of the ATM templates - where in your code I need to change it?
2. how I can merge my conditions with your strategy - should I just copy and paste into on bar update session?
3. is it backtesteble. I read in ninja help that ATM strategy is not backtesteble?

Thank you very much for your feedback in advance.

Miroslav


Reply With Quote
  #6 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


harcesis View Post
Hello Mrticks,

I found your sample template on ninjatrader support forum and I would like to use it since I am not able to program some decent trailing stop loss strategy via strategy wizard.

I have three questions:
1. can I change name of the ATM templates - where in your code I need to change it?
2. how I can merge my conditions with your strategy - should I just copy and paste into on bar update session?
3. is it backtesteble. I read in ninja help that ATM strategy is not backtesteble?

Thank you very much for your feedback in advance.

Miroslav

Hello Miroslav,

I have not used NT in over 5 years but I will try to help!

1. Look for this section in the code, this is where you need to edit your ATM template names to match what you have created locally.
 
Code
           // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
            // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'TF_long_3W_3BR' and 'TF_short_3W_3BR' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK  you can create your own****
                        if (orderIdL.Length == 0  
                                && atmStrategyIdL.Length == 0
								&& FirstTickOfBar
                                && Close [1] <= Open [1]
							    && High  [1] + PrevBarsPlusTicks * TickSize > GetCurrentBid())
                               
                        {
                                atmStrategyIdL = GetAtmStrategyUniqueId();
                                orderIdL = GetAtmStrategyUniqueId();
                                orderBarL = CurrentBar;
                                AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Stop, 0, High[1] + PrevBarsPlusTicks * TickSize, TimeInForce.Day, orderIdL, "TF_long_3W_3BR", atmStrategyIdL);	
			    
						}
                        if (orderIdS.Length == 0  
                                && atmStrategyIdS.Length == 0  
                                && FirstTickOfBar
                				&& Close [1] >= Open [1]
                				&& Low   [1] - PrevBarsMinusTicks * TickSize < GetCurrentAsk())
                               
                        {
                                atmStrategyIdS = GetAtmStrategyUniqueId();
                                orderIdS = GetAtmStrategyUniqueId();
                                orderBarS = CurrentBar;
                                AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Stop, 0, Low[1] - prevBarsMinusTicks * TickSize, TimeInForce.Day, orderIdS, "TF_short_3W_3BR", atmStrategyIdS);

2. Yes, look for this section and insert your code in their:
 
Code
  /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
3. I could never get NT to backtest with an ATM being called via a strategy!


Have fun!


Reply With Quote
  #7 (permalink)
 harcesis 
Prague/Czech Republic
 
Experience: Intermediate
Platform: Ninjatrader
Trading: YM, RTY
Posts: 13 since Sep 2011
Thanks Given: 2
Thanks Received: 0


mrticks View Post
Hello Miroslav,

I have not used NT in over 5 years but I will try to help!

1. Look for this section in the code, this is where you need to edit your ATM template names to match what you have created locally.
 
Code
           // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
            // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'TF_long_3W_3BR' and 'TF_short_3W_3BR' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK  you can create your own****
                        if (orderIdL.Length == 0  
                                && atmStrategyIdL.Length == 0
								&& FirstTickOfBar
                                && Close [1] <= Open [1]
							    && High  [1] + PrevBarsPlusTicks * TickSize > GetCurrentBid())
                               
                        {
                                atmStrategyIdL = GetAtmStrategyUniqueId();
                                orderIdL = GetAtmStrategyUniqueId();
                                orderBarL = CurrentBar;
                                AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Stop, 0, High[1] + PrevBarsPlusTicks * TickSize, TimeInForce.Day, orderIdL, "TF_long_3W_3BR", atmStrategyIdL);	
			    
						}
                        if (orderIdS.Length == 0  
                                && atmStrategyIdS.Length == 0  
                                && FirstTickOfBar
                				&& Close [1] >= Open [1]
                				&& Low   [1] - PrevBarsMinusTicks * TickSize < GetCurrentAsk())
                               
                        {
                                atmStrategyIdS = GetAtmStrategyUniqueId();
                                orderIdS = GetAtmStrategyUniqueId();
                                orderBarS = CurrentBar;
                                AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Stop, 0, Low[1] - prevBarsMinusTicks * TickSize, TimeInForce.Day, orderIdS, "TF_short_3W_3BR", atmStrategyIdS);

2. Yes, look for this section and insert your code in their:
 
Code
  /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
3. I could never get NT to backtest with an ATM being called via a strategy!


Have fun!

Hello Mrticks,

thank you for your replay. Sorry for delay I am trying to fix overfill issues until I will proceed with adding ATM strategy.

I am using unirenko charts and it seems it is opening extra positions in high volatility times.

I am trying to use bool logic to prevent extra entry if trade was once triggered.

Can I come back to you when I fix my overfill issue?

Thank you

Miroslav


Reply With Quote
  #8 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


harcesis View Post
Hello Mrticks,

thank you for your replay. Sorry for delay I am trying to fix overfill issues until I will proceed with adding ATM strategy.

I am using unirenko charts and it seems it is opening extra positions in high volatility times.

I am trying to use bool logic to prevent extra entry if trade was once triggered.

Can I come back to you when I fix my overfill issue?

Thank you

Miroslav

Best of luck with the overfill issue!


Reply With Quote




Last Updated on May 31, 2016


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts