NexusFi: Find Your Edge


Home Menu

 





Plotting Orders and Trade infos on chart


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
chrisbh
Manama
 
Posts: 5 since Jul 2014
Thanks Given: 1
Thanks Received: 0

Hello everyone,

You will find part of my strategy here below.
The idea is to have a visual representation of the bracket orders with Stop and Target (see attached pic) plus additional infos when the trade is closed.

I would like to add on the chart the value in ticks of the Stop or Target hit by price and see if there were any slippage when Stop or Target was hit.

 
Code
namespace NinjaTrader.Strategy
{
    [Description("Momentum Pimping")]
    public class AAA : Strategy
    {
        #region Variables
        private int contract = 1;        
        private int     barNumberOfOrder     = 0;
        private int        lineLength            = 0;  
        private IOrder entryOrder = null;        
          #endregion

        protected override void Initialize()
        {
               TimeInForce = Cbi.TimeInForce.Day;    
            CalculateOnBarClose = true;    
        }
        protected override void OnBarUpdate()
        {                
            //LONG ENTRY CONDITIONS
            if (Position.MarketPosition == MarketPosition.Flat
                && Close[0]<Close[1]
                && Close[1]<Close[2])
            {
                barNumberOfOrder = CurrentBar;
                entryOrder = EnterLongLimit(CONTRACT, Close[0], "");
            }
            //SHORT ENTRY CONDITIONS
            if (Position.MarketPosition == MarketPosition.Flat
                && Close[0]>Close[1]
                && Close[1]>Close[2])
            {
                barNumberOfOrder = CurrentBar;
                entryOrder = EnterShortLimit(CONTRACT, Close[0], "");                
            }        
        }
        protected override void OnExecution(IExecution execution)
        {
            if(execution.Name == "Stop loss")             PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\StopFilled.wav");    
            else if(execution.Name == "Profit target")     PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\TargetFilled.wav");            
           
            int Stop             =   10;
            int Target            =   20;
        
            if (entryOrder != null && entryOrder == execution.Order)
            {    
                SetStopLoss(CalculationMode.Ticks, Stop);
                SetProfitTarget(CalculationMode.Ticks, Target);    
            }
              
            lineLength = Math.Max(CurrentBar - barNumberOfOrder, 3);
            if (Position.MarketPosition == MarketPosition.Long)
            {                    
                PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert2.wav");
                DrawLine("Target", false, lineLength, Position.AvgPrice + (Target) * TickSize, -8*lineLength, Position.AvgPrice + (Target) * TickSize, Color.Lime, DashStyle.Solid, 2);
                DrawLine("Stop", false, lineLength, Position.AvgPrice - (Stop) * TickSize,-8*lineLength, Position.AvgPrice - (Stop) * TickSize, Color.Red, DashStyle.Solid, 2);
                DrawLine("Entry", false, lineLength, Position.AvgPrice, -8*lineLength, Position.AvgPrice, Color.Tan, DashStyle.Solid, 2);
                
                DrawText("TargetValue","Target: "+Convert.ToString(Target)+" Ticks" , 0, Low[0]-12*TickSize, Color.Yellow);
                DrawText("StopValue","Stop: "+Convert.ToString(Stop)+" Ticks" , 0, Low[0]-10*TickSize, Color.Yellow);
            }
            
            else if (Position.MarketPosition == MarketPosition.Short)
            {                    
                PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert2.wav");
                DrawLine("Target", false, lineLength, Position.AvgPrice - (Target) * TickSize, -8*lineLength, Position.AvgPrice - (Target) * TickSize, Color.Lime, DashStyle.Solid, 2);
                DrawLine("Stop", false, lineLength, Position.AvgPrice + (Stop) * TickSize, -8*lineLength, Position.AvgPrice + (Stop) * TickSize, Color.Red, DashStyle.Solid, 2);
                DrawLine("Entry", false, lineLength, Position.AvgPrice, -8*lineLength, Position.AvgPrice, Color.Tan, DashStyle.Solid, 2);
                
                DrawText("TargetValue", "Target:"+Convert.ToString(Target)+" Ticks" , 0, High[0]+12*TickSize, Color.Yellow);
                DrawText("StopValue","Stop:"+Convert.ToString(Stop)+" Ticks" , 0, High[0]+10*TickSize, Color.Yellow);
            }
            if (Position.MarketPosition == MarketPosition.Flat)
            {                
                RemoveDrawObject("Stop");
                RemoveDrawObject("Target");
                RemoveDrawObject("Entry");
                RemoveDrawObject("TargetValue");
                RemoveDrawObject("StopValue");
            }    
        }
        #region Properties    
        [Description("")]
        [GridCategory("3.Parameters")]
        public int CONTRACT
        {
            get { return contract; }
            set { contract = Math.Max(1, value); }
        }
        #endregion
    }
}
Additionally i would like to increase the font of the draw text....Dont know how !

Any recommendations to help me improve this part of the code would be more than welcome

Happy trading

Chris


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Lebanon Problem Kills Switzerland Talks, Brent at $ …
Prediction Markets & Event Contracts
Fed Hike Odds at 57% After Warsh: England Surges 12.9%, …
Prediction Markets & Event Contracts
Netherlands & Germany Surge as World Cup Field Narro …
Prediction Markets & Event Contracts
Daytrading to swingtrading
Traders Hideout
Trump Media to sell instant access to market-moving soci …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
FootPrintV2 Chart for NT8
1 thanks
BERN ALGOS algo trading journal
1 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks




Last Updated on July 5, 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