Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with example of adding atm to a Strat. Looking for example.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_Bertrand
    replied
    forrestang, what the point the stop does not execute like you would expect, what info does the TraceOrders output give you then? To me your price adjustment does not seem right for both sides you add 2 tick to the AvgPrice of the position.

    Leave a comment:


  • forrestang
    replied
    This thing is driving me crazy!!!

    Ok guys, this script is driving me nutz! I just can't seem to figure this out. I now have the long and short sides working fine.

    Now the problem is, that when the strategy takes a short, IT WILL NOT move my stop to BE+2. And it ONLY does this for the short side. If I comment out the long side completely, and only attempt to execute the short side, it STILL does not work.

    But EVERYTHING works for the long side, using the exact same code, but with different variables and operands of course.

    This is just a simple strat, trying to get the stops to work. I'm using a moving average to try to figure out how to get the stops to work.

    Here are the rules for the strategy (short example):
    1. If price crosses below an ema, go short
    2. At time of the short, enter a stop of 28 tics
    3. At time of short, enter profit target of 16 tics
    4. If price moves 8 tics in my favor, move stop to BE+2
    5. If at anytime price closes back below ema, exit trade immidiately


    Im attaching the script, and some examples. Any help would be greatly appreciated!
    Attached Files

    Leave a comment:


  • forrestang
    replied
    Just an update, I got it working!

    Previously, I was resetting my bool at the END of onBarUpdate(). I moved this and made it check at the beginning, and now it works fine.

    So both long and short are working properly in one script.

    Woot!

    Leave a comment:


  • forrestang
    replied
    Originally posted by NinjaTrader_Bertrand View Post
    You could go that route as well, but then they would not be able to cross communicate about the positions per default, I'm not sure if you would need or not, they would run independently then.
    Great! That probably would work. I'll give that a try until I can figure out how to get both the long and short side to work concurrently.

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    You could go that route as well, but then they would not be able to cross communicate about the positions per default, I'm not sure if you would need or not, they would run independently then.

    Leave a comment:


  • forrestang
    replied
    Would it be possible to just create two strategies? One for short, and one for long, so that it will execute the way that it should?

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    forrestang, for that case try working with a non simulated stoploss, last parameter set to 'false' instead of 'true'.

    Leave a comment:


  • forrestang
    replied
    I have yet to look into IOrder object.

    But I think it might be executing the trades I want.

    I have a different question about my stop loss. At one point I move my stop to BE+2. I would expect the trade to exit immediately once price touches that stop loss point. But it actually doesn't trigger till price moves through it one tic.

    Is there a way to change it so that it actually executes like a typical sell stop? Or would I just be better served by actually setting my stoploss order to BE+3 if I want it to perform like a BE+2?

    Code:
    			//BUY LOGIC BELOW-------------------------------------------------------------
    			if (Close[0]>spanB[0] && Close[1] > spanB[1] && Close[2] <= spanB[2])
    			{
    				EnterLong(DefaultQuantity, "Long1");
    			}
    						
    			if (buyCase)
    			{
    				SetStopLoss("Long1", CalculationMode.Price, Position.AvgPrice - initialStop* TickSize, true);
    				buyCase = false;
    			}
    
    			if (High[0] >= (Position.AvgPrice + beMove* TickSize) && !buyCase)
    			{
    				SetStopLoss("Long1", CalculationMode.Price, [COLOR="DarkOrange"]Position.AvgPrice + 2* TickSize[/COLOR], true);
    			}
    			
    			if (Close[0]< spanB[0] && !buyCase)
    			{
    				ExitLong("ExitLong1", "Long1");
    			}
    						
    			//Reset your bool flag when flat. 
    			if (Position.MarketPosition == MarketPosition.Flat )
    				buyCase = true;

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    forrestang, it would be advantageous working with the IOrder objects then for you, since you could check the detailed states / properties for each making up your full position - http://www.ninjatrader.com/support/h...nt7/iorder.htm

    This will give more granular control in this area.

    Leave a comment:


  • forrestang
    replied
    Since I tag my entry with a name upon entry, and so are the exits..... there must be some way to just check if that unique trade placed is still in the market?

    Leave a comment:


  • forrestang
    replied
    Ok... I have a slight problem. I'm using this to reset my flag:
    Code:
    			//Reset your bool flag when flat. 
    			if (Position.MarketPosition == MarketPosition.Flat)
    				sellCase = true;
    I duplicated the script, and flipped all of the values(for trades in the opposite direction), but the problem is above, as the strat may be in a short trade, and then trigger a long trade, so I would have a net 2 positions. Once it goes down to evaluate this to reset the flag, the strat thinks it may still be in a long position even due to the opposite direction being in a trade, and it resets my bool.

    Is there a way around this?
    Last edited by forrestang; 08-01-2011, 10:41 PM.

    Leave a comment:


  • forrestang
    replied
    Thanks for the help fellas.

    I think I got it now.

    I went with this, slight modification from my original by pulling the flag out of my entry loop:

    Code:
    #region Variables
    private bool buyCase = true;
     #endregion
    
    protected override void Initialize()
            {
                CalculateOnBarClose = true;
    	    TraceOrders      = true;
                SetProfitTarget(CalculationMode.Ticks, 16);
             }
    
    protected override void OnBarUpdate()
            {
    
    		if (buyCase == true)
    		{
    			SetStopLoss("Long1", CalculationMode.Price, Position.AvgPrice - 16* TickSize, true);
    			buyCase = false;
    		}
    
    		if (Close[0] >= (Position.AvgPrice + 8* TickSize) && buyCase == false)
    		{
    			SetStopLoss("Long1", CalculationMode.Price, Position.AvgPrice + 2* TickSize, true);
    		}
    			
    		if (Close[0]< spanB[0] && buyCase ==  false)
    		{
    			ExitLong("ExitLong1", "Long1");
    		}
    						
    			
    		if (Position.MarketPosition == MarketPosition.Flat)
    				buyCase = true;  //clear flag
            }
    Last edited by forrestang; 08-01-2011, 09:52 AM.

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    Hi forrestang, if you find your stops being not executed / ignored, please rerun your strategy with TraceOrders enabled, so you would get detailed order debug info shown in your output window.

    Leave a comment:


  • forrestang
    replied
    Howdy Austin. I'm not getting an error in terms of compiling or running it.

    The problem is that at times my stops aren't being executed. I must have my logic or my flag implemented in a bad way?

    So my Fixed Profit Target Exit, will always be a set number, so I put that in the 'Initialize' section.

    My STOP Exits, can occur on 3 possible conditions. So I put the 'setStopLoss' in the 'onBarUpdate()' section.

    The 3 possible stops are:
    1. Upon Entry, a fixed catastrophe stop a set number of tics from entry
    2. Price moves a fixed number of tics in my favor, then MOVES to BE+2 tics
    3. At any time after entry, if price CLOSES below my indicator, EXIT the trade

    Leave a comment:


  • NinjaTrader_Austin
    replied
    Forrestang, what is the exact error you're running into here?

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by CaptainJack, 05-29-2026, 05:09 AM
0 responses
390 views
0 likes
Last Post CaptainJack  
Started by CaptainJack, 05-29-2026, 12:02 AM
0 responses
262 views
0 likes
Last Post CaptainJack  
Started by charlesugo_1, 05-26-2026, 05:03 PM
0 responses
221 views
1 like
Last Post charlesugo_1  
Started by DannyP96, 05-18-2026, 02:38 PM
1 response
305 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by CarlTrading, 05-11-2026, 05:56 AM
0 responses
269 views
0 likes
Last Post CarlTrading  
Working...
X