NexusFi: Find Your Edge


Home Menu

 





Semi-automatic trading


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one maxi with 9 posts (1 thanks)
    2. looks_two terratec with 5 posts (2 thanks)
    3. looks_3 monpere with 3 posts (1 thanks)
    4. looks_4 redratsal with 2 posts (0 thanks)
    1. trending_up 7,359 views
    2. thumb_up 4 thanks given
    3. group 7 followers
    1. forum 22 posts
    2. attach_file 3 attachments




 
Search this Thread

Semi-automatic trading

  #1 (permalink)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

Hi all,

I'm programming an indicator which sends orders to a strategy through a button on chart. Once in position inserts stoploss and profit target orders in OCO. SL and PT levels are calculated as soon as the entry order is sent and remain active until the order is filled. I'm not using ATM but a simple Strategy that is attached to the chart. Everything works fine with only a single chart, but, when I use it with more charts, the strategy inserts the SL and TP orders only on the first activated strategy. Does anybody faced a trouble like this or has any hints/suggestions for fixing it?

Thanks.

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Build trailing stop for micro index(s)
Psychology and Money Management
Futures True Range Report
The Elite Circle
 
  #3 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371



maxi View Post
Hi all,

I'm programming an indicator which sends orders to a strategy through a button on chart. Once in position inserts stoploss and profit target orders in OCO. SL and PT levels are calculated as soon as the entry order is sent and remain active until the order is filled. I'm not using ATM but a simple Strategy that is attached to the chart. Everything works fine with only a single chart, but, when I use it with more charts, the strategy inserts the SL and TP orders only on the first activated strategy. Does anybody faced a trouble like this or has any hints/suggestions for fixing it?

Thanks.

I've been trading like this exclusively for the past 3 or 4 years. How are you interfacing the indicator to the strategy?

Reply With Quote
  #4 (permalink)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515


maxi View Post
Hi all,

I'm programming an indicator which sends orders to a strategy through a button on chart. Once in position inserts stoploss and profit target orders in OCO. SL and PT levels are calculated as soon as the entry order is sent and remain active until the order is filled. I'm not using ATM but a simple Strategy that is attached to the chart. Everything works fine with only a single chart, but, when I use it with more charts, the strategy inserts the SL and TP orders only on the first activated strategy. Does anybody faced a trouble like this or has any hints/suggestions for fixing it?

Thanks.

Using a similar concept, I solved most of my problems with a third file containing the outsourced global variables.

This file is placed on a chart that I never chage during the day (weekly chart).Now I can change timeframes when in a trade etc. without resetting the chart values in the charttrader chart. Using multiple strategies, global performance values etc.

This third file did it for me. Hard to guess if this will help with your code.

Reply With Quote
  #5 (permalink)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

monpere:
The strategy is interfaced through a Global variable from an indicator, which sends command (ex: "Buy" ) as well as entry level and SL and PT levels. Entry order (in stop) is entered on button pressing, while the exit levels are activated only "On Execution".

If I use a single chart, everything works as expected, but, adding a second chart (different market), on execution of the entry order, TP and SL are not activated.

Strategies are both attached to any of the 2 charts, so I wouldn't see any reason for not working properly.

My idea is that the manual order could generate a bit of confusion and probably the variable should be "restarded".

I've already done a similar code through ATM and it worked, but that's easier because one has to create an ATM for any of the markets. The pity is that I need to have the number of shares/lots variable and this cannot be done with ATM.

terratec:

interesting idea, although my levels need to be changed often. What do you mean with a third file? A new indicator?

Thanks to all.

Reply With Quote
  #6 (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


maxi View Post
monpere:
The strategy is interfaced through a Global variable from an indicator, which sends command (ex: "Buy" ) as well as entry level and SL and PT levels. Entry order (in stop) is entered on button pressing, while the exit levels are activated only "On Execution".

If I use a single chart, everything works as expected, but, adding a second chart (different market), on execution of the entry order, TP and SL are not activated.

Strategies are both attached to any of the 2 charts, so I wouldn't see any reason for not working properly.

My idea is that the manual order could generate a bit of confusion and probably the variable should be "restarded".

I've already done a similar code through ATM and it worked, but that's easier because one has to create an ATM for any of the markets. The pity is that I need to have the number of shares/lots variable and this cannot be done with ATM.

terratec:

interesting idea, although my levels need to be changed often. What do you mean with a third file? A new indicator?

Thanks to all.

NinjaTrader would not support cross communication between instantiated strategy or indicator classes, a turnaround point could be to rename the same strategy for each and every one chart you want to be opened on your workspace.

Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

Thanks for suggestion redratsal, I will try this.

(Grazie per il suggerimento)

Reply With Quote
  #8 (permalink)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515


maxi View Post
terratec:

interesting idea, although my levels need to be changed often. What do you mean with a third file? A new indicator?

