NexusFi: Find Your Edge


Home Menu

 





NT7 AtmStrategy Issues - Need Help


Discussion in NinjaTrader

Updated
    1. trending_up 1,250 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

NT7 AtmStrategy Issues - Need Help

  #1 (permalink)
 rmdavido 
Jackson, MS USA
 
Experience: Advanced
Platform: ThinkOrSwim
Trading: Options
Posts: 12 since Feb 2014
Thanks Given: 7
Thanks Received: 0

Hello,

Long time lurker, first time poster. I am developing a NT strategy using an AtmStrategy but it is not acting the way I want it to. I have attached the script. I want it to basically:

A) Kill the AtmEntryOrder after 1 bar if it does not fill - currently it does not
B) Kill any open AtmStrategies and positions after 3PM - currently it does not
C) When I specify to reverse positions, it does not.

Thanks for your help.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// 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")]
    public class StochScalpRANGE12 : Strategy
    {
        #region Variables
        // Wizard generated variables
		private string	orderId				= string.Empty;
		private string	atmStrategyId		= string.Empty;
		private int 	BarsPast_OE 		= 1;
		private 		DataSeries 			barcount;
        #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()
        {
			barcount = new DataSeries (this) ;

        }

		private void GoLong()
		{
			if (orderId != null)
			{
				string[] entryOrder = GetAtmStrategyEntryOrderStatus(orderId);
				if (GetAtmStrategyMarketPosition(orderId) != MarketPosition.Flat)
					return;
				
				if (entryOrder.Length > 0)
				{                   
					if (entryOrder[2].ToString() != "Filled")
					return;
				} 
				
			
			}
			orderId = GetAtmStrategyUniqueId();
			atmStrategyId = GetAtmStrategyUniqueId();
			AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "CL-Ichi", atmStrategyId);
			barcount.Set(CurrentBars[0]);
		}
		
		private void GoShort()
        {
            if (orderId != null)
            {
                string[] entryOrder = GetAtmStrategyEntryOrderStatus(orderId);               
                if (GetAtmStrategyMarketPosition(orderId) != MarketPosition.Flat)
                    return;

                if (entryOrder.Length > 0)
               { 
                    if (entryOrder[2].ToString() != "Filled")
                    return;
               }
				
            }
       
            orderId    = GetAtmStrategyUniqueId();
			atmStrategyId = GetAtmStrategyUniqueId();
            AtmStrategyCreate(Cbi.OrderAction.SellShort, OrderType.Limit, High[0], 0, TimeInForce.Day, orderId, "CL-Ichi", atmStrategyId);
			barcount.Set(CurrentBars[0]);
        }
		
		private void ExitLong()
        {
            // check to see if not flat, close all open orders
            AtmStrategyClose(orderId);
        } 
			
		private void ExitShort()
        {
            // check to see if not flat, close all open orders
            AtmStrategyClose(orderId);
		}
			
		
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
      	{
				
			if (ToTime(Time[0]) >= ToTime(15, 0, 0))
            {
            AtmStrategyClose(orderId);
            } 
			
//			Cancels Limit order LONG
			if ((CurrentBars[0] + BarsPast_OE)  > barcount[0] && GetAtmStrategyMarketPosition(orderId) == MarketPosition.Long)
			{
			AtmStrategyCancelEntryOrder(orderId);
			orderId = string.Empty;
			Print("Cancelled LONG ENTRY Order from strategy");
			}
			
//			Cancels Limit order SHORT
			if ((CurrentBars[0] + BarsPast_OE)  > barcount[0] && GetAtmStrategyMarketPosition(orderId) == MarketPosition.Short)
			{
			AtmStrategyCancelEntryOrder(orderId);
			orderId = string.Empty;
			Print("Cancelled SHORT ENTRY Order from strategy");
			}
								
			if ((ToTime(Time[0]) > ToTime(5, 30, 0)) && (ToTime(Time[0]) < ToTime(15, 0, 0)))
			{
						
				// Condition set 1
				if (CrossAbove(MACD(10, 22, 5), MACD(10, 22, 5).Avg, 1))
				{
					if (Position.MarketPosition == MarketPosition.Flat)
					{
						GoLong();
					}
					
					if (Position.MarketPosition == MarketPosition.Short)
					{
						ExitShort();
						GoLong();
					}
				}
				
				// Condition set 2
				if (CrossBelow(MACD(10, 22, 5), MACD(10, 22, 5).Avg, 1))
				{
					if (Position.MarketPosition == MarketPosition.Flat)
					{
						GoShort();
					}
					
					if (Position.MarketPosition == MarketPosition.Long)
					{
						ExitLong();
						GoShort();
					}
	        	}
					
			}
			
		}


         #region Properties
		
       	 #endregion
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #3 (permalink)
 GregLGTP 
Austin, TX
 
Experience: Beginner
Platform: NinjaTrader
Broker: NT Broker
Trading: ES
Posts: 121 since Mar 2015
Thanks Given: 258
Thanks Received: 70


@rmdavido,

sprinkle print statements in the code before and after key decision points to see what it does and that it does or does not go where you expect.

Open the Output Window when you run the strategy and watch for the output from the print statements.

Rinse, Repeat until you find where it's going wrong.


Reply With Quote
  #4 (permalink)
 rmdavido 
Jackson, MS USA
 
Experience: Advanced
Platform: ThinkOrSwim
Trading: Options
Posts: 12 since Feb 2014
Thanks Given: 7
Thanks Received: 0

So the output window says this

**NT** Submitting order with strategy 'StochScalpRANGE12/32fa0ce14438448fb4be48d2155722f1'
**NT** GetAtmStrategyMarketPosition() method error: AtmStrategyId '4ef0caf2603f4510b2b0d95ba51324f4' does not exist

and

Cancelled LONG ENTRY Order from strategy
**NT** AtmStrategyCancelEntryOrder() method error: Missing orderId parameter

Started this thread Reply With Quote




Last Updated on May 13, 2015


© 2024 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 - Privacy Policy - Downloads - Top
no new posts