NexusFi: Find Your Edge


Home Menu

 





Dynamic calculation of R/R after an entry signal


Discussion in NinjaTrader

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




 
Search this Thread

Dynamic calculation of R/R after an entry signal

  #1 (permalink)
AquaLife
Amsterdam
 
Posts: 3 since Oct 2014
Thanks Given: 1
Thanks Received: 0

Hi all,

I'm currently working on a strategy that measures the Risk/Reward ratio as an entry filter. This is the coding I'm currently using for a LONG entry;

 
Code
if (CCI(256)[0] > -100 && CCI(256)[1] > -100 && CCI(256)[2] > -100 && CrossAbove(CCI(256), -100, 3) && ((EMA(50)[0] - Close[0]) / (Close[0] - (Low[LowestBar(Low, 96)] - 10 * TickSize))) >= 0.90)
			{	
				LongEntryOrder = EnterLong(30000, "LongEntry");
				DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] - 5 * TickSize, Color.Lime);
			}
As you can see I'm checking if CCI > -100 for the past 3 bars. The red part is the R/R measurement. As you can see I want the R/R ratio to be at least 0,90 before I want to enter a trade. But now the thing I can't figure out yet;

IF the R/R ratio is below 0,9, but all the other rules for entry are met, I want my strategy to check on the next bar if;

1) Target 1 wouldn't have hit yet. (Target 1 = EMA 50 period)
2) My stoploss wouldn't have hit yet (StopLoss = 10 ticks below the lowest low of the last 96 bars counted from the entry bar)
3) CCI remains above -100
4) R/R ratio is at least 1.10

I want the strategy to keep checking these 4 requirements and enter a LONG position if all 4 requirements are met. If 1 of the 4 are false, I want the strategy to reset completely and start checking again for the original entry requirements. But I have no idea what logic to use to keep checking this every bar and still keep in mind the first entry requirements.

I hope I'm making some sense here. To clear things up, I've added a chart where I'm illustrating what I just described.
I've also added my whole coding.

 
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 CCItest : Strategy
    {
        #region Variables
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
		
		private IOrder LongEntryOrder = null;
		private IOrder ShortEntryOrder = null;
		private IOrder LongScalper = null;
		private IOrder LongTarget1 = null;
		private IOrder ShortScalper = null;
		private IOrder ShortTarget1 = null;
		
		#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()
        {
            CalculateOnBarClose = true;
			ExitOnClose = false;
			EntriesPerDirection = 1;
			EntryHandling = EntryHandling.AllEntries;
			
			Add(CCI(256));
            Add(EMA(50));
		}

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // LONG entry condition set 
            if (CCI(256)[0] > -100 && CCI(256)[1] > -100 && CCI(256)[2] > -100 && CrossAbove(CCI(256), -100, 3) && ((EMA(50)[0] - Close[0]) / (Close[0] - (Low[LowestBar(Low, 96)] - 10 * TickSize))) >= 0.90)
			{	
				LongEntryOrder = EnterLong(10000, "LongEntry");
				DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] - 5 * TickSize, Color.Lime);
			}
		
			// SHORT entry condition set
            if (CCI(256)[0] < 100 && CCI(256)[1] < 100 && CCI(256)[2] < 100 && CrossBelow(CCI(256), 100, 3) && ((Close[0] - EMA(50)[0]) / ((High[HighestBar(High, 96)] + 10 * TickSize) - Close[0])) >= 0.90)
			{
				ShortEntryOrder = EnterShort(10000, "ShortEntry");
				DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 5 * TickSize, Color.Lime);
				}
			
			
			
			
			
			

			
			
			
			// LONG StopLoss condition set
			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (Position.Quantity == 10000)
				{
					if (EMA(50)[0] <= Position.AvgPrice)
					{
						ExitLong(0, 10000, "ExitEMALong", "");
					}
				}
			}
				
			// SHORT StopLoss condition set
			if (Position.MarketPosition == MarketPosition.Short)
			{
				if (Position.Quantity == 10000)
				{
					if (EMA(50)[0] >= Position.AvgPrice)
					{
						ExitShort(0, 10000, "ExitEMAShort", "");
					}
				}
			}
			
			
			
			
			
			
			
			
			
			
			// LONG Scalper condition set
			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (Position.Quantity == 10000)
				{
					LongScalper = ExitLongLimit(0, true, 10000, EMA(50)[0] - 2 * TickSize, "LongScalper", "");
				}
			}

			// SHORT Scalper condition set
			if (Position.MarketPosition == MarketPosition.Short)
			{
				if (Position.Quantity == 10000)
				{
					ShortScalper = ExitShortLimit(0, true, 10000, EMA(100)[0] + 2 * TickSize, "ShortScalper", "");
				}
			}

		}
		
		
		
		
		
		
		
		
		
		
		protected override void OnExecution (IExecution execution)
		{
			if (LongEntryOrder != null && LongEntryOrder == execution.Order)
			{
				if (Position.Quantity == 10000)
				{
					ExitLongStop(0, true, 30000, Low[LowestBar(Low, 96)] - 10 * TickSize, "StoppedOutLong", "");
				}
			}
			
			if (ShortEntryOrder != null && ShortEntryOrder == execution.Order)
			{
				if (Position.Quantity == 10000)
				{
					ExitShortStop(0, true, 30000, High[HighestBar(High, 96)] + 10 * TickSize, "StoppedOutShort", "");
				}
			}

				
		}
	}
		#region Properties
        #endregion
}

Attached Thumbnails
Click image for larger version

Name:	Example.png
Views:	169
Size:	35.6 KB
ID:	162944  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
35 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks




Last Updated on October 22, 2014


© 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