You have an indicator and a strategy. Somewhere you have to define your global stuff. If doing in the indicator or strategy you will have a problem if you use multiple charts / strategies.

So I use an indicator file (could also be a strategy), to have those declarations only once on my system and untouched for the day. In this file I just have the declarations of the variables, their standard values and some calculations like unrealized and realized P&L for all instruments etc.

All the other stuff like sending commands and feedback goes from indy to the strategy of that instrument and back to indy. The third file ist for declaration (and some extras) only. Code like this:

 
Code
public class Strategy_bTPAM_Global {
  	public static string command = "";	// does send commands from indicator to strategy
	public static double timeframe = 0;	// does send the timeframe from indicator to strategy
	public static string status = "";	// does send infos from strategy to indicator
	
	// price data from indicator to strategy
	public static int t1quantity = 0; // quantity for target1
	public static int t2quantity = 0; // quantity for target2
	public static double stoploss = 0; //sl ticks
	public static double target1 = 0; //t1 ticks
	public static double target2 = 0; //t2 ticks
	
	//constants for stop and targets used by indicator and strategy
	public static double baseTicksES = 8;
	public static double baseTicksYM = 16;
	public static double baseTicksNQ = 14;
	public static double baseTicks6E = 16;
	public static double baseTicksCL = 20;
	public static double baseTicksGC = 30;
	
	// Trading plan
	public static double dailylosslimit = 1000;
	public static double highwatertrigger = 1000; // triggered for pullbacklevel (min. level)
	public static double highwaterpullback = 40; // max. pullback% allowed from high water before stop trading for the day
	public static double addposition = 400; // add to a position allowed if profit is higher and position is green
	
	// Account stuff
	public static double BuyingPower = 0;
	public static double CashValue = 0;
	public static double RealizedProfitLoss = 0;
	public static double RealizedProfitLossHigh = 0;
	
	// Position stuff
	public static double UnrealizedProfitLossTotal = 0;
	public static double UnrealizedProfitLossES = 0;
	public static double UnrealizedProfitLossYM = 0;
	public static double UnrealizedProfitLossNQ = 0;
	public static double UnrealizedProfitLoss6E = 0;
	public static double UnrealizedProfitLossCL = 0;
	public static double UnrealizedProfitLossGC = 0;
}

namespace NinjaTrader.Indicator
{
    [Description("bTPAMglobals: Think, Plan, Action, Manage... ")]
	// run this indicator somewhere in a chart that is always in the active workspace
    public class bTPAMglobals : Indicator
    {
        #region Variables
        #endregion

        #region Initialize
		protected override void Initialize()
        {
			CalculateOnBarClose = false; 
        }
		#endregion
		
		#region OnBarUpdate
        protected override void OnBarUpdate()
		{
				if (Strategy_bTPAM_Global.RealizedProfitLossHigh < Strategy_bTPAM_Global.RealizedProfitLoss)
				{
					Strategy_bTPAM_Global.RealizedProfitLossHigh = Strategy_bTPAM_Global.RealizedProfitLoss;
				}
				Strategy_bTPAM_Global.UnrealizedProfitLossTotal = Strategy_bTPAM_Global.UnrealizedProfitLossES
				+ Strategy_bTPAM_Global.UnrealizedProfitLossYM + Strategy_bTPAM_Global.UnrealizedProfitLossNQ
				+ Strategy_bTPAM_Global.UnrealizedProfitLoss6E + Strategy_bTPAM_Global.UnrealizedProfitLossCL
				+ Strategy_bTPAM_Global.UnrealizedProfitLossGC;
        }
		#endregion

Reply With Quote
Thanked by:
  #9 (permalink)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

terratec:

this way sounds good unless you keep your markets/targets/stops unchanged (it looks like some sort of "plan for that day"), but my semi-automated trading is for intraday, so targets and stops must necessarily be manually changed.

Thanks for the idea, I'll keep in mind for future applications.

Reply With Quote
  #10 (permalink)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515



maxi View Post
terratec:

this way sounds good unless you keep your markets/targets/stops unchanged (it looks like some sort of "plan for that day"), but my semi-automated trading is for intraday, so targets and stops must necessarily be manually changed.

Thanks for the idea, I'll keep in mind for future applications.

hi maxi

I am a scalper and have to decide very quick for a mini, medium or big scalp, or to add a runner. It is the beauty of that system that let me do this.

In the indicator I just have to press a button for the strategy (mini, medium, big I would like, and one for the quantity. (and order type and place) The system will place the stops and targets according to the instrument (calculated from the baseTicks values in the globals). The baseTick values could be calculated by ATR etc. but I use values fitting to my style for each instrument. This way I dont have to change settings in each indicator etc., just in one file. And I only need one indicator and one strategy for all the instruments, plus that third file.

When trading in ES, I can just switch the instrument in the chart to CL and everything is ready...

Reply With Quote




Last Updated on November 3, 2016


© 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