Advertisement
Sort6666

Untitled

Jun 20th, 2025 (edited)
351
0
20 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 165.40 KB | Source Code | 0 0
  1. #region Using declarations
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Xml.Serialization;
  13. using NinjaTrader.Cbi;
  14. using NinjaTrader.Gui;
  15. using NinjaTrader.Gui.Chart;
  16. using NinjaTrader.Gui.SuperDom;
  17. using NinjaTrader.Gui.Tools;
  18. using NinjaTrader.Data;
  19. using NinjaTrader.NinjaScript;
  20. using NinjaTrader.Core.FloatingPoint;
  21. using NinjaTrader.NinjaScript.Indicators;
  22. using NinjaTrader.NinjaScript.DrawingTools;
  23. #endregion
  24.  
  25. //This namespace holds Strategies in this folder and is required. Do not change it.
  26. namespace NinjaTrader.NinjaScript.Strategies.TradeSaberStrategies
  27. {
  28.     public class OrderEntryButtons : Strategy
  29.     {  
  30.         #region Position
  31.        
  32.         private double myDbl;
  33.        
  34.         private int positionSizeLong;
  35.         private int positionSizeShort;
  36.        
  37.         private bool autoPositionSize;
  38.         private bool customPositionSize;
  39.        
  40.         private double riskSize; // Got deleted. Shorts only, may need later. may delete later
  41.         private double riskOffset;
  42.        
  43.         //RR Mode
  44.         private double LongValues;
  45.         private double ShortValues;
  46.            
  47.         private double LongValuesOffset;
  48.         private double ShortValuesOffset;
  49.        
  50.         //Tick Mode
  51.         private double LongValuesOffsetTickMode;
  52.         private double ShortValuesOffsetTickMode;
  53.        
  54.         private double LongValuesTickMode;
  55.         private double ShortValuesTickMode;
  56.        
  57.        
  58.         private int firstTargetPositionLong;
  59.         private int secondTargetPositionLong;
  60.        
  61.         private int firstTargetPositionShort;
  62.         private int secondTargetPositionShort;
  63.        
  64.        
  65.        
  66.         #endregion
  67.        
  68.         #region Custom Entries
  69.        
  70.         private bool activateMarket;
  71.         private bool armMarket;
  72.         private bool armMarketLong;
  73.         private bool armMarketShort;
  74.        
  75.         private int  armMarketCount = 0;
  76.        
  77.        
  78.         private bool enterClosePrice;
  79.        
  80.         //private bool enterBodyLongHL; May use Later
  81.         //private bool enterBodyShortHL; May use Later
  82.        
  83.         #endregion
  84.        
  85.         #region Entry Offset
  86.        
  87.         private double entryAreaLong;
  88.         private double entryAreaShort;
  89.        
  90.         private double entryAreaClose;
  91.        
  92.         private double percentageCalcEntry;
  93.         private double priceCalcEntry;
  94.         private double tickCalcEntry;
  95.         private double candleBarOffsetEntry;
  96.                
  97.         private double enterLong;
  98.         private double enterShort;
  99.        
  100.         private double enterCloseLong;
  101.         private double enterCloseShort;
  102.        
  103.         #endregion
  104.        
  105.         #region Limit Entry Offset
  106.    
  107.         private double percentageCalcLimitLong;
  108.         private double percentageCalcLimitShort;
  109.         private double priceCalcLimit;
  110.         private double tickCalcLimit;
  111.         private double candleBarOffsetLimit;
  112.                
  113.         private double limitOffsetLong;
  114.         private double limitOffsetShort;
  115.        
  116.         private double limitPriceSetLong;
  117.         private double limitPriceSetShort;
  118.        
  119.         #endregion
  120.        
  121.         #region Stop Offset
  122.        
  123.         private double stopAreaLong;
  124.         private double stopAreaShort;
  125.        
  126.         private double percentageCalcStop;
  127.         private double priceCalcStop;
  128.         private double tickCalcStop;
  129.         private double candleBarOffsetStop;
  130.                
  131.         private double stopLong;
  132.         private double stopShort;
  133.        
  134.         private double setStopLong;
  135.         private double setStopShort;
  136.        
  137.         #endregion
  138.        
  139.         #region Initial Profit Targets
  140.        
  141.         private double setFirstTargetLong;
  142.         private double setFinalTargetLong;
  143.        
  144.         private double setFirstTargetShort;
  145.         private double setFinalTargetShort;
  146.         #endregion
  147.        
  148.         #region Breakeven Offset
  149.        
  150.         private double breakevenAreaLong;
  151.         private double breakevenAreaShort;
  152.        
  153.         private double percentageCalcBreakeven;
  154.         private double priceCalcBreakeven;
  155.         private double tickCalcBreakeven;
  156.         private double candleBarOffsetBreakeven;
  157.                
  158.         private double breakevenLong;
  159.         private double breakevenShort;
  160.        
  161.         private double setBreakevenLong;
  162.         private double setBreakevenShort;
  163.        
  164.         #endregion
  165.        
  166.         #region Trail Offset
  167.        
  168.         private double trailAreaLong;
  169.         private double trailAreaShort;
  170.        
  171.         private double percentageCalcTrail;
  172.         private double priceCalcTrail;
  173.         private double tickCalcTrail;
  174.         private double candleBarOffsetTrail;
  175.        
  176.         private bool activeTrail;
  177.        
  178.         #endregion
  179.        
  180.         #region Management
  181.        
  182.         private bool myFreeTrade;//Regular Trade Profit/Sop
  183.         private bool myFreeLimit;//Limit Orders
  184.        
  185.         //BE Area
  186.         private bool breakevenAreaSetButton;
  187.         private bool breakevenAreaSetAuto;
  188.         private bool myFreeBEArea;
  189.         private double breakevenAreaTrigger;
  190.         private double breakevenAreaStopSet;
  191.        
  192.         //BE Actual
  193.         private bool breakevenActualSetButton;
  194.         private bool breakevenActualSetAuto;
  195.         private bool myFreeBEActual;
  196.         private double breakevenActualTrigger;
  197.         private double breakevenActualStopSet;
  198.        
  199.         //Custom Stop
  200.         private bool myFreeCustomStop;
  201.         private double customStopTrigger;
  202.        
  203.         //Trail
  204.         //private bool candleTrailSetButton;
  205.         //private bool candleTrailSetAuto;
  206.         private double candleTrailTrigger;
  207.        
  208.         private double candleTrailStopSetLong;
  209.         private double candleTrailStopSetShort;
  210.        
  211.         private bool myFreeCandleTrail;
  212.         private bool trailTriggeredCandle;
  213.         //private bool myFreeCustomTrail;//Custom Trail
  214.        
  215.         //private bool myFreeCandleTrail;//Candle Trail
  216.        
  217.         #endregion
  218.        
  219.         #region Fib
  220.        
  221.         private bool isFib;
  222.         private int fibCount = 1;
  223.        
  224.         #endregion
  225.    
  226.         private bool countOnce;
  227.        
  228.         private bool myFillCheck;
  229.        
  230.         private int myPosition;
  231.        
  232.         private OrderManagement managementType = OrderManagement.RR_Mode;
  233.        
  234.         public enum OrderManagement
  235.         {
  236.             RR_Mode,
  237.             Tick_Mode,
  238.         }
  239.        
  240.         private bool rrMode;
  241.         private bool tickMode;
  242.        
  243.         private bool AddOffset = true;
  244.        
  245.         #region Button Clicked
  246.        
  247.         private bool longButtonHLClicked;   //1
  248.         private bool shortButtonHLClicked;  //2
  249.            
  250.         private bool longButtonMarketClicked;       //3
  251.         private bool shortButtonMarketClicked;      //4
  252.        
  253.         private bool customLongClicked;             //5
  254.         private bool customShortClicked;            //6
  255.        
  256.        
  257.         private bool breakevenButtonClicked;        //8
  258.         private bool trailButtonClicked;            //9
  259.        
  260.         private bool lineButtonClicked;             //10
  261.         private bool longLineButtonClicked;
  262.         private bool shortLineButtonClicked;
  263.        
  264.         private bool unlockButtonClicked;           //11
  265.        
  266.         private bool displayButtonClicked;          //16
  267.        
  268.         private bool fibButtonClicked;              //17
  269.        
  270.         #endregion
  271.        
  272.         #region Chart Trader Buttons
  273.        
  274.         private System.Windows.Controls.RowDefinition   addedRow;
  275.         private Gui.Chart.ChartTab                      chartTab;
  276.         private Gui.Chart.Chart                         chartWindow;
  277.         private System.Windows.Controls.Grid            chartTraderGrid, chartTraderButtonsGrid, lowerButtonsGrid;
  278.         private System.Windows.Controls.Button          longButtonHL, shortButtonHL, longButtonMarket, shortButtonMarket, customLong, customShort, myButton7, breakevenButton, trailButton, lineButton, unlockButton, myButton12, myButton13, myButton14, myButton15, displayButton, fibButton;
  279.         private bool                                    panelActive;
  280.         private System.Windows.Controls.TabItem         tabItem;
  281.        
  282.         #endregion
  283.        
  284.         #region TradeSaber Social
  285.        
  286.         private string author                               = "TradeSaber(Dre)";
  287.         private string version                              = "Version 5.0.2 // December 2022";
  288.        
  289.         private string youtube                              = "https://youtu.be/WvO8Gwx3Fh0";
  290.         private string discord                              = "https://discord.gg/2YU9GDme8j";
  291.         private string tradeSaber                           = "https://tradesaber.com/";
  292.        
  293.         private bool showSocials;
  294.        
  295.         private bool youtubeButtonClicked;
  296.         private bool discordButtonClicked;
  297.         private bool tradeSaberButtonClicked;
  298.        
  299.         private System.Windows.Controls.Button youtubeButton;
  300.         private System.Windows.Controls.Button discordButton;
  301.         private System.Windows.Controls.Button tradeSaberButton;
  302.        
  303.        
  304.         private System.Windows.Controls.Grid myGrid29;
  305.        
  306.         #endregion
  307.        
  308.         protected override void OnStateChange()
  309.         {
  310.             /// 5.0.2 Bug Fixes
  311.             /// Issue with certain Futures instruments needing more than 2 decimals. Not setting proper targets.
  312.             /// Issue with the Close Position button not closing dual targets
  313.             /// Issue with Breakeven, Trail Not working after hitting first target (On filled Position) ....>Partial fill management has been disabled due to issue with position size
  314.            
  315.             if (State == State.SetDefaults)
  316.             {
  317.                 Description                                 = @"Enter the description for your new custom Strategy here.";
  318.                 Name                                        = "OrderEntryButtons";
  319.                 Calculate                                   = Calculate.OnEachTick;
  320.                 EntriesPerDirection                         = 1;
  321.                 EntryHandling                               = EntryHandling.UniqueEntries;
  322.                 IsExitOnSessionCloseStrategy                = true;
  323.                 ExitOnSessionCloseSeconds                   = 30;
  324.                 IsFillLimitOnTouch                          = false;
  325.                 MaximumBarsLookBack                         = MaximumBarsLookBack.TwoHundredFiftySix;
  326.                 OrderFillResolution                         = OrderFillResolution.Standard;
  327.                 Slippage                                    = 0;
  328.                 StartBehavior                               = StartBehavior.WaitUntilFlat;
  329.                 TimeInForce                                 = TimeInForce.Gtc;
  330.                 TraceOrders                                 = false;
  331.                 RealtimeErrorHandling                       = RealtimeErrorHandling.StopCancelClose;
  332.                 StopTargetHandling                          = StopTargetHandling.PerEntryExecution;
  333.                 BarsRequiredToTrade                         = 20;
  334.                 // Disable this property for performance gains in Strategy Analyzer optimizations
  335.                 // See the Help Guide for additional information
  336.                 IsInstantiatedOnEachOptimizationIteration   = true;
  337.                
  338.                 #region Default Parameters
  339.                
  340.                 //Position Size
  341.                 autoPositionSize                            = true;
  342.                 MaxLossPerTrade                             = 1000;
  343.                 customPositionSize                          = false;
  344.                 CustomPositionAmount                        = 5;
  345.                
  346.                 //Custom Button
  347.                 armMarket                                   = false;
  348.                 enterClosePrice                             = true;
  349.                
  350.                 //Entry Offset
  351.                 PriceOffsetEntry                            = 0;
  352.                 PercentageOffsetEntry                       = 0;
  353.                 TickOffsetEntry                             = 0;
  354.                
  355.                 //Limit Order Offset (Offsets from Entry)
  356.                 PriceOffsetLimit                            = 0;
  357.                 PercentageOffsetLimit                       = 0;
  358.                 TickOffsetLimit                             = 0;
  359.                 myFreeLimit                                 = true;
  360.                 useLimit                                    = false;
  361.                
  362.                 //Dual Target Options
  363.                 dualTarget                                  = false;
  364.                 splitPercent                                = 0.25;
  365.                
  366.                 //Stop Offset
  367.                 stopLoss                                    = true;
  368.                 PriceOffsetStop                             = 0;
  369.                 PercentageOffsetStop                        = 0;
  370.                 TickOffsetStop                              = 0;
  371.                
  372.                 //Profit
  373.                 profitTarget                                = true;
  374.                 FirstTargetRR                               = 1;
  375.                 FinalTargetRR                               = 5;
  376.                
  377.                
  378.                 //Management
  379.                 PriceOffsetBreakeven                        = 0;
  380.                 PercentageOffsetBreakeven                   = 0;
  381.                 TickOffsetBreakeven                         = 0;
  382.                
  383.                 breakevenAreaSetButton                      = false;
  384.                 breakevenAreaSetAuto                        = false;
  385.                 breakevenAreaTarget                         = 1.0;
  386.                
  387.                 breakevenActualSetButton                    = true;
  388.                 breakevenActualSetAuto                      = false;
  389.                 breakevenActualTarget                       = 1.5; 
  390.                
  391.                 ///Custom Move - Later Use
  392.                 //customMoveStopSet                         = false;
  393.                 //customMoveStopTarget                      = 2.0;
  394.                
  395.                 ///customTrailSet                           = false;
  396.                 ///customTrailTarget                        = 2.5;
  397.                
  398.                 //TrailStop
  399.                 PriceOffsetTrail                            = 0;
  400.                 PercentageOffsetTrail                       = 0;
  401.                 TickOffsetTrail                             = 0;
  402.                
  403.                
  404.                 candleTrailSetButton                        = true;
  405.                 candleTrailSetAuto                          = false;
  406.                 candleTrailTarget                           = 1.0;                         
  407.                            
  408.                
  409.                 //Entry And Stop Line look back
  410.                 CandleLookBackEntry                         = 1;
  411.                 CandleLookBackStop                          = 1;
  412.                
  413.                 CandleRange                                 = true;
  414.                 //AddOffset                                 = true;
  415.                
  416.        
  417.                 countOnce                                   = true;
  418.                
  419.  
  420.                 DisplayText                                 = true;
  421.                
  422.                 showSocials                                 = true;
  423.                
  424.                 //Prints
  425.                 SystemPrint                                 = true;
  426.                 EntryPrints                                 = false;
  427.                 LimitPrints                                 = false;
  428.                 StopPrints                                  = false;
  429.                 PositionSizePrints                          = false;
  430.                 ProfitTatgetPrints                          = false;
  431.                 BreakevenPrints                             = false;
  432.                 TrailPrints                                 = false;
  433.                
  434.                 #endregion
  435.             }
  436.             else if (State == State.Configure)
  437.             {
  438.             }
  439.            
  440.             else if (State == State.DataLoaded)
  441.             {              
  442.                 ClearOutputWindow();
  443.                
  444.                 myDbl = Instrument.MasterInstrument.PointValue * Instrument.MasterInstrument.TickSize;
  445.                
  446.                
  447.                 switch (managementType)
  448.                 {
  449.                     case OrderManagement.RR_Mode:
  450.                     {
  451.                         rrMode      = true;
  452.                         tickMode    = false;
  453.                     }
  454.                     break;
  455.                    
  456.                     case OrderManagement.Tick_Mode:
  457.                     {
  458.                         rrMode      = false;
  459.                         tickMode    = true;
  460.                     }
  461.                     break;
  462.                 }
  463.                
  464.             }
  465.  
  466.             else if (State == State.Historical)
  467.             {
  468.                 #region Chart Trader Buttons Load
  469.                
  470.                 if (ChartControl != null)
  471.                 {
  472.                     ChartControl.Dispatcher.InvokeAsync(() =>
  473.                     {
  474.                         CreateWPFControls();
  475.                     });
  476.                 }
  477.                
  478.                 #endregion
  479.                
  480.                 #region Range/Unlock Buttons Load
  481.                 /* Removed -> Moved to chart trader
  482.                
  483.                 if (UserControlCollection.Contains(myGrid))
  484.                     return;
  485.                
  486.                 Dispatcher.InvokeAsync((() =>
  487.                 {
  488.                     myGrid = new System.Windows.Controls.Grid
  489.                     {
  490.                         Name = "MyCustomGrid", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
  491.                     };
  492.                
  493.                     System.Windows.Controls.ColumnDefinition column1 = new System.Windows.Controls.ColumnDefinition();
  494.                     System.Windows.Controls.ColumnDefinition column2 = new System.Windows.Controls.ColumnDefinition();
  495.                    
  496.                     myGrid.ColumnDefinitions.Add(column1);
  497.                     myGrid.ColumnDefinitions.Add(column2);
  498.                    
  499.                     lineButton = new System.Windows.Controls.Button
  500.                     {
  501.                         Name = "longLineButton", Content = "LongRange", Foreground = Brushes.Black, Background = Brushes.Green
  502.                     };
  503.                    
  504.                     unlockButton = new System.Windows.Controls.Button
  505.                     {
  506.                         Name = "unlockButton", Content = "Unlocked", Foreground = Brushes.Black, Background = Brushes.White
  507.                     };
  508.                
  509.                     lineButton.Click += OnButtonClick;
  510.                     unlockButton.Click += OnButtonClick;
  511.                    
  512.                     System.Windows.Controls.Grid.SetColumn(lineButton, 0);
  513.                     System.Windows.Controls.Grid.SetColumn(unlockButton, 1);
  514.                    
  515.                     myGrid.Children.Add(lineButton);
  516.                     myGrid.Children.Add(unlockButton);
  517.                    
  518.                     UserControlCollection.Add(myGrid);
  519.                    
  520.                     longLineButtonClicked   = true;
  521.                     unlockButtonClicked     = true;
  522.                    
  523.                 }));
  524.                 */
  525.                 #endregion
  526.                
  527.                 #region TradeSaber Socials
  528.            
  529.             if (showSocials)
  530.             {
  531.                 if (UserControlCollection.Contains(myGrid29))
  532.                     return;
  533.                
  534.                 Dispatcher.InvokeAsync((() =>
  535.                 {
  536.                     myGrid29 = new System.Windows.Controls.Grid
  537.                     {
  538.                         Name = "MyCustomGrid", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom
  539.                     };
  540.                    
  541.                     System.Windows.Controls.ColumnDefinition column1 = new System.Windows.Controls.ColumnDefinition();
  542.                     System.Windows.Controls.ColumnDefinition column2 = new System.Windows.Controls.ColumnDefinition();
  543.                     System.Windows.Controls.ColumnDefinition column3 = new System.Windows.Controls.ColumnDefinition();
  544.                    
  545.                     myGrid29.ColumnDefinitions.Add(column1);
  546.                     myGrid29.ColumnDefinitions.Add(column2);
  547.                     myGrid29.ColumnDefinitions.Add(column3);
  548.                    
  549.                     youtubeButton = new System.Windows.Controls.Button
  550.                     {
  551.                         Name = "YoutubeButton", Content = "Youtube", Foreground = Brushes.White, Background = Brushes.Red
  552.                     };
  553.                    
  554.                     discordButton = new System.Windows.Controls.Button
  555.                     {
  556.                         Name = "DiscordButton", Content = "Discord", Foreground = Brushes.White, Background = Brushes.RoyalBlue
  557.                     };
  558.                    
  559.                     tradeSaberButton = new System.Windows.Controls.Button
  560.                     {
  561.                         Name = "TradeSaberButton", Content = "TradeSaber", Foreground = Brushes.White, Background = Brushes.DarkOrange
  562.                     };
  563.                    
  564.                     youtubeButton.Click += OnButtonClick;
  565.                     discordButton.Click += OnButtonClick;
  566.                     tradeSaberButton.Click += OnButtonClick;
  567.                    
  568.                     System.Windows.Controls.Grid.SetColumn(youtubeButton, 0);
  569.                     System.Windows.Controls.Grid.SetColumn(discordButton, 1);
  570.                     System.Windows.Controls.Grid.SetColumn(tradeSaberButton, 2);
  571.                    
  572.                     myGrid29.Children.Add(youtubeButton);
  573.                     myGrid29.Children.Add(discordButton);
  574.                     myGrid29.Children.Add(tradeSaberButton);
  575.                    
  576.                     UserControlCollection.Add(myGrid29);
  577.                 }));
  578.             }
  579.         #endregion
  580.             }
  581.            
  582.             else if (State == State.Terminated)
  583.             {
  584.                 #region Chart Trader Termninate
  585.                
  586.                 if (ChartControl != null)
  587.                 {
  588.                     ChartControl.Dispatcher.InvokeAsync(() =>
  589.                     {
  590.                         DisposeWPFControls();
  591.                     });
  592.                 }
  593.                
  594.                 #endregion
  595.                
  596.                 #region Terminate Range/Unlock Buttons
  597.                 /* Removed -> Moved to chart trader
  598.                
  599.                 Dispatcher.InvokeAsync((() =>
  600.                 {
  601.                     if (myGrid != null)
  602.                     {
  603.                         if (lineButton != null)
  604.                         {
  605.                             myGrid.Children.Remove(lineButton);
  606.                             lineButton.Click -= OnButtonClick;
  607.                             lineButton = null;
  608.                         }
  609.                        
  610.                         if (unlockButton != null)
  611.                         {
  612.                             myGrid.Children.Remove(unlockButton);
  613.                             unlockButton.Click -= OnButtonClick;
  614.                             unlockButton = null;
  615.                         }
  616.                        
  617.                     }
  618.                 }));
  619.                     */
  620.                 #endregion
  621.                
  622.                 #region Terminate TradeSaber Socials
  623.            
  624.             if (showSocials)
  625.             {
  626.                 Dispatcher.InvokeAsync((() =>
  627.                 {
  628.                     if (myGrid29 != null)
  629.                     {
  630.                         if (youtubeButton != null)
  631.                         {
  632.                             myGrid29.Children.Remove(youtubeButton);
  633.                             youtubeButton.Click -= OnButtonClick;
  634.                             youtubeButton = null;
  635.                         }
  636.                        
  637.                         if (discordButton != null)
  638.                         {
  639.                             myGrid29.Children.Remove(discordButton);
  640.                             discordButton.Click -= OnButtonClick;
  641.                             discordButton = null;
  642.                         }
  643.                        
  644.                         if (tradeSaberButton != null)
  645.                         {
  646.                             myGrid29.Children.Remove(tradeSaberButton);
  647.                             tradeSaberButton.Click -= OnButtonClick;
  648.                             tradeSaberButton = null;
  649.                         }      
  650.                     }
  651.                 }));
  652.             }
  653.         #endregion
  654.             }
  655.                
  656.         }
  657.        
  658.         #region Button Click Events
  659.    
  660.         #region Buy High Button 1
  661.        
  662.         protected void Button1Click(object sender, RoutedEventArgs e)
  663.         {
  664.             ForceRefresh();
  665.             if(longButtonHL.Content == "BUY HIGH" && Position.MarketPosition == MarketPosition.Flat && customLongClicked == false)
  666.             {
  667.                 if (unlockButtonClicked == false)
  668.                 {
  669.                     countOnce = true;
  670.                 }
  671.                
  672.                 longButtonHL.Content = "Live";
  673.                
  674.                
  675.                 RemoveDrawObject("EntryLine");
  676.                 RemoveDrawObject("StopLine");
  677.                
  678.                 Draw.HorizontalLine(this, "EntryLine", enterLong, Brushes.Green);
  679.                 Draw.HorizontalLine(this, "StopLine", stopLong, Brushes.Red);
  680.                
  681.                 longButtonHLClicked = true;
  682.  
  683.                 return;
  684.             }
  685.            
  686.             if (longButtonHL.Content == "Live")
  687.             {
  688.                 ForceRefresh();
  689.                 longButtonHL.Content = "BUY HIGH";
  690.                 longButtonHLClicked = false;
  691.                
  692.                 RemoveDrawObject("EntryLine");
  693.                 RemoveDrawObject("StopLine");
  694.                
  695.                 return;
  696.             }
  697.         }
  698.        
  699.         #endregion
  700.        
  701.         #region Sell Low Button 2
  702.  
  703.         protected void Button2Click(object sender, RoutedEventArgs e)
  704.         {
  705.             ForceRefresh();
  706.             if(shortButtonHL.Content == "SELL LOW" && Position.MarketPosition == MarketPosition.Flat && customShortClicked == false)
  707.             {
  708.                 if (unlockButtonClicked == false)
  709.                 {
  710.                     countOnce = true;
  711.                 }
  712.                
  713.                 shortButtonHL.Content = "Live";
  714.                
  715.                 RemoveDrawObject("EntryLine");
  716.                 RemoveDrawObject("StopLine");
  717.                
  718.                 Draw.HorizontalLine(this, "EntryLine", enterShort, Brushes.Green);
  719.                 Draw.HorizontalLine(this, "StopLine", stopShort, Brushes.Red);
  720.                
  721.                 shortButtonHLClicked = true;
  722.  
  723.                 return;
  724.             }
  725.            
  726.             if (shortButtonHL.Content == "Live")
  727.             {
  728.                 ForceRefresh();
  729.                 shortButtonHL.Content = "SELL LOW";
  730.                 shortButtonHLClicked = false;
  731.                
  732.                 RemoveDrawObject("EntryLine");
  733.                 RemoveDrawObject("StopLine");
  734.                
  735.                 return;
  736.             }
  737.         }
  738.        
  739.         #endregion
  740.        
  741.         #region Buy Market Button 3
  742.        
  743.         protected void Button3Click(object sender, RoutedEventArgs e)
  744.         {
  745.             ForceRefresh();
  746.             if (Position.MarketPosition == MarketPosition.Flat)
  747.             {
  748.                 countOnce = true;
  749.                 longButtonMarketClicked = true;
  750.             }      
  751.             return;
  752.         }
  753.        
  754.         #endregion
  755.        
  756.         #region Sell Market Button 4
  757.        
  758.         protected void Button4Click(object sender, RoutedEventArgs e)
  759.         {
  760.             ForceRefresh();
  761.             if (Position.MarketPosition == MarketPosition.Flat)
  762.             {
  763.                 countOnce = true;
  764.                 shortButtonMarketClicked = true;
  765.             }      
  766.             return;
  767.         }      
  768.        
  769.         #endregion
  770.        
  771.         #region Custom Long Button 5
  772.        
  773.         protected void Button5Click(object sender, RoutedEventArgs e)
  774.         {
  775.             ForceRefresh();
  776.            
  777.             #region Arm Market
  778.            
  779.             if (armMarket)
  780.             {
  781.                 if (customLong.Content == "Custom Long" && Position.MarketPosition == MarketPosition.Flat && longButtonHLClicked == false )
  782.                 {
  783.                     if (unlockButtonClicked == false)
  784.                     {
  785.                         countOnce = true;
  786.                         Print("unlockButtfalse " + activateMarket);
  787.                     }
  788.                    
  789.                     if (unlockButtonClicked == true)
  790.                     {
  791.                         armMarket = true;
  792.                        
  793.                         Print("unlockButtTrue " + activateMarket);
  794.                     }
  795.                     customLong.Content = "MarketArmed";
  796.                     customLong.Background   = Brushes.Orange;
  797.                     customLongClicked = true;
  798.                    
  799.                     Print(customLongClicked);
  800.                     return;
  801.                 }  
  802.                
  803.                 if (customLong.Content == "MarketArmed" && Position.MarketPosition == MarketPosition.Flat)
  804.                 {
  805.                     customLong.Content = "Custom Long";
  806.                     customLong.Background   = Brushes.MediumSeaGreen;
  807.                     customLongClicked = false;
  808.                     armMarketCount = 0;
  809.                     Print(customLongClicked);
  810.                    
  811.                     return;
  812.                 }  
  813.             }
  814.            
  815.            
  816.             #endregion
  817.            
  818.             #region Close Price
  819.            
  820.             if (enterClosePrice)
  821.             {
  822.                 if (customLong.Content == "Custom Long" && Position.MarketPosition == MarketPosition.Flat && longButtonHLClicked == false)
  823.                 {
  824.                     if (unlockButtonClicked == false)
  825.                     {
  826.                         countOnce = true;
  827.                     }
  828.                    
  829.                     customLong.Content = "Previous Close L";
  830.                     customLong.Background   = Brushes.Orange;
  831.                     customLongClicked = true;
  832.                    
  833.                     Print(customLongClicked);
  834.                     return;
  835.                 }  
  836.                
  837.                 if (customLong.Content == "Previous Close L" && Position.MarketPosition == MarketPosition.Flat)
  838.                 {
  839.                     customLong.Content = "Custom Long";
  840.                     customLong.Background   = Brushes.MediumSeaGreen;
  841.                     customLongClicked = false;
  842.                    
  843.                     Print(customLongClicked);
  844.                     RemoveDrawObject("EntryLine");
  845.                     RemoveDrawObject("StopLine");
  846.                     return;
  847.                 }  
  848.             }
  849.            
  850.            
  851.             #endregion
  852.         }
  853.        
  854.         #endregion
  855.        
  856.         #region Custom Short Button 6
  857.        
  858.         protected void Button6Click(object sender, RoutedEventArgs e)
  859.         {
  860.             ForceRefresh();
  861.            
  862.             #region Arm Market
  863.             if (armMarket)
  864.             {
  865.                 if (customShort.Content == "Custom Short" && Position.MarketPosition == MarketPosition.Flat && shortButtonHLClicked == false)
  866.                 {
  867.                     if (unlockButtonClicked == false)
  868.                     {
  869.                         countOnce = true;
  870.                         Print("unlockButtfalse " + activateMarket);
  871.                     }
  872.                    
  873.                     if (unlockButtonClicked == true)
  874.                     {
  875.                         armMarket = true;
  876.                        
  877.                         Print("unlockButtTrue " + activateMarket);
  878.                     }
  879.                     customShort.Content = "MarketArmed";
  880.                     customShort.Background  = Brushes.Orange;
  881.                     customShortClicked = true;
  882.                     Print(customShortClicked);
  883.                     return;
  884.                 }  
  885.                
  886.                 if (customShort.Content == "MarketArmed" && Position.MarketPosition == MarketPosition.Flat)
  887.                 {
  888.                     customShort.Content = "Custom Short";
  889.                     customShort.Background  = Brushes.IndianRed;
  890.                     customShortClicked = false;
  891.                     armMarketCount = 0;
  892.                     Print(customShortClicked);
  893.                    
  894.                     return;
  895.                 }  
  896.             }
  897.            
  898.            
  899.             #endregion
  900.            
  901.             #region Close Price
  902.            
  903.             if (enterClosePrice)
  904.             {
  905.                 if (customShort.Content == "Custom Short" && Position.MarketPosition == MarketPosition.Flat && shortButtonHLClicked == false)
  906.                 {
  907.                     if (unlockButtonClicked == false)
  908.                 {
  909.                     countOnce = true;
  910.                 }
  911.                     customShort.Content = "Previous Close S";
  912.                     customShort.Background  = Brushes.Orange;
  913.                     customShortClicked = true;
  914.                
  915.                     Print(customShortClicked);
  916.                     return;
  917.                 }  
  918.                
  919.                 if (customShort.Content == "Previous Close S" && Position.MarketPosition == MarketPosition.Flat)
  920.                 {
  921.                     customShort.Content = "Custom Short";
  922.                     customShort.Background  = Brushes.IndianRed;
  923.                     customShortClicked = false;
  924.                     Print(customShortClicked);
  925.                    
  926.                     RemoveDrawObject("EntryLine");
  927.                     RemoveDrawObject("StopLine");
  928.                     return;
  929.                 }  
  930.             }
  931.             #endregion
  932.                                        
  933.         }      
  934.        
  935.         #endregion
  936.        
  937.         #region Close Position Button 7
  938.        
  939.         protected void Button7Click(object sender, RoutedEventArgs e)
  940.         {
  941.             ForceRefresh();
  942.  
  943.             ExitLong(Position.Quantity);
  944.             ExitShort(Position.Quantity);                      
  945.         }      
  946.        
  947.         #endregion //Swapped Position after
  948.        
  949.         #region Breakeven Button 8
  950.        
  951.         protected void Button8Click(object sender, RoutedEventArgs e)
  952.         {
  953.             ForceRefresh();
  954.             if (Position.MarketPosition == MarketPosition.Long && Close[0] > Position.AveragePrice)
  955.             {
  956.                 breakevenButtonClicked = true;
  957.                
  958.                 if (breakevenAreaSetButton)
  959.                 {
  960.                     myFreeBEArea = true;
  961.                 }
  962.                
  963.                 if (breakevenActualSetButton)
  964.                 {
  965.                     myFreeBEActual = true;
  966.                 }  
  967.             }
  968.            
  969.                 if (Position.MarketPosition == MarketPosition.Short && Close[0] < Position.AveragePrice)
  970.             {
  971.                 breakevenButtonClicked = true;
  972.                
  973.                 if (breakevenAreaSetButton)
  974.                 {
  975.                     myFreeBEArea = true;
  976.                 }
  977.                
  978.                 if (breakevenActualSetButton)
  979.                 {
  980.                     myFreeBEActual = true;
  981.                 }  
  982.             }
  983.             return;                        
  984.         }      
  985.        
  986.         #endregion
  987.        
  988.         #region Trail Button 9 // Needs custom added
  989.        
  990.         protected void Button9Click(object sender, RoutedEventArgs e)
  991.         {
  992.             ForceRefresh();
  993.            
  994.             if (candleTrailSetButton)
  995.             {
  996.                 if (trailButton.Content == "Trail Stop" && Position.MarketPosition != MarketPosition.Flat)
  997.                 {
  998.                     trailButton.Content = "Trail Active!";
  999.                     trailButton.Background  = Brushes.Goldenrod;
  1000.                    
  1001.                     myFreeCandleTrail   = true;
  1002.                     trailButtonClicked  = true;
  1003.                     activeTrail         = true;
  1004.                    
  1005.                     Print("trailButtonClicked " + trailButtonClicked);
  1006.                     return;
  1007.                    
  1008.                 }
  1009.                
  1010.                 if (trailButton.Content == "Trail Active!" && Position.MarketPosition != MarketPosition.Flat)
  1011.                 {
  1012.                     trailButton.Content = "Trail Stop";
  1013.                     trailButton.Background  = Brushes.LightGray;
  1014.                    
  1015.                     trailButtonClicked = false;
  1016.                     activeTrail = false;
  1017.                    
  1018.                     return;
  1019.                 }
  1020.             }
  1021.            
  1022.                
  1023.                 if (candleTrailSetButton)
  1024.                 {
  1025.                     myFreeCandleTrail = true;
  1026.                 }
  1027.            
  1028.             return;                        
  1029.         }      
  1030.        
  1031.         #endregion
  1032.        
  1033.         #region Range Line Button 10
  1034.        
  1035.         protected void Button10Click(object sender, RoutedEventArgs e)
  1036.         {
  1037.             ForceRefresh();
  1038.            
  1039.             #region Hide -> Long
  1040.            
  1041.             if (lineButton.Content == "HideRange")
  1042.             {
  1043.                 lineButton.Content = "LongRange";
  1044.                 lineButton.Foreground = Brushes.Black;
  1045.                 lineButton.Background = Brushes.Green;
  1046.                
  1047.                 longLineButtonClicked = true;
  1048.                 shortLineButtonClicked = false;
  1049.                 countOnce = true;
  1050.                
  1051.                 if (AddOffset)
  1052.                     {
  1053.                         RemoveDrawObject("EntryLine");
  1054.                         RemoveDrawObject("StopLine");
  1055.                        
  1056.                         Draw.HorizontalLine(this, "EntryLine", enterLong, Brushes.Green);
  1057.                         Draw.HorizontalLine(this, "StopLine", stopLong, Brushes.Red);
  1058.                     }
  1059.                    
  1060.                     else if (AddOffset == false)
  1061.                     {
  1062.                         RemoveDrawObject("EntryLine");
  1063.                         RemoveDrawObject("StopLine");
  1064.                        
  1065.                         Draw.HorizontalLine(this, "EntryLine", entryAreaLong, Brushes.Green);
  1066.                         Draw.HorizontalLine(this, "StopLine", stopAreaLong, Brushes.Red);
  1067.                     }
  1068.            
  1069.                     return;
  1070.             }
  1071.            
  1072.             #endregion
  1073.            
  1074.             #region Long -> Short
  1075.            
  1076.             if (lineButton.Content == "LongRange")
  1077.             {
  1078.                 lineButton.Content = "ShortRange";
  1079.                 lineButton.Foreground = Brushes.White;
  1080.                 lineButton.Background = Brushes.Red;
  1081.                
  1082.                 longLineButtonClicked = false;
  1083.                 shortLineButtonClicked = true;
  1084.                 countOnce = true;
  1085.                
  1086.                
  1087.                     if (AddOffset)
  1088.                     {
  1089.                         RemoveDrawObject("EntryLine");
  1090.                         RemoveDrawObject("StopLine");
  1091.                        
  1092.                         Draw.HorizontalLine(this, "EntryLine", enterShort, Brushes.Green);
  1093.                         Draw.HorizontalLine(this, "StopLine", stopShort, Brushes.Red);
  1094.                     }
  1095.                    
  1096.                     else if (AddOffset == false)
  1097.                     {
  1098.                         RemoveDrawObject("EntryLine");
  1099.                         RemoveDrawObject("StopLine");
  1100.                        
  1101.                         Draw.HorizontalLine(this, "EntryLine", entryAreaShort, Brushes.Green);
  1102.                         Draw.HorizontalLine(this, "StopLine", stopAreaShort, Brushes.Red);
  1103.                     }
  1104.                    
  1105.                 return;
  1106.             }
  1107.            
  1108.             #endregion
  1109.            
  1110.             #region Short -> Hide
  1111.            
  1112.             if (lineButton.Content == "ShortRange")
  1113.             {
  1114.                 lineButton.Content = "HideRange";
  1115.                 lineButton.Foreground = Brushes.White;
  1116.                 lineButton.Background = Brushes.Black;
  1117.                
  1118.                 RemoveDrawObject("EntryLine");
  1119.                 RemoveDrawObject("StopLine");
  1120.                
  1121.                
  1122.                 longLineButtonClicked = false;
  1123.                 shortLineButtonClicked = false;
  1124.                 countOnce = true;
  1125.                
  1126.                 return;
  1127.             }
  1128.            
  1129.             #endregion
  1130.            
  1131.         }      
  1132.        
  1133.         #endregion
  1134.        
  1135.         #region Unlocked Button 11
  1136.        
  1137.         protected void Button11Click(object sender, RoutedEventArgs e)
  1138.         {
  1139.             ForceRefresh();
  1140.            
  1141.             if (unlockButton.Content == "Unlocked")
  1142.             {
  1143.                 unlockButton.Content = "Locked";
  1144.                 unlockButton.Foreground = Brushes.White;
  1145.                 unlockButton.Background = Brushes.Black;
  1146.                
  1147.                 unlockButtonClicked = true;
  1148.  
  1149.                 return;
  1150.             }
  1151.            
  1152.             if (unlockButton.Content == "Locked")  
  1153.             {
  1154.                 unlockButton.Content = "Unlocked";
  1155.                 unlockButton.Foreground = Brushes.Black;
  1156.                 unlockButton.Background = Brushes.White;
  1157.                
  1158.                 unlockButtonClicked = false;
  1159.                 countOnce = true;
  1160.  
  1161.                 return;
  1162.             }
  1163.         }      
  1164.        
  1165.         #endregion
  1166.        
  1167.         #region EntryLine ++ Button 12
  1168.        
  1169.         protected void Button12Click(object sender, RoutedEventArgs e)
  1170.         {
  1171.             ForceRefresh();
  1172.             CandleLookBackEntry ++;
  1173.             armMarketCount --;
  1174.            
  1175.             countOnce = true;
  1176.             Print("CandleLookBackEntry " + CandleLookBackEntry);
  1177.             return;
  1178.         }      
  1179.        
  1180.         #endregion
  1181.        
  1182.         #region EntryLine -- Button 13
  1183.        
  1184.         protected void Button13Click(object sender, RoutedEventArgs e)
  1185.         {
  1186.             ForceRefresh();
  1187.            
  1188.             if (CandleLookBackEntry > 1)
  1189.             {
  1190.                 CandleLookBackEntry --;
  1191.                 armMarketCount --;
  1192.            
  1193.                 countOnce = true;
  1194.                 Print("CandleLookBackEntry " + CandleLookBackEntry);
  1195.                 return;
  1196.             }                              
  1197.         }      
  1198.        
  1199.         #endregion
  1200.        
  1201.         #region StopLine ++ Button 14
  1202.        
  1203.         protected void Button14Click(object sender, RoutedEventArgs e)
  1204.         {
  1205.             ForceRefresh();
  1206.            
  1207.             if (rrMode)
  1208.             {
  1209.                 CandleLookBackStop ++;
  1210.                 armMarketCount --;
  1211.            
  1212.                 countOnce = true;
  1213.                 Print("CandleLookBackStop " + CandleLookBackStop);
  1214.                 return;
  1215.             }
  1216.            
  1217.             if (tickMode)
  1218.             {
  1219.                 TickOffsetStop ++;
  1220.                
  1221.                 countOnce = true;
  1222.                 Print("Stop From Entry (Ticks) " + TickOffsetStop);
  1223.                 return;
  1224.             }
  1225.            
  1226.         }      
  1227.        
  1228.         #endregion
  1229.        
  1230.         #region StopLine -- Button 15
  1231.        
  1232.         protected void Button15Click(object sender, RoutedEventArgs e)
  1233.         {
  1234.             ForceRefresh();
  1235.            
  1236.             if (rrMode)
  1237.             {
  1238.                 if (CandleLookBackStop > 1)
  1239.                 {
  1240.                     CandleLookBackStop --;
  1241.                     armMarketCount --;
  1242.            
  1243.                     countOnce = true;
  1244.                     Print("CandleLookBackStop " + CandleLookBackStop);
  1245.                     return;
  1246.                 }                          
  1247.             }
  1248.            
  1249.             if (tickMode)
  1250.             {
  1251.                 if ((TickOffsetStop) > 1)
  1252.                 {
  1253.                     TickOffsetStop --;
  1254.                    
  1255.                     countOnce = true;
  1256.                     Print("Stop From Entry (Ticks) " + TickOffsetStop);
  1257.                     return;
  1258.                 }
  1259.             }
  1260.                            
  1261.         }      
  1262.        
  1263.         #endregion
  1264.        
  1265.         #region Display Button 16
  1266.        
  1267.         protected void Button16Click(object sender, RoutedEventArgs e)
  1268.         {
  1269.             ForceRefresh();
  1270.            
  1271.             if (displayButton.Content == "Show Display" && DisplayText == true)
  1272.             {
  1273.                 displayButton.Content = "Hide Display";
  1274.                 displayButton.Foreground = Brushes.White;
  1275.                 displayButton.Background = Brushes.Black;
  1276.                
  1277.                 DisplayText = false;
  1278.                 Print(DisplayText);
  1279.                 RemoveDrawObject("TextBox");
  1280.                
  1281.                 //countOnce = true;
  1282.                 return;
  1283.             }
  1284.            
  1285.             if (displayButton.Content == "Hide Display" && DisplayText == false)
  1286.             {
  1287.                 displayButton.Content = "Show Display";
  1288.                 displayButton.Foreground = Brushes.Black;
  1289.                 displayButton.Background = Brushes.White;
  1290.                
  1291.                 DisplayText = true;
  1292.                 Print(DisplayText);
  1293.                
  1294.                 if (longButtonHLClicked == true || longButtonMarketClicked == true || longLineButtonClicked == true || customLongClicked == true || Position.MarketPosition == MarketPosition.Long)
  1295.                 {
  1296.                     #region Draw Lines / Text Long Offset
  1297.        
  1298.                         #region RR mode
  1299.                        
  1300.                     if (rrMode)
  1301.                     {
  1302.                         if (DisplayText)
  1303.                         {
  1304.                             Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterLong, 2) + ("("+CandleLookBackEntry+")")
  1305.                             + "\nStop Line: " + Math.Round(stopLong, 2) + ("("+CandleLookBackStop+")")
  1306.                            
  1307.                             + "\n\nMax Loss($): " + MaxLossPerTrade
  1308.                             + "\nRange($): " + LongValuesOffset
  1309.                             + "\nRange(Ticks): " + LongValuesOffset / TickSize
  1310.                             + "\nPosition Size: " + positionSizeLong   
  1311.                        
  1312.                             ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  1313.                         }
  1314.                     }
  1315.                        
  1316.                         #endregion
  1317.                    
  1318.                         #region Tick Mode
  1319.                    
  1320.                     if (tickMode)
  1321.                     {
  1322.                         if (DisplayText)
  1323.                         {
  1324.                             Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterLong, 2) + ("("+CandleLookBackEntry+")")
  1325.                             + "\nStop Line: " + Math.Round(enterLong - candleBarOffsetStop, 2) + ("("+candleBarOffsetStop / TickSize+")")
  1326.                            
  1327.                             + "\n\nMax Loss($): " + MaxLossPerTrade
  1328.                             + "\nRange($): " + candleBarOffsetStop
  1329.                             + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  1330.                             + "\nPosition Size: " + positionSizeLong   
  1331.                        
  1332.                             ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  1333.                         }
  1334.                     }
  1335.                
  1336.                     #endregion
  1337.                    
  1338.                     #endregion
  1339.                 }
  1340.                
  1341.                 if (shortButtonHLClicked == true || shortButtonMarketClicked == true || shortLineButtonClicked == true || customShortClicked == true || Position.MarketPosition == MarketPosition.Short)
  1342.                 {
  1343.                     #region Draw Lines / Text Short Offset
  1344.                
  1345.                         #region RR Mode
  1346.                        
  1347.                 if (rrMode)
  1348.                 {
  1349.                     if (DisplayText)
  1350.                     {
  1351.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterShort, 2) + ("("+CandleLookBackEntry+")")
  1352.                         + "\nStop Line: " + Math.Round(stopShort, 2) + ("("+CandleLookBackStop+")")
  1353.                            
  1354.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  1355.                         + "\nRange($): " + ShortValuesOffset
  1356.                         + "\nRange(Ticks): " + ShortValuesOffset / TickSize
  1357.                         + "\nPosition Size: " + positionSizeShort  
  1358.                        
  1359.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  1360.                     }
  1361.                    
  1362.                 }
  1363.                        
  1364.                     #endregion
  1365.                    
  1366.                         #region Tick Mode
  1367.                        
  1368.                 if (tickMode)
  1369.                 {                  
  1370.                     if (DisplayText)
  1371.                     {
  1372.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterShort, 2) + ("("+CandleLookBackEntry+")")
  1373.                         + "\nStop Line: " + Math.Round(enterShort + candleBarOffsetStop, 2) + ("("+candleBarOffsetStop / TickSize+")")
  1374.                            
  1375.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  1376.                         + "\nRange($): " + candleBarOffsetStop
  1377.                         + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  1378.                         + "\nPosition Size: " + positionSizeShort  
  1379.                        
  1380.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  1381.                     }
  1382.                    
  1383.                 }
  1384.                        
  1385.                     #endregion
  1386.                    
  1387.                 #endregion
  1388.                 }
  1389.                
  1390.                 //countOnce = true;
  1391.                 return;
  1392.             }
  1393.                                                
  1394.         }      
  1395.        
  1396.         #endregion
  1397.        
  1398.         #region Fib Button 17
  1399.        
  1400.         protected void Button17Click(object sender, RoutedEventArgs e)
  1401.         {
  1402.             ForceRefresh();
  1403.            
  1404.             if (fibButton.Content == "HideFib")
  1405.             {
  1406.                 fibButton.Content = "ShowFib";
  1407.                 fibButton.Foreground = Brushes.Black;
  1408.                 fibButton.Background = Brushes.White;
  1409.                
  1410.                 fibButtonClicked = true;
  1411.                
  1412.                 if (fibButtonClicked && Position.MarketPosition == MarketPosition.Long)
  1413.                 {
  1414.                     if (rrMode)
  1415.                     {
  1416.                         Draw.FibonacciRetracements(this, "FibLong", false, fibCount, setStopLong, fibCount, enterLong);
  1417.                     }
  1418.                
  1419.                     if (tickMode)
  1420.                     {
  1421.                         Draw.FibonacciRetracements(this, "FibLong", false, fibCount, Position.AveragePrice - candleBarOffsetStop, fibCount, Position.AveragePrice);
  1422.                     }
  1423.                 }
  1424.            
  1425.             if (fibButtonClicked && Position.MarketPosition == MarketPosition.Short)
  1426.             {
  1427.                 if (rrMode)
  1428.                 {
  1429.                     Draw.FibonacciRetracements(this, "FibShort", false, fibCount, setStopShort, fibCount, enterShort);
  1430.                 }
  1431.                
  1432.                 if (tickMode)
  1433.                 {
  1434.                     Draw.FibonacciRetracements(this, "FibShort", false, fibCount, Position.AveragePrice + candleBarOffsetStop, fibCount, Position.AveragePrice);
  1435.                 }
  1436.             }
  1437.                    
  1438.                 return;
  1439.             }
  1440.            
  1441.             if (fibButton.Content == "ShowFib")
  1442.             {
  1443.                 fibButton.Content = "HideFib";
  1444.                 fibButton.Foreground = Brushes.White;
  1445.                 fibButton.Background = Brushes.Black;
  1446.                
  1447.                 fibButtonClicked = false;
  1448.                
  1449.                 if ((!fibButtonClicked) || (Position.MarketPosition == MarketPosition.Flat))
  1450.                
  1451.                 {
  1452.                     RemoveDrawObject("FibLong");
  1453.                     RemoveDrawObject("FibShort");
  1454.                 }
  1455.                
  1456.                 return;
  1457.             }
  1458.         }      
  1459.        
  1460.         #endregion
  1461.        
  1462.         #endregion
  1463.        
  1464.         #region Button Controls
  1465.        
  1466.         protected void CreateWPFControls()
  1467.         {
  1468.             #region Create WPF Controls
  1469.            
  1470.                 #region Button Grid
  1471.            
  1472.             chartWindow             = Window.GetWindow(ChartControl.Parent) as Gui.Chart.Chart;
  1473.  
  1474.             // if not added to a chart, do nothing
  1475.             if (chartWindow == null)
  1476.                 return;
  1477.  
  1478.             // this is the entire chart trader area grid
  1479.             chartTraderGrid         = (chartWindow.FindFirst("ChartWindowChartTraderControl") as Gui.Chart.ChartTrader).Content as System.Windows.Controls.Grid;
  1480.  
  1481.             // this grid contains the existing chart trader buttons
  1482.             chartTraderButtonsGrid  = chartTraderGrid.Children[0] as System.Windows.Controls.Grid;
  1483.  
  1484.             // this grid is to organize stuff below
  1485.             lowerButtonsGrid = new System.Windows.Controls.Grid();
  1486.  
  1487.             //Makes 2 Columns
  1488.             lowerButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition());        
  1489.             lowerButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition());    
  1490.            
  1491.             //Makes Rows
  1492.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //Buy High / Sell Low
  1493.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //Market
  1494.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //Custom
  1495.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //Close Position
  1496.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //Management
  1497.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //EntryLines
  1498.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //EntryLine +-
  1499.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //StopLine +-
  1500.             lowerButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() ); //Display / Fib
  1501.            
  1502.             addedRow    = new System.Windows.Controls.RowDefinition() { Height = new GridLength(240) };
  1503.                
  1504.  
  1505.             // this style (provided by NinjaTrader_MichaelM) gives the correct default minwidth (and colors) to make buttons appear like chart trader buttons
  1506.             Style basicButtonStyle  = Application.Current.FindResource("BasicEntryButton") as Style;
  1507.            
  1508.             #endregion
  1509.  
  1510.                 #region Button Content
  1511.            
  1512.                 longButtonHL = new System.Windows.Controls.Button()//1
  1513.                 {      
  1514.                     Name            = "longButtonHL",
  1515.                     Content         = "BUY HIGH",
  1516.                     Height          = 25,
  1517.                     Margin          = new Thickness(5,0,5,0),
  1518.                     Padding         = new Thickness(0,0,0,0),
  1519.                     Style           = basicButtonStyle
  1520.                        
  1521.                 };             
  1522.  
  1523.                 shortButtonHL = new System.Windows.Controls.Button()//2
  1524.                 {      
  1525.                     Name            = "shortButtonHL",
  1526.                     Content         = "SELL LOW",
  1527.                     Height          = 25,
  1528.                     Margin          = new Thickness(5,0,5,0),
  1529.                     Padding         = new Thickness(0,0,0,0),
  1530.                     Style           = basicButtonStyle
  1531.                 };     
  1532.                
  1533.                 longButtonMarket = new System.Windows.Controls.Button()//3
  1534.                 {      
  1535.                    
  1536.                     Content         = string.Format("Buy Market"),
  1537.                     Height          = 25,
  1538.                     Margin          = new Thickness(5,0,5,0),
  1539.                     Padding         = new Thickness(0,0,0,0),
  1540.                     Style           = basicButtonStyle
  1541.                 };     
  1542.                
  1543.                 shortButtonMarket = new System.Windows.Controls.Button()//4
  1544.                 {      
  1545.                    
  1546.                     Content         = string.Format("Short Market"),
  1547.                     Height          = 25,
  1548.                     Margin          = new Thickness(5,0,5,0),
  1549.                     Padding         = new Thickness(0,0,0,0),
  1550.                     Style           = basicButtonStyle
  1551.                 };     
  1552.                
  1553.                 customLong = new System.Windows.Controls.Button()//5
  1554.                 {      
  1555.                    
  1556.                     Content         = "Custom Long",
  1557.                     Height          = 25,
  1558.                     Margin          = new Thickness(5,0,5,0),
  1559.                     Padding         = new Thickness(0,0,0,0),
  1560.                     Style           = basicButtonStyle
  1561.                 };     
  1562.                
  1563.                 customShort = new System.Windows.Controls.Button()//6
  1564.                 {      
  1565.                    
  1566.                     Content         = "Custom Short",
  1567.                     Height          = 25,
  1568.                     Margin          = new Thickness(5,0,5,0),
  1569.                     Padding         = new Thickness(0,0,0,0),
  1570.                     Style           = basicButtonStyle
  1571.                 };     
  1572.                
  1573.                 myButton7 = new System.Windows.Controls.Button()//7
  1574.                 {      
  1575.                    
  1576.                     Content         = string.Format("Close Position"),
  1577.                     Height          = 25,
  1578.                     Margin          = new Thickness(5,0,5,0),
  1579.                     Padding         = new Thickness(0,0,0,0),
  1580.                     Style           = basicButtonStyle
  1581.                 };     
  1582.                
  1583.                 breakevenButton = new System.Windows.Controls.Button()//8
  1584.                 {      
  1585.                    
  1586.                     Content         = string.Format("BreakEven"),
  1587.                     Height          = 25,
  1588.                     Margin          = new Thickness(5,0,5,0),
  1589.                     Padding         = new Thickness(0,0,0,0),
  1590.                     Style           = basicButtonStyle
  1591.                 };     
  1592.                
  1593.                 trailButton = new System.Windows.Controls.Button()//9
  1594.                 {      
  1595.                    
  1596.                     Content         = "Trail Stop",
  1597.                     Height          = 25,
  1598.                     Margin          = new Thickness(5,0,5,0),
  1599.                     Padding         = new Thickness(0,0,0,0),
  1600.                     Style           = basicButtonStyle
  1601.                 };     
  1602.                
  1603.                 lineButton = new System.Windows.Controls.Button()//10
  1604.                 {      
  1605.                    
  1606.                     Content         = "HideRange",
  1607.                     Height          = 25,
  1608.                     Margin          = new Thickness(5,0,5,0),
  1609.                     Padding         = new Thickness(0,0,0,0),
  1610.                     Style           = basicButtonStyle
  1611.                 };     
  1612.                
  1613.                 unlockButton = new System.Windows.Controls.Button()//11
  1614.                 {      
  1615.                    
  1616.                     Content         = "Unlocked",
  1617.                     Height          = 25,
  1618.                     Margin          = new Thickness(5,0,5,0),
  1619.                     Padding         = new Thickness(0,0,0,0),
  1620.                     Style           = basicButtonStyle
  1621.                 };     
  1622.            
  1623.                 myButton12 = new System.Windows.Controls.Button()//12
  1624.                 {      
  1625.                    
  1626.                     Content         = string.Format("EntryLine ++"),
  1627.                     Height          = 25,
  1628.                     Margin          = new Thickness(5,0,5,0),
  1629.                     Padding         = new Thickness(0,0,0,0),
  1630.                     Style           = basicButtonStyle
  1631.                 };     
  1632.                
  1633.                 myButton13 = new System.Windows.Controls.Button()//13
  1634.                 {      
  1635.                    
  1636.                     Content         = string.Format("EntryLine --"),
  1637.                     Height          = 25,
  1638.                     Margin          = new Thickness(5,0,5,0),
  1639.                     Padding         = new Thickness(0,0,0,0),
  1640.                     Style           = basicButtonStyle
  1641.                 };     
  1642.                
  1643.                 myButton14 = new System.Windows.Controls.Button()//14
  1644.                 {      
  1645.                    
  1646.                     Content         = string.Format("StopLine ++"),
  1647.                     Height          = 25,
  1648.                     Margin          = new Thickness(5,0,5,0),
  1649.                     Padding         = new Thickness(0,0,0,0),
  1650.                     Style           = basicButtonStyle
  1651.                 };     
  1652.                
  1653.                 myButton15 = new System.Windows.Controls.Button()//15
  1654.                 {      
  1655.                    
  1656.                     Content         = string.Format("StopLine --"),
  1657.                     Height          = 25,
  1658.                     Margin          = new Thickness(5,0,5,0),
  1659.                     Padding         = new Thickness(0,0,0,0),
  1660.                     Style           = basicButtonStyle
  1661.                 };     
  1662.                
  1663.                
  1664.                
  1665.                 if (DisplayText)
  1666.                 {
  1667.                     displayButton = new System.Windows.Controls.Button()//16
  1668.                     {      
  1669.                        
  1670.                         Content         = "Show Display",
  1671.                         Height          = 25,
  1672.                         Margin          = new Thickness(5,0,5,0),
  1673.                         Padding         = new Thickness(0,0,0,0),
  1674.                         Style           = basicButtonStyle
  1675.                     };     
  1676.                 }
  1677.                
  1678.                 if (DisplayText == false)
  1679.                 {
  1680.                     displayButton = new System.Windows.Controls.Button()//16 (2)
  1681.                     {      
  1682.                        
  1683.                         Content         = "Hide Display",
  1684.                         Height          = 25,
  1685.                         Margin          = new Thickness(5,0,5,0),
  1686.                         Padding         = new Thickness(0,0,0,0),
  1687.                         Style           = basicButtonStyle
  1688.                     };     
  1689.                 }
  1690.                
  1691.                
  1692.                
  1693.                 fibButton = new System.Windows.Controls.Button()//17
  1694.                 {      
  1695.                    
  1696.                     Content         = "HideFib",
  1697.                     Height          = 25,
  1698.                     Margin          = new Thickness(5,0,5,0),
  1699.                     Padding         = new Thickness(0,0,0,0),
  1700.                     Style           = basicButtonStyle
  1701.                 };     
  1702.                 #endregion
  1703.                
  1704.                 #region Button Colors
  1705.                    
  1706.                 //1. Buy High
  1707.                     longButtonHL.Background = Brushes.ForestGreen;
  1708.                     longButtonHL.BorderBrush    = Brushes.Black;
  1709.                     longButtonHL.Foreground    = Brushes.Black;
  1710.                     longButtonHL.BorderThickness = new Thickness(2.0);
  1711.                     longButtonHL.IsEnabled = true;
  1712.  
  1713.                 //2. Sell Low
  1714.                     shortButtonHL.Background    = Brushes.Firebrick;
  1715.                     shortButtonHL.BorderBrush   = Brushes.Black;   
  1716.                     shortButtonHL.Foreground    = Brushes.White;   
  1717.                     shortButtonHL.BorderThickness = new Thickness(2.0);        
  1718.                
  1719.                 //3. Long Market
  1720.                     longButtonMarket.Background = Brushes.MediumSeaGreen;
  1721.                     longButtonMarket.BorderBrush    = Brushes.Black;   
  1722.                     longButtonMarket.Foreground    = Brushes.Black;
  1723.                     longButtonMarket.BorderThickness = new Thickness(2.0);             
  1724.                
  1725.                 //.4 Short Market
  1726.                     shortButtonMarket.Background    = Brushes.IndianRed;
  1727.                     shortButtonMarket.BorderBrush   = Brushes.Black;   
  1728.                     shortButtonMarket.Foreground    = Brushes.White;   
  1729.                     shortButtonMarket.BorderThickness = new Thickness(2.0);    
  1730.                
  1731.                 //5. Custom Long
  1732.                     customLong.Background   = Brushes.MediumSeaGreen;
  1733.                     customLong.BorderBrush  = Brushes.Black;   
  1734.                     customLong.Foreground    = Brushes.Black;  
  1735.                     customLong.BorderThickness = new Thickness(2.0);   
  1736.                
  1737.                 //6. Custom Short
  1738.                     customShort.Background  = Brushes.IndianRed;
  1739.                     customShort.BorderBrush = Brushes.Black;   
  1740.                     customShort.Foreground    = Brushes.White; 
  1741.                     customShort.BorderThickness = new Thickness(2.0);  
  1742.                
  1743.                 //7. Close Position - Swithced Position after
  1744.                     myButton7.Background    = Brushes.DarkOrange;
  1745.                     myButton7.BorderBrush   = Brushes.Black;   
  1746.                     myButton7.Foreground    = Brushes.Black;   
  1747.                     myButton7.BorderThickness = new Thickness(2.0);
  1748.                
  1749.                 //8. Breakeven
  1750.                     breakevenButton.Background  = Brushes.LightGray;
  1751.                     breakevenButton.BorderBrush = Brushes.Black;   
  1752.                     breakevenButton.Foreground    = Brushes.DarkGreen; 
  1753.                     breakevenButton.BorderThickness = new Thickness(2.0);
  1754.                
  1755.                 //9. Trail
  1756.                     trailButton.Background  = Brushes.LightGray;
  1757.                     trailButton.BorderBrush = Brushes.Black;   
  1758.                     trailButton.Foreground    = Brushes.DarkGreen; 
  1759.                     trailButton.BorderThickness = new Thickness(2.0);
  1760.                
  1761.                 //10. Line
  1762.                     lineButton.Background   = Brushes.Black;
  1763.                     lineButton.BorderBrush  = Brushes.Black;   
  1764.                     lineButton.Foreground    = Brushes.White;  
  1765.                     lineButton.BorderThickness = new Thickness(2.0);
  1766.                
  1767.                 //11. Unlocked
  1768.                     unlockButton.Background = Brushes.White;
  1769.                     unlockButton.BorderBrush    = Brushes.Black;   
  1770.                     unlockButton.Foreground    = Brushes.Black;
  1771.                     unlockButton.BorderThickness = new Thickness(2.0);
  1772.                
  1773.                 //12. EntryLine ++
  1774.                     myButton12.Background   = Brushes.PaleGreen;
  1775.                     myButton12.BorderBrush  = Brushes.Black;   
  1776.                     myButton12.Foreground    = Brushes.DarkGreen;  
  1777.                     myButton12.BorderThickness = new Thickness(2.0);
  1778.                
  1779.                 //13. EntryLine --
  1780.                     myButton13.Background   = Brushes.PaleGreen;
  1781.                     myButton13.BorderBrush  = Brushes.Black;   
  1782.                     myButton13.Foreground    = Brushes.Firebrick;  
  1783.                     myButton13.BorderThickness = new Thickness(2.0);
  1784.                
  1785.                 //14. StopLine ++
  1786.                     myButton14.Background   = Brushes.LightSalmon;
  1787.                     myButton14.BorderBrush  = Brushes.Black;   
  1788.                     myButton14.Foreground    = Brushes.DarkGreen;  
  1789.                     myButton14.BorderThickness = new Thickness(2.0);
  1790.                
  1791.                 //15. StopLine --
  1792.                     myButton15.Background   = Brushes.LightSalmon;
  1793.                     myButton15.BorderBrush  = Brushes.Black;   
  1794.                     myButton15.Foreground    = Brushes.Firebrick;  
  1795.                     myButton15.BorderThickness = new Thickness(2.0);
  1796.                
  1797.                 //16.
  1798.                 if (DisplayText)
  1799.                 {
  1800.                     displayButton.Background    = Brushes.White;
  1801.                     displayButton.BorderBrush   = Brushes.Black;   
  1802.                     displayButton.Foreground    = Brushes.Black;   
  1803.                     displayButton.BorderThickness = new Thickness(2.0);
  1804.                 }
  1805.                
  1806.                 if (DisplayText == false)
  1807.                 {
  1808.                     displayButton.Background    = Brushes.Black;
  1809.                     displayButton.BorderBrush   = Brushes.Black;   
  1810.                     displayButton.Foreground    = Brushes.White;   
  1811.                     displayButton.BorderThickness = new Thickness(2.0);
  1812.                 }
  1813.                    
  1814.                
  1815.                 //17.
  1816.                     fibButton.Background    = Brushes.Black;
  1817.                     fibButton.BorderBrush   = Brushes.Black;   
  1818.                     fibButton.Foreground    = Brushes.White;   
  1819.                     fibButton.BorderThickness = new Thickness(2.0);
  1820.                
  1821.            
  1822.             #endregion 
  1823.                
  1824.                 #region Button Click
  1825.                
  1826.                     longButtonHL.Click +=  Button1Click;
  1827.                     shortButtonHL.Click +=  Button2Click;
  1828.                    
  1829.                     longButtonMarket.Click +=  Button3Click;
  1830.                     shortButtonMarket.Click +=  Button4Click;  
  1831.                
  1832.            
  1833.                     customLong.Click +=  Button5Click;
  1834.                     customShort.Click +=  Button6Click;
  1835.                
  1836.                     myButton7.Click +=  Button7Click;
  1837.                
  1838.                     breakevenButton.Click +=  Button8Click;
  1839.                     trailButton.Click +=  Button9Click;
  1840.                
  1841.                     lineButton.Click +=  Button10Click;
  1842.                     unlockButton.Click +=  Button11Click;
  1843.                
  1844.                     myButton12.Click +=  Button12Click;
  1845.                
  1846.                     myButton13.Click +=  Button13Click;
  1847.                
  1848.                     myButton14.Click +=  Button14Click;
  1849.                     myButton15.Click +=  Button15Click;
  1850.                
  1851.                     displayButton.Click +=  Button16Click;
  1852.                     fibButton.Click +=  Button17Click;
  1853.                
  1854.                 #endregion
  1855.                
  1856.                 #region Button Location
  1857.                
  1858.                     //High Low             
  1859.                     System.Windows.Controls.Grid.SetColumn(longButtonHL, 0);               
  1860.                     System.Windows.Controls.Grid.SetColumn(shortButtonHL, 1);
  1861.                    
  1862.                     //Market
  1863.                     System.Windows.Controls.Grid.SetColumn(longButtonMarket, 0);               
  1864.                     System.Windows.Controls.Grid.SetRow(longButtonMarket, 1);                  
  1865.                            
  1866.                     System.Windows.Controls.Grid.SetColumn(shortButtonMarket, 1);              
  1867.                     System.Windows.Controls.Grid.SetRow(shortButtonMarket, 1);                     
  1868.                
  1869.                     //Custom
  1870.                     System.Windows.Controls.Grid.SetColumn(customLong, 0);             
  1871.                     System.Windows.Controls.Grid.SetRow(customLong, 2);
  1872.                
  1873.                     System.Windows.Controls.Grid.SetColumn(customShort, 1);            
  1874.                     System.Windows.Controls.Grid.SetRow(customShort, 2);
  1875.                
  1876.                     //Breakeven
  1877.                     System.Windows.Controls.Grid.SetColumn(breakevenButton, 0);            
  1878.                     System.Windows.Controls.Grid.SetRow(breakevenButton, 3);
  1879.                
  1880.                     //Trail
  1881.                     System.Windows.Controls.Grid.SetColumn(trailButton, 1);            
  1882.                     System.Windows.Controls.Grid.SetRow(trailButton, 3);
  1883.                
  1884.                     //Close
  1885.                     System.Windows.Controls.Grid.SetColumn(myButton7, 1);              
  1886.                     System.Windows.Controls.Grid.SetRow(myButton7, 4);
  1887.                
  1888.                     //Range
  1889.                     System.Windows.Controls.Grid.SetColumn(lineButton, 0);             
  1890.                     System.Windows.Controls.Grid.SetRow(lineButton, 5);
  1891.                
  1892.                     //Unlocked
  1893.                     System.Windows.Controls.Grid.SetColumn(unlockButton, 1);               
  1894.                     System.Windows.Controls.Grid.SetRow(unlockButton, 5);
  1895.                
  1896.                     //EntryLine ++
  1897.                     System.Windows.Controls.Grid.SetColumn(myButton12, 0);             
  1898.                     System.Windows.Controls.Grid.SetRow(myButton12, 6);
  1899.                    
  1900.                     //EntryLine --
  1901.                     System.Windows.Controls.Grid.SetColumn(myButton13, 1);             
  1902.                     System.Windows.Controls.Grid.SetRow(myButton13, 6);
  1903.                
  1904.                     //StopLine ++
  1905.                     System.Windows.Controls.Grid.SetColumn(myButton14, 0);             
  1906.                     System.Windows.Controls.Grid.SetRow(myButton14, 7);
  1907.                
  1908.                     //StopLine --
  1909.                     System.Windows.Controls.Grid.SetColumn(myButton15, 1);             
  1910.                     System.Windows.Controls.Grid.SetRow(myButton15, 7);
  1911.                
  1912.                     //Display
  1913.                     System.Windows.Controls.Grid.SetColumn(displayButton, 0);              
  1914.                     System.Windows.Controls.Grid.SetRow(displayButton, 8);
  1915.                
  1916.                     //Fib
  1917.                     System.Windows.Controls.Grid.SetColumn(fibButton, 1);              
  1918.                     System.Windows.Controls.Grid.SetRow(fibButton, 8);
  1919.                
  1920.                 #endregion
  1921.                
  1922.                 #region Add Buttons
  1923.                
  1924.                     lowerButtonsGrid.Children.Add(longButtonHL);                           
  1925.                     lowerButtonsGrid.Children.Add(shortButtonHL);
  1926.                
  1927.                
  1928.                     lowerButtonsGrid.Children.Add(longButtonMarket);
  1929.                     lowerButtonsGrid.Children.Add(shortButtonMarket);              
  1930.                
  1931.                     lowerButtonsGrid.Children.Add(customLong);
  1932.                     lowerButtonsGrid.Children.Add(customShort);
  1933.                
  1934.                     lowerButtonsGrid.Children.Add(myButton7);
  1935.                
  1936.                     lowerButtonsGrid.Children.Add(breakevenButton);
  1937.                
  1938.                     lowerButtonsGrid.Children.Add(trailButton);
  1939.                
  1940.                     lowerButtonsGrid.Children.Add(lineButton);
  1941.                     lowerButtonsGrid.Children.Add(unlockButton);
  1942.                
  1943.                     lowerButtonsGrid.Children.Add(myButton12);
  1944.                     lowerButtonsGrid.Children.Add(myButton13);
  1945.                
  1946.                     lowerButtonsGrid.Children.Add(myButton14);
  1947.                     lowerButtonsGrid.Children.Add(myButton15);
  1948.                
  1949.                     lowerButtonsGrid.Children.Add(displayButton);
  1950.                     lowerButtonsGrid.Children.Add(fibButton);
  1951.                
  1952.                 #endregion
  1953.                
  1954.             if (TabSelected())
  1955.                 InsertWPFControls();
  1956.  
  1957.             chartWindow.MainTabControl.SelectionChanged += TabChangedHandler;
  1958.            
  1959.             #endregion
  1960.         }
  1961.    
  1962.         public void DisposeWPFControls()
  1963.         {
  1964.             #region Dispose
  1965.            
  1966.             if (chartWindow != null)
  1967.                 chartWindow.MainTabControl.SelectionChanged -= TabChangedHandler;
  1968.  
  1969.             if (longButtonHL != null)
  1970.                 longButtonHL.Click -= Button1Click;
  1971.  
  1972.             if (shortButtonHL != null)
  1973.                 shortButtonHL.Click -= Button2Click;
  1974.            
  1975.             if (longButtonMarket != null)
  1976.                 longButtonMarket.Click -= Button3Click;
  1977.            
  1978.             if (shortButtonMarket != null)
  1979.                 shortButtonMarket.Click -= Button4Click;
  1980.            
  1981.             if (customLong != null)
  1982.                 customLong.Click -= Button5Click;
  1983.            
  1984.             if (customShort != null)
  1985.                 customShort.Click -= Button6Click;
  1986.            
  1987.             if (myButton7 != null)
  1988.                 myButton7.Click -= Button7Click;
  1989.            
  1990.             if (breakevenButton != null)
  1991.                 breakevenButton.Click -= Button8Click;
  1992.                
  1993.             if (trailButton != null)
  1994.                 trailButton.Click -= Button9Click; 
  1995.            
  1996.             if (lineButton != null)
  1997.                 lineButton.Click -= Button10Click;
  1998.            
  1999.             if (unlockButton != null)
  2000.                 unlockButton.Click -= Button11Click;
  2001.            
  2002.             if (myButton12 != null)
  2003.                 myButton12.Click -= Button12Click;
  2004.            
  2005.             if (myButton13 != null)
  2006.                 myButton13.Click -= Button13Click;
  2007.            
  2008.             if (myButton14 != null)
  2009.                 myButton14.Click -= Button14Click;
  2010.            
  2011.             if (myButton15 != null)
  2012.                 myButton15.Click -= Button15Click;
  2013.            
  2014.             if (displayButton != null)
  2015.                 displayButton.Click -= Button16Click;
  2016.            
  2017.             if (fibButton != null)
  2018.                 fibButton.Click -= Button17Click;
  2019.  
  2020.             RemoveWPFControls();
  2021.            
  2022.             #endregion
  2023.         }
  2024.        
  2025.         public void InsertWPFControls()
  2026.         {
  2027.             #region Insert WPF
  2028.            
  2029.             if (panelActive)
  2030.                 return;
  2031.            
  2032.             // add a new row (addedRow) for our lowerButtonsGrid below the ask and bid prices and pnl display          
  2033.             chartTraderGrid.RowDefinitions.Add(addedRow);
  2034.             System.Windows.Controls.Grid.SetRow(lowerButtonsGrid, (chartTraderGrid.RowDefinitions.Count - 1));
  2035.             chartTraderGrid.Children.Add(lowerButtonsGrid);
  2036.  
  2037.             panelActive = true;
  2038.            
  2039.             #endregion
  2040.         }
  2041.        
  2042.         #endregion
  2043.        
  2044.    
  2045.         protected override void OnBarUpdate()
  2046.         {
  2047.             if (State != State.Realtime )
  2048.                 return;
  2049.            
  2050.             if (countOnce && Position.MarketPosition == MarketPosition.Flat && unlockButtonClicked == false)
  2051.             {
  2052.                
  2053.                 if (CandleRange == false)
  2054.                 {
  2055.                     #region Entry Offset
  2056.                    
  2057.             if (longButtonHLClicked == true || longButtonMarketClicked == true || longLineButtonClicked == true || (customLongClicked == true && enterClosePrice == false)
  2058.                 || shortButtonHLClicked == true || shortButtonMarketClicked == true || shortLineButtonClicked == true || (customShortClicked == true && enterClosePrice == false)
  2059.                 )              
  2060.             {
  2061.                 //HL
  2062.                 entryAreaLong       = High[CandleLookBackEntry];
  2063.                 entryAreaShort      = Low[CandleLookBackEntry];
  2064.             }
  2065.                
  2066.             if ((customLongClicked || customShortClicked) && enterClosePrice == true)
  2067.             {
  2068.                 //Previous Close Price 
  2069.                 entryAreaLong   = Close[CandleLookBackEntry];
  2070.                 entryAreaShort  = Close[CandleLookBackEntry];  
  2071.             }
  2072.                
  2073.                    
  2074.             //Adds offset to your entry area. Gives user customization.
  2075.             percentageCalcEntry     = ((High[CandleLookBackEntry] - Low[CandleLookBackEntry]) * PercentageOffsetEntry);
  2076.             priceCalcEntry          = PriceOffsetEntry;
  2077.             tickCalcEntry           = TickOffsetEntry * TickSize;
  2078.            
  2079.             //Picks the highest of the 3 numbers
  2080.             candleBarOffsetEntry = Math.Max(percentageCalcEntry, Math.Max(priceCalcEntry, tickCalcEntry));
  2081.            
  2082.             //Add both of them together to define final entry point
  2083.             enterLong = entryAreaLong + candleBarOffsetEntry;
  2084.             enterShort = entryAreaShort - candleBarOffsetEntry;
  2085.            
  2086.            
  2087.             #region Entry Prints
  2088.            
  2089.             if (SystemPrint)
  2090.             {
  2091.                 if (EntryPrints)
  2092.                 {
  2093.                     Print("percentageCalcEntry " + percentageCalcEntry + " " + Time[CandleLookBackEntry]);
  2094.                     Print("priceCalcEntry " + priceCalcEntry + " " + Time[CandleLookBackEntry]);
  2095.                     Print("tickCalcEntry " + tickCalcEntry + " " + Time[CandleLookBackEntry]);
  2096.                    
  2097.                     Print("candleBarOffsetEntry " + candleBarOffsetEntry + " " + Time[CandleLookBackEntry]);
  2098.                    
  2099.                     Print("enterLong " + enterLong + " " + Time[CandleLookBackEntry]);
  2100.                     Print("enterShort " + enterShort + " " + Time[CandleLookBackEntry]);
  2101.                 }
  2102.             }
  2103.             #endregion
  2104.            
  2105.             #endregion
  2106.            
  2107.                     #region Stop Offset
  2108.            
  2109.             //Define what area you will set a stop (If it is based on the chart)
  2110.             stopAreaLong        = Low[CandleLookBackStop];
  2111.             stopAreaShort       = High[CandleLookBackStop];
  2112.            
  2113.             //Adds offset to your stop area. Gives user customization.
  2114.             percentageCalcStop      = ((High[CandleLookBackStop] - Low[CandleLookBackStop]) * PercentageOffsetStop);
  2115.             priceCalcStop           = PriceOffsetStop;
  2116.             tickCalcStop            = TickOffsetStop * TickSize;
  2117.            
  2118.             //Picks the highest of the 3 numbers
  2119.             candleBarOffsetStop = Math.Max(percentageCalcStop, Math.Max(priceCalcStop, tickCalcStop));
  2120.            
  2121.             //Add both of them together to define final stop point
  2122.             stopLong = stopAreaLong - candleBarOffsetStop;
  2123.             stopShort = stopAreaShort + candleBarOffsetStop;
  2124.            
  2125.             #region StopPrints
  2126.            
  2127.             if (SystemPrint)
  2128.             {
  2129.                 if (StopPrints)
  2130.                 {
  2131.                     Print("percentageCalcStop " + percentageCalcStop + " " + Time[CandleLookBackStop]);
  2132.                     Print("priceCalcStop " + priceCalcStop + " " + Time[CandleLookBackStop]);
  2133.                     Print("tickCalcStop " + tickCalcStop + " " + Time[CandleLookBackStop]);
  2134.                
  2135.                     Print("candleBarOffsetStop " + candleBarOffsetStop + " " + Time[CandleLookBackStop]);
  2136.                    
  2137.                     Print("stopLong " + stopLong + " " + Time[CandleLookBackStop]);
  2138.                     Print("stopShort " + stopShort + " " + Time[CandleLookBackStop]);
  2139.                 }
  2140.             }
  2141.            
  2142.             #endregion
  2143.            
  2144.             #endregion
  2145.            
  2146.                     #region Breakeven Offset
  2147.            
  2148.             //Define what area you will set a breakeven (If it is based on the chart)
  2149.             breakevenAreaLong       = entryAreaLong;
  2150.             breakevenAreaShort      = entryAreaShort;
  2151.            
  2152.             //Adds offset to your breakeven area. Gives user customization.
  2153.             percentageCalcBreakeven     = ((entryAreaLong - stopAreaLong) * PercentageOffsetBreakeven);
  2154.             priceCalcBreakeven          = PriceOffsetBreakeven;
  2155.             tickCalcBreakeven           = TickOffsetBreakeven * TickSize;
  2156.            
  2157.             //Picks the highest of the 3 numbers
  2158.             candleBarOffsetBreakeven = Math.Max(percentageCalcBreakeven, Math.Max(priceCalcBreakeven, tickCalcBreakeven));
  2159.            
  2160.             //Add both of them together to define final breakeven point
  2161.             //breakevenLong = breakevenAreaLong - candleBarOffsetBreakeven;
  2162.             //breakevenShort = breakevenAreaShort + candleBarOffsetBreakeven;
  2163.            
  2164.             #region BreakevenPrints
  2165.            
  2166.             if (SystemPrint)
  2167.             {
  2168.                 if (BreakevenPrints)
  2169.                 {
  2170.                     Print("percentageCalcBreakeven " + percentageCalcBreakeven + " " + Time[1]);
  2171.                     Print("priceCalcBreakeven " + priceCalcBreakeven + " " + Time[1]);
  2172.                     Print("tickCalcBreakeven " + tickCalcBreakeven + " " + Time[1]);
  2173.                
  2174.                     Print("candleBarOffsetBreakeven " + candleBarOffsetBreakeven + " " + Time[1]);
  2175.                    
  2176.                     Print("breakevenLong " + breakevenLong + " " + Time[1]);
  2177.                     Print("breakevenShort " + breakevenShort + " " + Time[1]);
  2178.                 }
  2179.             }
  2180.            
  2181.             #endregion
  2182.            
  2183.             #endregion
  2184.            
  2185.                     #region Range Values
  2186.            
  2187.             LongValuesOffset    = Math.Round(enterLong - stopLong, 4);
  2188.             ShortValuesOffset   = Math.Round(stopShort - enterShort, 4);
  2189.            
  2190.             LongValues          = Math.Round(entryAreaLong - stopAreaLong, 4);
  2191.             ShortValues         = Math.Round(stopAreaShort - entryAreaShort, 4);
  2192.            
  2193.             #endregion
  2194.            
  2195.                     #region Limit Entry Offset
  2196.            
  2197.             if (useLimit)
  2198.             {
  2199.                 percentageCalcLimitLong     = LongValuesOffset * PercentageOffsetLimit;
  2200.                 percentageCalcLimitShort    = ShortValuesOffset * PercentageOffsetLimit;
  2201.                 priceCalcLimit              = PriceOffsetLimit;
  2202.                 tickCalcLimit               = TickOffsetLimit * TickSize;
  2203.                
  2204.                 limitOffsetLong             = Math.Max(percentageCalcLimitLong, Math.Max(priceCalcLimit, tickCalcLimit));  
  2205.                 limitOffsetShort            = Math.Max(percentageCalcLimitShort, Math.Max(priceCalcLimit, tickCalcLimit));
  2206.                
  2207.                 if (AddOffset)
  2208.                 {
  2209.                     limitPriceSetLong           = enterLong + limitOffsetLong;
  2210.                     limitPriceSetShort          = enterShort - limitOffsetShort;
  2211.                 }
  2212.                
  2213.                 else if (AddOffset == false)
  2214.                 {
  2215.                     limitPriceSetLong           = entryAreaLong + limitOffsetLong;
  2216.                     limitPriceSetShort          = entryAreaShort - limitOffsetShort;
  2217.                 }
  2218.                
  2219.                 #region Limit Prints
  2220.            
  2221.             if (SystemPrint)
  2222.             {
  2223.                 if (LimitPrints)
  2224.                 {
  2225.                     Print("percentageCalcLimitLong " + percentageCalcLimitLong + " " + Time[0]);
  2226.                     Print("percentageCalcLimitShort " + percentageCalcLimitShort + " " + Time[0]);
  2227.                     Print("priceCalcLimit " + priceCalcLimit + " " + Time[0]);
  2228.                     Print("tickCalcLimit " + tickCalcLimit + " " + Time[0]);
  2229.                    
  2230.                     Print("limitOffsetLong " + limitOffsetLong + " " + Time[0]);
  2231.                     Print("limitPriceSetShort " + limitPriceSetShort + " " + Time[0]);
  2232.                    
  2233.                     Print("limitPriceSetLong " + limitPriceSetLong + " " + Time[0]);
  2234.                     Print("limitPriceSetShort " + limitPriceSetShort + " " + Time[0]);
  2235.                 }
  2236.             }
  2237.             #endregion
  2238.             }
  2239.            
  2240.            
  2241.             #endregion
  2242.            
  2243.            
  2244.                     #region Offset Added Logic
  2245.            
  2246.             if (AddOffset) ///Update Prints
  2247.             {  
  2248.                 //Long Trades
  2249.                 if (longButtonHLClicked == true || longButtonMarketClicked == true || longLineButtonClicked == true || customLongClicked == true)
  2250.                 {
  2251.                        
  2252.                     #region Position Size Long
  2253.                
  2254.                 if (autoPositionSize)
  2255.                 {
  2256.                     if (rrMode)
  2257.                     {
  2258.                         riskOffset = MaxLossPerTrade / ( ( (LongValuesOffset) / TickSize) * myDbl);
  2259.                     }
  2260.                    
  2261.                     if (tickMode)
  2262.                     {
  2263.                         riskOffset = MaxLossPerTrade / ( ( (candleBarOffsetStop) / TickSize) * myDbl);
  2264.                     }
  2265.                 }
  2266.                
  2267.                 else if (customPositionSize)
  2268.                 {
  2269.                     riskOffset = CustomPositionAmount;
  2270.                 }
  2271.                
  2272.                 positionSizeLong = (Convert.ToInt32(riskOffset));
  2273.                
  2274.                
  2275.                     //Single Target
  2276.                     if (dualTarget == false)
  2277.                     {
  2278.                         positionSizeLong = (Convert.ToInt32(riskOffset));
  2279.                        
  2280.                         if (positionSizeLong < 1)
  2281.                         {
  2282.                             positionSizeLong = 1;
  2283.                         }
  2284.                     }
  2285.                    
  2286.                     //Dual Target
  2287.                     if (dualTarget)
  2288.                     {
  2289.                        
  2290.                     firstTargetPositionLong = (Convert.ToInt32(positionSizeLong * splitPercent));
  2291.                        
  2292.                         if (firstTargetPositionLong < 1)
  2293.                         {
  2294.                             firstTargetPositionLong = 1;
  2295.                         }
  2296.                
  2297.                     secondTargetPositionLong = positionSizeLong - firstTargetPositionLong;
  2298.                        
  2299.                         if(secondTargetPositionLong < 1)
  2300.                         {
  2301.                             secondTargetPositionLong = 1;
  2302.                         }  
  2303.                     }
  2304.                    
  2305.                         #region Position Size Prints
  2306.                        
  2307.                         if (SystemPrint)
  2308.                         {
  2309.                             if (PositionSizePrints)
  2310.                             {
  2311.                                 Print("positionSizeLong "+ positionSizeLong + " " + Time[0]);
  2312.                                 Print("firstTargetPositionLong "+ firstTargetPositionLong + " " + Time[0]);
  2313.                                 Print("secondTargetPositionLong "+ secondTargetPositionLong + " " + Time[0]);
  2314.                             }
  2315.                         }
  2316.                        
  2317.                         #endregion
  2318.                            
  2319.                     #endregion
  2320.            
  2321.                     #region Set Stop/Profit Long
  2322.                
  2323.                 if (Low[0] > stopLong)
  2324.                 {
  2325.                     setStopLong = stopLong;
  2326.                    
  2327.                     setFirstTargetLong = enterLong + (LongValuesOffset * FirstTargetRR);
  2328.                     setFinalTargetLong = enterLong + (LongValuesOffset * FinalTargetRR);
  2329.                 }
  2330.                
  2331.                 else if (Low[0] <= stopLong)
  2332.                 {
  2333.                     setStopLong = Low[0] - candleBarOffsetStop;
  2334.                    
  2335.                     setFirstTargetLong = enterLong + ((enterLong - setStopLong) * FirstTargetRR);
  2336.                     setFinalTargetLong = enterLong + ((enterLong - setStopLong) * FinalTargetRR);
  2337.                 }
  2338.                
  2339.                 #region Profit Target Long Prints
  2340.                
  2341.                 if (SystemPrint)
  2342.                 {
  2343.                     if (ProfitTatgetPrints)
  2344.                     {
  2345.                         Print("setStopLong "+ setStopLong + " " + Time[0]);
  2346.                         Print("setFirstTargetLong "+ setFirstTargetLong + " " + Time[0]);
  2347.                         Print("setFinalTargetLong "+ setFinalTargetLong + " " + Time[0]);      
  2348.                     }
  2349.                 }
  2350.                
  2351.                 #endregion
  2352.                
  2353.                
  2354.                 #endregion
  2355.                
  2356.                     #region Draw Lines / Text Long Offset
  2357.        
  2358.                         #region RR mode
  2359.                        
  2360.                     if (rrMode)
  2361.                     {
  2362.                         RemoveDrawObject("EntryLine");
  2363.                         RemoveDrawObject("StopLine");
  2364.                    
  2365.                         Draw.HorizontalLine(this, "EntryLine", enterLong, Brushes.Green);
  2366.                         Draw.HorizontalLine(this, "StopLine", stopLong, Brushes.Red);
  2367.                    
  2368.                         if (DisplayText)
  2369.                         {
  2370.                             Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterLong, 4) + ("("+CandleLookBackEntry+")")
  2371.                             + "\nStop Line: " + Math.Round(stopLong, 4) + ("("+CandleLookBackStop+")")
  2372.                            
  2373.                             + "\n\nMax Loss($): " + MaxLossPerTrade
  2374.                             + "\nRange($): " + LongValuesOffset
  2375.                             + "\nRange(Ticks): " + LongValuesOffset / TickSize
  2376.                             + "\nPosition Size: " + positionSizeLong   
  2377.                        
  2378.                             ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2379.                         }
  2380.                     }
  2381.                        
  2382.                         #endregion
  2383.                    
  2384.                         #region Tick Mode
  2385.                    
  2386.                     if (tickMode)
  2387.                     {
  2388.                         RemoveDrawObject("EntryLine");
  2389.                         RemoveDrawObject("StopLine");
  2390.                    
  2391.                         Draw.HorizontalLine(this, "EntryLine", enterLong, Brushes.Green);
  2392.                         Draw.HorizontalLine(this, "StopLine", enterLong - candleBarOffsetStop, Brushes.Red);
  2393.                    
  2394.                         if (DisplayText)
  2395.                         {
  2396.                             Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterLong, 4) + ("("+CandleLookBackEntry+")")
  2397.                             + "\nStop Line: " + Math.Round(enterLong - candleBarOffsetStop, 4) + ("("+candleBarOffsetStop / TickSize+")")
  2398.                            
  2399.                             + "\n\nMax Loss($): " + MaxLossPerTrade
  2400.                             + "\nRange($): " + candleBarOffsetStop
  2401.                             + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  2402.                             + "\nPosition Size: " + positionSizeLong   
  2403.                        
  2404.                             ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2405.                         }
  2406.                     }
  2407.                
  2408.                     #endregion
  2409.                    
  2410.                     #endregion
  2411.                                        
  2412.                 }
  2413.                
  2414.                
  2415.                 //Short Trades
  2416.                 if (shortButtonHLClicked == true || shortButtonMarketClicked == true || shortLineButtonClicked == true || customShortClicked == true)
  2417.                 {
  2418.                
  2419.                     #region Position Size Short
  2420.                
  2421.                 if (autoPositionSize)
  2422.                 {
  2423.                     if (rrMode)
  2424.                     {
  2425.                         riskOffset = MaxLossPerTrade / ( ( (ShortValuesOffset) / TickSize) * myDbl);
  2426.                     }
  2427.                    
  2428.                     if (tickMode)
  2429.                     {
  2430.                         riskOffset = MaxLossPerTrade / ( ( (candleBarOffsetStop) / TickSize) * myDbl);
  2431.                     }
  2432.                 }
  2433.                
  2434.                 else if (customPositionSize)
  2435.                 {
  2436.                     riskOffset = CustomPositionAmount;
  2437.                 }
  2438.                
  2439.                 positionSizeShort = (Convert.ToInt32(riskOffset));
  2440.                
  2441.                
  2442.                     //Single Target
  2443.                     if (dualTarget == false)
  2444.                     {
  2445.                         positionSizeShort = (Convert.ToInt32(riskOffset));
  2446.                        
  2447.                         if (positionSizeShort < 1)
  2448.                         {
  2449.                             positionSizeShort = 1;
  2450.                         }
  2451.                     }
  2452.                    
  2453.                     //Dual Target
  2454.                     if (dualTarget)
  2455.                     {
  2456.                        
  2457.                     firstTargetPositionShort = (Convert.ToInt32(positionSizeShort * splitPercent));
  2458.                        
  2459.                         if (firstTargetPositionShort < 1)
  2460.                         {
  2461.                             firstTargetPositionShort = 1;
  2462.                         }
  2463.                
  2464.                     secondTargetPositionShort = positionSizeShort - firstTargetPositionShort;
  2465.                        
  2466.                         if(secondTargetPositionShort < 1)
  2467.                         {
  2468.                             secondTargetPositionShort = 1;
  2469.                         }  
  2470.                     }
  2471.                    
  2472.                         #region Position Size Prints
  2473.                        
  2474.                         if (SystemPrint)
  2475.                         {
  2476.                             if (PositionSizePrints)
  2477.                             {
  2478.                                 Print("positionSizeShort "+ positionSizeShort + " " + Time[0]);
  2479.                                 Print("firstTargetPositionShort "+ firstTargetPositionShort + " " + Time[0]);
  2480.                                 Print("secondTargetPositionShort "+ secondTargetPositionShort + " " + Time[0]);
  2481.                             }
  2482.                         }
  2483.                        
  2484.                         #endregion
  2485.                        
  2486.                    
  2487.                     #endregion
  2488.                
  2489.                     #region Set Stop/Profit Short
  2490.                
  2491.                 if (High[0] < stopShort)
  2492.                 {
  2493.                     setStopShort = stopShort;
  2494.                    
  2495.                     setFirstTargetShort = enterShort - (ShortValuesOffset * FirstTargetRR);
  2496.                     setFinalTargetShort = enterShort - (ShortValuesOffset * FinalTargetRR);
  2497.                 }
  2498.                
  2499.                 else if (High[0] >= stopShort)
  2500.                 {
  2501.                     setStopShort = High[0] + candleBarOffsetStop;
  2502.                    
  2503.                     setFirstTargetShort = enterShort - ((setStopShort - enterShort) * FirstTargetRR);
  2504.                     setFinalTargetShort = enterShort - ((setStopShort - enterShort) * FinalTargetRR);
  2505.                 }
  2506.                
  2507.                
  2508.                 #region Profit Target Prints
  2509.                        
  2510.                         if (SystemPrint)
  2511.                         {
  2512.                             if (ProfitTatgetPrints)
  2513.                             {
  2514.                                 Print("setStopShort "+ setStopShort + " " + Time[0]);
  2515.                                 Print("setFirstTargetShort "+ setFirstTargetShort + " " + Time[0]);
  2516.                                 Print("setFinalTargetShort "+ setFinalTargetShort + " " + Time[0]);
  2517.                             }
  2518.                         }
  2519.                        
  2520.                         #endregion
  2521.                
  2522.                 #endregion
  2523.                    
  2524.                     #region Draw Lines / Text Short Offset
  2525.                
  2526.                         #region RR Mode
  2527.                        
  2528.                 if (rrMode)
  2529.                 {
  2530.                     RemoveDrawObject("EntryLine");
  2531.                     RemoveDrawObject("StopLine");
  2532.                    
  2533.                    
  2534.                     Draw.HorizontalLine(this, "EntryLine", enterShort, Brushes.Green);
  2535.                     Draw.HorizontalLine(this, "StopLine", stopShort, Brushes.Red);
  2536.                    
  2537.                     if (DisplayText)
  2538.                     {
  2539.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterShort, 4) + ("("+CandleLookBackEntry+")")
  2540.                         + "\nStop Line: " + Math.Round(stopShort, 4) + ("("+CandleLookBackStop+")")
  2541.                            
  2542.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  2543.                         + "\nRange($): " + ShortValuesOffset
  2544.                         + "\nRange(Ticks): " + ShortValuesOffset / TickSize
  2545.                         + "\nPosition Size: " + positionSizeShort  
  2546.                        
  2547.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2548.                     }
  2549.                    
  2550.                 }
  2551.                        
  2552.                     #endregion
  2553.                    
  2554.                         #region Tick Mode
  2555.                        
  2556.                 if (tickMode)
  2557.                 {
  2558.                     RemoveDrawObject("EntryLine");
  2559.                     RemoveDrawObject("StopLine");
  2560.                    
  2561.                    
  2562.                     Draw.HorizontalLine(this, "EntryLine", enterShort, Brushes.Green);
  2563.                     Draw.HorizontalLine(this, "StopLine", enterShort + candleBarOffsetStop, Brushes.Red);
  2564.                    
  2565.                     if (DisplayText)
  2566.                     {
  2567.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterShort, 4) + ("("+CandleLookBackEntry+")")
  2568.                         + "\nStop Line: " + Math.Round(enterShort + candleBarOffsetStop, 4) + ("("+candleBarOffsetStop / TickSize+")")
  2569.                            
  2570.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  2571.                         + "\nRange($): " + candleBarOffsetStop
  2572.                         + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  2573.                         + "\nPosition Size: " + positionSizeShort  
  2574.                        
  2575.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2576.                     }
  2577.                    
  2578.                 }
  2579.                        
  2580.                     #endregion
  2581.                    
  2582.                 #endregion
  2583.                
  2584.                 }
  2585.             }
  2586.            
  2587.             #endregion 
  2588.            
  2589.                     #region W/O Offset
  2590.             /* Removed for simplicity of use
  2591.            
  2592.             if (AddOffset == false)
  2593.             {  
  2594.                 //Long Trades
  2595.                 if (longButtonHLClicked == true || longButtonMarketClicked == true || longLineButtonClicked == true || customLongClicked == true)
  2596.                 {
  2597.                
  2598.                     #region Position Size Long
  2599.                
  2600.                 if (autoPositionSize)
  2601.                 {
  2602.                     riskOffset = MaxLossPerTrade / ( ( (LongValues) / TickSize) * myDbl);
  2603.                 }
  2604.                
  2605.                 else if (customPositionSize)
  2606.                 {
  2607.                     riskOffset = CustomPositionAmount;
  2608.                 }
  2609.                
  2610.                 positionSize = (Convert.ToInt32(riskOffset));
  2611.                
  2612.                
  2613.                     //Single Target
  2614.                     if (dualTarget == false)
  2615.                     {
  2616.                         positionSize = (Convert.ToInt32(riskOffset));
  2617.                        
  2618.                         if (positionSize < 1)
  2619.                         {
  2620.                             positionSize = 1;
  2621.                         }
  2622.                     }
  2623.                    
  2624.                     //Dual Target
  2625.                     if (dualTarget)
  2626.                     {
  2627.                        
  2628.                     firstTargetPosition = (Convert.ToInt32(positionSize * splitPercent));
  2629.                        
  2630.                         if (firstTargetPosition < 1)
  2631.                         {
  2632.                             firstTargetPosition = 1;
  2633.                         }
  2634.                
  2635.                     secondTargetPosition = positionSize - firstTargetPosition;
  2636.                        
  2637.                         if(secondTargetPosition < 1)
  2638.                         {
  2639.                             secondTargetPosition = 1;
  2640.                         }  
  2641.                     }
  2642.                    
  2643.                         #region Position Size Prints
  2644.                        
  2645.                         if (SystemPrint)
  2646.                         {
  2647.                             if (PositionSizePrints)
  2648.                             {
  2649.                                 Print("positionSize "+ positionSize + " " + Time[0]);
  2650.                                 Print("firstTargetPosition "+ firstTargetPosition + " " + Time[0]);
  2651.                                 Print("secondTargetPosition "+ secondTargetPosition + " " + Time[0]);
  2652.                             }
  2653.                         }
  2654.                        
  2655.                         #endregion
  2656.                        
  2657.                    
  2658.                    
  2659.                
  2660.                     #endregion
  2661.                    
  2662.                     #region Set Stop/Profit Long       
  2663.                    
  2664.                 if (Low[0] > stopAreaLong)
  2665.                 {
  2666.                     setStopLong = stopAreaLong;
  2667.                 }
  2668.                
  2669.                 else if (Low[0] <= stopAreaLong)
  2670.                 {
  2671.                     setStopLong = Low[0];
  2672.                 }
  2673.                
  2674.                 setFirstTarget = entryAreaLong + (LongValues * FirstTargetRR);
  2675.                 setFinalTarget = entryAreaLong + (LongValues * FinalTargetRR);
  2676.                
  2677.                 #endregion
  2678.                
  2679.                     #region Draw Lines / Text Long W/O Offset
  2680.                
  2681.                     #region RR mode
  2682.                
  2683.                 if (rrMode)
  2684.                 {
  2685.                     RemoveDrawObject("EntryLine");
  2686.                     RemoveDrawObject("StopLine");
  2687.                    
  2688.                    
  2689.                     Draw.HorizontalLine(this, "EntryLine", entryAreaLong, Brushes.Green);
  2690.                     Draw.HorizontalLine(this, "StopLine", stopAreaLong, Brushes.Red);
  2691.                    
  2692.                     if (DisplayText)
  2693.                     {
  2694.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaLong, 2) + ("("+CandleLookBackEntry+")")
  2695.                         + "\nStop Line: " + Math.Round(stopAreaLong, 2) + ("("+CandleLookBackStop+")")
  2696.                            
  2697.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  2698.                         + "\nRange($): " + LongValues  
  2699.                         + "\nRange(Ticks): " + LongValues / TickSize
  2700.                         + "\nPosition Size: " + positionSize   
  2701.                        
  2702.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2703.                     }
  2704.                 }
  2705.                    
  2706.                     #endregion
  2707.                
  2708.                     #region Tick mode
  2709.                
  2710.                 if (tickMode)
  2711.                 {
  2712.                     RemoveDrawObject("EntryLine");
  2713.                     RemoveDrawObject("StopLine");
  2714.                    
  2715.                    
  2716.                     Draw.HorizontalLine(this, "EntryLine", entryAreaLong, Brushes.Green);
  2717.                     Draw.HorizontalLine(this, "StopLine", entryAreaLong - candleBarOffsetStop, Brushes.Red);
  2718.                    
  2719.                     if (DisplayText)
  2720.                     {
  2721.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaLong, 2) + ("("+CandleLookBackEntry+")")
  2722.                         + "\nStop Line: " + Math.Round(entryAreaLong - candleBarOffsetStop, 2) + ("("+candleBarOffsetStop / TickSize+")")
  2723.                            
  2724.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  2725.                         + "\nRange($): " + candleBarOffsetStop 
  2726.                         + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  2727.                         + "\nPosition Size: " + positionSize   
  2728.                        
  2729.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2730.                     }
  2731.                 }
  2732.                    
  2733.                     #endregion
  2734.                    
  2735.                     #endregion
  2736.                
  2737.                 }
  2738.                
  2739.                 //Short Trades
  2740.                 if (shortButtonHLClicked == true || shortButtonMarketClicked == true || shortLineButtonClicked == true || customShortClicked == true)
  2741.                 {
  2742.                
  2743.                     #region Position Size Short
  2744.                
  2745.                 if (autoPositionSize)
  2746.                 {
  2747.                     riskOffset = MaxLossPerTrade / ( ( (ShortValues) / TickSize) * myDbl);
  2748.                 }
  2749.                
  2750.                 else if (customPositionSize)
  2751.                 {
  2752.                     riskOffset = CustomPositionAmount;
  2753.                 }
  2754.                
  2755.                 positionSize = (Convert.ToInt32(riskOffset));
  2756.                
  2757.                
  2758.                     //Single Target
  2759.                     if (dualTarget == false)
  2760.                     {
  2761.                         positionSize = (Convert.ToInt32(riskOffset));
  2762.                        
  2763.                         if (positionSize < 1)
  2764.                         {
  2765.                             positionSize = 1;
  2766.                         }
  2767.                     }
  2768.                    
  2769.                     //Dual Target
  2770.                     if (dualTarget)
  2771.                     {
  2772.                        
  2773.                     firstTargetPosition = (Convert.ToInt32(positionSize * splitPercent));
  2774.                        
  2775.                         if (firstTargetPosition < 1)
  2776.                         {
  2777.                             firstTargetPosition = 1;
  2778.                         }
  2779.                
  2780.                     secondTargetPosition = positionSize - firstTargetPosition;
  2781.                        
  2782.                         if(secondTargetPosition < 1)
  2783.                         {
  2784.                             secondTargetPosition = 1;
  2785.                         }  
  2786.                     }
  2787.                    
  2788.                         #region Position Size Prints
  2789.                        
  2790.                         if (SystemPrint)
  2791.                         {
  2792.                             if (PositionSizePrints)
  2793.                             {
  2794.                                 Print("positionSize "+ positionSize + " " + Time[0]);
  2795.                                 Print("firstTargetPosition "+ firstTargetPosition + " " + Time[0]);
  2796.                                 Print("secondTargetPosition "+ secondTargetPosition + " " + Time[0]);
  2797.                             }
  2798.                         }
  2799.                        
  2800.                         #endregion
  2801.                        
  2802.                    
  2803.                     #endregion
  2804.                    
  2805.                     #region Set Stop/Profit Short      
  2806.                    
  2807.                 if (High[0] < stopAreaShort)
  2808.                 {
  2809.                     setStopShort = stopAreaShort;
  2810.                 }
  2811.                
  2812.                 else if (High[0] >= stopAreaShort)
  2813.                 {
  2814.                     setStopShort = High[0];
  2815.                 }
  2816.                
  2817.                 setFirstTarget = entryAreaShort - (ShortValues * FirstTargetRR);
  2818.                 setFinalTarget = entryAreaShort - (ShortValues * FinalTargetRR);
  2819.                
  2820.                 #endregion
  2821.                
  2822.                     #region Draw Lines / Text Short W/O Offset
  2823.                
  2824.                     #region RR mode
  2825.                
  2826.                 if (rrMode)
  2827.                 {
  2828.                     RemoveDrawObject("EntryLine");
  2829.                     RemoveDrawObject("StopLine");
  2830.                    
  2831.                    
  2832.                     Draw.HorizontalLine(this, "EntryLine", entryAreaShort, Brushes.Green);
  2833.                     Draw.HorizontalLine(this, "StopLine", stopAreaShort, Brushes.Red);
  2834.                    
  2835.                     if (DisplayText)
  2836.                     {
  2837.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaShort, 2) + ("("+CandleLookBackEntry+")")
  2838.                         + "\nStop Line: " + Math.Round(stopAreaShort, 2) + ("("+CandleLookBackStop+")")
  2839.                            
  2840.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  2841.                         + "\nRange($): " + ShortValues 
  2842.                         + "\nRange(Ticks): " + ShortValues / TickSize
  2843.                         + "\nPosition Size: " + positionSize   
  2844.                        
  2845.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2846.                     }
  2847.                 }
  2848.                
  2849.                     #endregion
  2850.                
  2851.                     #region Tick mode
  2852.                
  2853.                 if (tickMode)
  2854.                 {
  2855.                     RemoveDrawObject("EntryLine");
  2856.                     RemoveDrawObject("StopLine");
  2857.                    
  2858.                    
  2859.                     Draw.HorizontalLine(this, "EntryLine", entryAreaShort, Brushes.Green);
  2860.                     Draw.HorizontalLine(this, "StopLine", entryAreaShort + candleBarOffsetStop, Brushes.Red);
  2861.                    
  2862.                     if (DisplayText)
  2863.                     {
  2864.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaShort, 2) + ("("+CandleLookBackEntry+")")
  2865.                         + "\nStop Line: " + Math.Round( entryAreaShort + candleBarOffsetStop, 2) + ("("+candleBarOffsetStop / TickSize+")")
  2866.                            
  2867.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  2868.                         + "\nRange($): " + candleBarOffsetStop 
  2869.                         + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  2870.                         + "\nPosition Size: " + positionSize   
  2871.                        
  2872.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  2873.                     }
  2874.                 }
  2875.                
  2876.                     #endregion
  2877.                
  2878.                     #endregion
  2879.                
  2880.                 }
  2881.                
  2882.             }
  2883.             */
  2884.             #endregion //Removed for now
  2885.            
  2886.                 }
  2887.            
  2888.                 if (CandleRange)
  2889.                 {
  2890.                     #region Entry Offset
  2891.    
  2892.             if (longButtonHLClicked == true || longButtonMarketClicked == true || longLineButtonClicked == true || (customLongClicked == true && enterClosePrice == false)
  2893.                 || shortButtonHLClicked == true || shortButtonMarketClicked == true || shortLineButtonClicked == true || (customShortClicked == true && enterClosePrice == false)
  2894.                 )      
  2895.             {  
  2896.                 //HL
  2897.                 entryAreaLong       = MAX(High, CandleLookBackEntry)[1];
  2898.                 entryAreaShort      = MIN(Low, CandleLookBackEntry)[1];
  2899.             }  
  2900.            
  2901.             if ((customLongClicked || customShortClicked) && enterClosePrice == true)
  2902.             {
  2903.                 //Previous Close Price 
  2904.                 entryAreaLong       = MAX(Close, CandleLookBackEntry)[1];
  2905.                 entryAreaShort      = MAX(Close, CandleLookBackEntry)[1];
  2906.             }
  2907.            
  2908.             //Adds offset to your entry area. Gives user customization.
  2909.             percentageCalcEntry     = ((entryAreaLong - entryAreaShort) * PercentageOffsetEntry);
  2910.             priceCalcEntry          = PriceOffsetEntry;
  2911.             tickCalcEntry           = TickOffsetEntry * TickSize;
  2912.            
  2913.             //Picks the highest of the 3 numbers
  2914.             candleBarOffsetEntry = Math.Max(percentageCalcEntry, Math.Max(priceCalcEntry, tickCalcEntry));
  2915.            
  2916.             //Add both of them together to define final entry point
  2917.             enterLong = entryAreaLong + candleBarOffsetEntry;
  2918.             enterShort = entryAreaShort - candleBarOffsetEntry;
  2919.                            
  2920.            
  2921.             #region Entry Prints
  2922.            
  2923.             if (SystemPrint)
  2924.             {
  2925.                 if (EntryPrints)
  2926.                 {
  2927.                     Print("entryAreaLong " + entryAreaLong + " " + Time[1]);
  2928.                     Print("entryAreaShort " + entryAreaShort + " " + Time[1]);
  2929.                    
  2930.                     Print("percentageCalcEntry Range " + percentageCalcEntry + " " + Time[1]);
  2931.                     Print("priceCalcEntry Range  " + priceCalcEntry + " " + Time[1]);
  2932.                     Print("tickCalcEntry Range  " + tickCalcEntry + " " + Time[1]);
  2933.                    
  2934.                     Print("candleBarOffsetEntry Range " + candleBarOffsetEntry + " " + Time[1]);
  2935.                    
  2936.                     Print("enterLong  " + enterLong + " " + Time[1]);
  2937.                     Print("enterShort "  + enterShort + " " + Time[1]);
  2938.                 }
  2939.             }
  2940.             #endregion
  2941.            
  2942.             #endregion
  2943.            
  2944.                     #region Stop Offset
  2945.            
  2946.             //Define what area you will set a stop (If it is based on the chart)
  2947.             stopAreaLong        = MIN(Low, CandleLookBackStop)[1];
  2948.             stopAreaShort       = MAX(High, CandleLookBackStop)[1];
  2949.            
  2950.             //Adds offset to your stop area. Gives user customization.
  2951.             percentageCalcStop      = ((stopAreaShort - stopAreaLong) * PercentageOffsetStop);
  2952.             priceCalcStop           = PriceOffsetStop;
  2953.             tickCalcStop            = TickOffsetStop * TickSize;
  2954.            
  2955.             //Picks the highest of the 3 numbers
  2956.             candleBarOffsetStop = Math.Max(percentageCalcStop, Math.Max(priceCalcStop, tickCalcStop));
  2957.            
  2958.             //Add both of them together to define final stop point
  2959.             stopLong = stopAreaLong - candleBarOffsetStop;
  2960.             stopShort = stopAreaShort + candleBarOffsetStop;
  2961.            
  2962.             #region StopPrints
  2963.            
  2964.             if (SystemPrint)
  2965.             {
  2966.                 if (StopPrints)
  2967.                 {
  2968.                     Print("percentageCalcStop Range " + percentageCalcStop + " " + Time[1]);
  2969.                     Print("priceCalcStop Range " + priceCalcStop + " " + Time[1]);
  2970.                     Print("tickCalcStop Range " + tickCalcStop + " " + Time[1]);
  2971.                
  2972.                     Print("candleBarOffsetStop Range " + candleBarOffsetStop + " " + Time[1]);
  2973.                    
  2974.                     Print("stopLong Range " + stopLong + " " + Time[1]);
  2975.                     Print("stopShort Range " + stopShort + " " + Time[1]);
  2976.                 }
  2977.             }
  2978.            
  2979.             #endregion
  2980.            
  2981.             #endregion
  2982.            
  2983.                     #region Breakeven Offset
  2984.            
  2985.             //Define what area you will set a breakeven (If it is based on the chart - Different from 'Actual Breakeven')
  2986.             breakevenAreaLong       = entryAreaLong;
  2987.             breakevenAreaShort      = entryAreaShort;
  2988.            
  2989.             //Adds offset to your breakeven area. Gives user customization.
  2990.             percentageCalcBreakeven     = ((entryAreaLong - stopAreaLong) * PercentageOffsetBreakeven);
  2991.             priceCalcBreakeven          = PriceOffsetBreakeven;
  2992.             tickCalcBreakeven           = TickOffsetBreakeven * TickSize;
  2993.            
  2994.             //Picks the highest of the 3 numbers
  2995.             candleBarOffsetBreakeven = Math.Max(percentageCalcBreakeven, Math.Max(priceCalcBreakeven, tickCalcBreakeven));
  2996.            
  2997.             #region BreakevenPrints
  2998.            
  2999.             if (SystemPrint)
  3000.             {
  3001.                 if (BreakevenPrints)
  3002.                 {
  3003.                     Print("percentageCalcBreakeven Range " + percentageCalcBreakeven + " " + Time[1]);
  3004.                     Print("priceCalcBreakeven Range " + priceCalcBreakeven + " " + Time[1]);
  3005.                     Print("tickCalcBreakeven Range " + tickCalcBreakeven + " " + Time[1]);
  3006.                
  3007.                     Print("candleBarOffsetBreakeven Range " + candleBarOffsetBreakeven + " " + Time[1]);
  3008.                    
  3009.                     Print("breakevenLong Range " + breakevenLong + " " + Time[1]);
  3010.                     Print("breakevenShort Range " + breakevenShort + " " + Time[1]);
  3011.                 }
  3012.             }
  3013.            
  3014.             #endregion
  3015.            
  3016.             #endregion
  3017.            
  3018.                     #region Range Values
  3019.            
  3020.             LongValuesOffset    = Math.Round(enterLong - stopLong, 4);
  3021.             ShortValuesOffset   = Math.Round(stopShort - enterShort, 4);
  3022.            
  3023.             LongValues          = Math.Round(entryAreaLong - stopAreaLong, 4);
  3024.             ShortValues         = Math.Round(stopAreaShort - entryAreaShort, 4);
  3025.             /*
  3026.             LongValuesOffset    = Math.Round(enterLong - stopLong, 2);
  3027.             ShortValuesOffset   = Math.Round(stopShort - enterShort, 2);
  3028.            
  3029.             LongValues          = Math.Round(entryAreaLong - stopAreaLong, 2);
  3030.             ShortValues         = Math.Round(stopAreaShort - entryAreaShort, 2);
  3031.            
  3032.             ///////////////////////////////////////////////////////
  3033.             LongValuesOffsetTickMode    = Math.Round(enterLong - (enterLong - candleBarOffsetStop), 2);
  3034.             ShortValuesOffsetTickMode   = Math.Round((enterShort + candleBarOffsetStop) - enterShort, 2);
  3035.            
  3036.             LongValuesTickMode          = Math.Round(entryAreaLong - (entryAreaLong - candleBarOffsetStop), 2);
  3037.             ShortValuesTickMode         = Math.Round((entryAreaShort + candleBarOffsetStop) - entryAreaShort, 2);
  3038.            
  3039.            
  3040.             Print("LongValuesOffsetTickMode " + LongValuesOffsetTickMode);     
  3041.             Print("ShortValuesOffsetTickMode " + ShortValuesOffsetTickMode);
  3042.            
  3043.             Print("LongValuesTickMode " + LongValuesTickMode);
  3044.             Print("ShortValuesTickMode " + ShortValuesTickMode);
  3045.         */ 
  3046.             #endregion
  3047.                    
  3048.                     #region Limit Entry Offset
  3049.            
  3050.             if (useLimit)
  3051.             {
  3052.                 percentageCalcLimitLong     = LongValuesOffset * PercentageOffsetLimit;
  3053.                 percentageCalcLimitShort    = ShortValuesOffset * PercentageOffsetLimit;
  3054.                 priceCalcLimit              = PriceOffsetLimit;
  3055.                 tickCalcLimit               = TickOffsetLimit * TickSize;
  3056.                
  3057.                 limitOffsetLong             = Math.Max(percentageCalcLimitLong, Math.Max(priceCalcLimit, tickCalcLimit));  
  3058.                 limitOffsetShort            = Math.Max(percentageCalcLimitShort, Math.Max(priceCalcLimit, tickCalcLimit));
  3059.                
  3060.                 if (AddOffset)
  3061.                 {
  3062.                     limitPriceSetLong           = enterLong + limitOffsetLong;
  3063.                     limitPriceSetShort          = enterShort - limitOffsetShort;
  3064.                 }
  3065.                
  3066.                 else if (AddOffset == false)
  3067.                 {
  3068.                     limitPriceSetLong           = entryAreaLong + limitOffsetLong;
  3069.                     limitPriceSetShort          = entryAreaShort - limitOffsetShort;
  3070.                 }
  3071.                
  3072.                 #region Limit Prints
  3073.            
  3074.             if (SystemPrint)
  3075.             {
  3076.                 if (LimitPrints)
  3077.                 {
  3078.                     Print("percentageCalcLimitLong " + percentageCalcLimitLong + " " + Time[0]);
  3079.                     Print("percentageCalcLimitShort " + percentageCalcLimitShort + " " + Time[0]);
  3080.                     Print("priceCalcLimit " + priceCalcLimit + " " + Time[0]);
  3081.                     Print("tickCalcLimit " + tickCalcLimit + " " + Time[0]);
  3082.                    
  3083.                     Print("limitOffsetLong " + limitOffsetLong + " " + Time[0]);
  3084.                     Print("limitPriceSetShort " + limitPriceSetShort + " " + Time[0]);
  3085.                    
  3086.                     Print("limitPriceSetLong " + limitPriceSetLong + " " + Time[0]);
  3087.                     Print("limitPriceSetShort " + limitPriceSetShort + " " + Time[0]);
  3088.                 }
  3089.             }
  3090.             #endregion
  3091.             }
  3092.                 #endregion
  3093.            
  3094.                    
  3095.                     #region Offset Added Logic
  3096.            
  3097.             if (AddOffset) ///Update Prints
  3098.             {  
  3099.                 //Long Trades
  3100.                 if (longButtonHLClicked == true || longButtonMarketClicked == true || longLineButtonClicked == true || customLongClicked == true)
  3101.                 {
  3102.                        
  3103.                     #region Position Size Long
  3104.                
  3105.                 if (autoPositionSize)
  3106.                 {
  3107.                     if (rrMode)
  3108.                     {
  3109.                         riskOffset = MaxLossPerTrade / ( ( (LongValuesOffset) / TickSize) * myDbl);
  3110.                     }
  3111.                    
  3112.                     if (tickMode)
  3113.                     {
  3114.                         riskOffset = MaxLossPerTrade / ( ( (candleBarOffsetStop) / TickSize) * myDbl);
  3115.                     }
  3116.                 }
  3117.                
  3118.                 else if (customPositionSize)
  3119.                 {
  3120.                     riskOffset = CustomPositionAmount;
  3121.                 }
  3122.                
  3123.                 positionSizeLong = (Convert.ToInt32(riskOffset));
  3124.                
  3125.                
  3126.                     //Single Target
  3127.                     if (dualTarget == false)
  3128.                     {
  3129.                         positionSizeLong = (Convert.ToInt32(riskOffset));
  3130.                        
  3131.                         if (positionSizeLong < 1)
  3132.                         {
  3133.                             positionSizeLong = 1;
  3134.                         }
  3135.                     }
  3136.                    
  3137.                     //Dual Target
  3138.                     if (dualTarget)
  3139.                     {
  3140.                        
  3141.                     firstTargetPositionLong = (Convert.ToInt32(positionSizeLong * splitPercent));
  3142.                        
  3143.                         if (firstTargetPositionLong < 1)
  3144.                         {
  3145.                             firstTargetPositionLong = 1;
  3146.                         }
  3147.                
  3148.                     secondTargetPositionLong = positionSizeLong - firstTargetPositionLong;
  3149.                        
  3150.                         if(secondTargetPositionLong < 1)
  3151.                         {
  3152.                             secondTargetPositionLong = 1;
  3153.                         }  
  3154.                     }
  3155.                    
  3156.                         #region Position Size Prints
  3157.                        
  3158.                         if (SystemPrint)
  3159.                         {
  3160.                             if (PositionSizePrints)
  3161.                             {
  3162.                                 Print("positionSizeLong "+ positionSizeLong + " " + Time[0]);
  3163.                                 Print("firstTargetPositionLong "+ firstTargetPositionLong + " " + Time[0]);
  3164.                                 Print("secondTargetPositionLong "+ secondTargetPositionLong + " " + Time[0]);
  3165.                             }
  3166.                         }
  3167.                        
  3168.                         #endregion
  3169.                        
  3170.                    
  3171.                     #endregion
  3172.                
  3173.                     #region Set Stop/Profit Long
  3174.                
  3175.                 if (Low[0] > stopLong)
  3176.                 {
  3177.                     setStopLong = stopLong;
  3178.                    
  3179.                     setFirstTargetLong = enterLong + (LongValuesOffset * FirstTargetRR);
  3180.                     setFinalTargetLong = enterLong + (LongValuesOffset * FinalTargetRR);
  3181.                 }
  3182.                
  3183.                 else if (Low[0] <= stopLong)
  3184.                 {
  3185.                     setStopLong = Low[0] - candleBarOffsetStop;
  3186.                    
  3187.                     setFirstTargetLong = enterLong + ((enterLong - setStopLong) * FirstTargetRR);
  3188.                     setFinalTargetLong = enterLong + ((enterLong - setStopLong) * FinalTargetRR);
  3189.                 }
  3190.                
  3191.    
  3192.                 #region Profit Target Long Prints
  3193.                
  3194.                 if (SystemPrint)
  3195.                 {
  3196.                     if (ProfitTatgetPrints)
  3197.                     {
  3198.                         Print("setStopLong "+ setStopLong + " " + Time[0]);
  3199.                         Print("setFirstTargetLong "+ setFirstTargetLong + " " + Time[0]);
  3200.                         Print("setFinalTargetLong "+ setFinalTargetLong + " " + Time[0]);      
  3201.                     }
  3202.                 }
  3203.                
  3204.                 #endregion
  3205.                
  3206.                 #endregion
  3207.                
  3208.                     #region Draw Lines / Text Long Offset
  3209.        
  3210.                         #region RR mode
  3211.                        
  3212.                     if (rrMode)
  3213.                     {
  3214.                         RemoveDrawObject("EntryLine");
  3215.                         RemoveDrawObject("StopLine");
  3216.                    
  3217.                         Draw.HorizontalLine(this, "EntryLine", enterLong, Brushes.Green);
  3218.                         Draw.HorizontalLine(this, "StopLine", stopLong, Brushes.Red);
  3219.                    
  3220.                         if (DisplayText)
  3221.                         {
  3222.                             Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterLong, 4) + ("("+CandleLookBackEntry+")")
  3223.                             + "\nStop Line: " + Math.Round(stopLong, 4) + ("("+CandleLookBackStop+")")
  3224.                            
  3225.                             + "\n\nMax Loss($): " + MaxLossPerTrade
  3226.                             + "\nRange($): " + LongValuesOffset
  3227.                             + "\nRange(Ticks): " + LongValuesOffset / TickSize
  3228.                             + "\nPosition Size: " + positionSizeLong   
  3229.                        
  3230.                             ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3231.                         }
  3232.                     }
  3233.                        
  3234.                         #endregion
  3235.                    
  3236.                         #region Tick Mode
  3237.                    
  3238.                     if (tickMode)
  3239.                     {
  3240.                         RemoveDrawObject("EntryLine");
  3241.                         RemoveDrawObject("StopLine");
  3242.                    
  3243.                         Draw.HorizontalLine(this, "EntryLine", enterLong, Brushes.Green);
  3244.                         Draw.HorizontalLine(this, "StopLine", enterLong - candleBarOffsetStop, Brushes.Red);
  3245.                    
  3246.                         if (DisplayText)
  3247.                         {
  3248.                             Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterLong, 4) + ("("+CandleLookBackEntry+")")
  3249.                             + "\nStop Line: " + Math.Round(enterLong - candleBarOffsetStop, 4) + ("("+candleBarOffsetStop / TickSize+")")
  3250.                            
  3251.                             + "\n\nMax Loss($): " + MaxLossPerTrade
  3252.                             + "\nRange($): " + candleBarOffsetStop
  3253.                             + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  3254.                             + "\nPosition Size: " + positionSizeLong   
  3255.                        
  3256.                             ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3257.                         }
  3258.                     }
  3259.                
  3260.                     #endregion
  3261.                    
  3262.                     #endregion
  3263.                                        
  3264.                 }
  3265.                
  3266.                
  3267.                 //Short Trades
  3268.                 if (shortButtonHLClicked == true || shortButtonMarketClicked == true || shortLineButtonClicked == true || customShortClicked == true)
  3269.                 {
  3270.                
  3271.                     #region Position Size Short
  3272.                
  3273.                 if (autoPositionSize)
  3274.                 {
  3275.                     if (rrMode)
  3276.                     {
  3277.                         riskOffset = MaxLossPerTrade / ( ( (ShortValuesOffset) / TickSize) * myDbl);
  3278.                     }
  3279.                    
  3280.                     if (tickMode)
  3281.                     {
  3282.                         riskOffset = MaxLossPerTrade / ( ( (candleBarOffsetStop) / TickSize) * myDbl);
  3283.                     }
  3284.                 }
  3285.                
  3286.                 else if (customPositionSize)
  3287.                 {
  3288.                     riskOffset = CustomPositionAmount;
  3289.                 }
  3290.                
  3291.                 positionSizeShort = (Convert.ToInt32(riskOffset));
  3292.                
  3293.                
  3294.                     //Single Target
  3295.                     if (dualTarget == false)
  3296.                     {
  3297.                         positionSizeShort = (Convert.ToInt32(riskOffset));
  3298.                        
  3299.                         if (positionSizeShort < 1)
  3300.                         {
  3301.                             positionSizeShort = 1;
  3302.                         }
  3303.                     }
  3304.                    
  3305.                     //Dual Target
  3306.                     if (dualTarget)
  3307.                     {
  3308.                        
  3309.                     firstTargetPositionShort = (Convert.ToInt32(positionSizeShort * splitPercent));
  3310.                        
  3311.                         if (firstTargetPositionShort < 1)
  3312.                         {
  3313.                             firstTargetPositionShort = 1;
  3314.                         }
  3315.                
  3316.                     secondTargetPositionShort = positionSizeShort - firstTargetPositionShort;
  3317.                        
  3318.                         if(secondTargetPositionShort < 1)
  3319.                         {
  3320.                             secondTargetPositionShort = 1;
  3321.                         }  
  3322.                     }
  3323.                    
  3324.                         #region Position Size Prints
  3325.                        
  3326.                         if (SystemPrint)
  3327.                         {
  3328.                             if (PositionSizePrints)
  3329.                             {
  3330.                                 Print("positionSizeShort "+ positionSizeShort + " " + Time[0]);
  3331.                                 Print("firstTargetPositionShort "+ firstTargetPositionShort + " " + Time[0]);
  3332.                                 Print("secondTargetPositionShort "+ secondTargetPositionShort + " " + Time[0]);
  3333.                             }
  3334.                         }
  3335.                        
  3336.                         #endregion
  3337.                        
  3338.                    
  3339.                     #endregion
  3340.                
  3341.                     #region Set Stop/Profit Short
  3342.                
  3343.                 if (High[0] < stopShort)
  3344.                 {
  3345.                     setStopShort = stopShort;
  3346.                
  3347.                     setFirstTargetShort = enterShort - (ShortValuesOffset * FirstTargetRR);
  3348.                     setFinalTargetShort = enterShort - (ShortValuesOffset * FinalTargetRR);
  3349.                 }
  3350.                
  3351.                 else if (High[0] >= stopShort)
  3352.                 {
  3353.                     setStopShort = High[0] + candleBarOffsetStop;
  3354.                    
  3355.                     setFirstTargetShort = enterShort - ((setStopShort - enterShort) * FirstTargetRR);
  3356.                     setFinalTargetShort = enterShort - ((setStopShort - enterShort) * FinalTargetRR);
  3357.                 }
  3358.                
  3359.                
  3360.                 #region Profit Target Prints
  3361.                        
  3362.                         if (SystemPrint)
  3363.                         {
  3364.                             if (ProfitTatgetPrints)
  3365.                             {
  3366.                                 Print("setStopShort "+ setStopLong + " " + Time[0]);
  3367.                                 Print("setFirstTargetShort "+ setFirstTargetShort + " " + Time[0]);
  3368.                                 Print("setFinalTargetShort "+ setFinalTargetShort + " " + Time[0]);
  3369.                             }
  3370.                         }
  3371.                        
  3372.                         #endregion
  3373.                
  3374.                 #endregion
  3375.                    
  3376.                     #region Draw Lines / Text Short Offset
  3377.                
  3378.                         #region RR Mode
  3379.                        
  3380.                 if (rrMode)
  3381.                 {
  3382.                     RemoveDrawObject("EntryLine");
  3383.                     RemoveDrawObject("StopLine");
  3384.                    
  3385.                    
  3386.                     Draw.HorizontalLine(this, "EntryLine", enterShort, Brushes.Green);
  3387.                     Draw.HorizontalLine(this, "StopLine", stopShort, Brushes.Red);
  3388.                    
  3389.                     if (DisplayText)
  3390.                     {
  3391.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterShort, 4) + ("("+CandleLookBackEntry+")")
  3392.                         + "\nStop Line: " + Math.Round(stopShort, 4) + ("("+CandleLookBackStop+")")
  3393.                            
  3394.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  3395.                         + "\nRange($): " + ShortValuesOffset
  3396.                         + "\nRange(Ticks): " + ShortValuesOffset / TickSize
  3397.                         + "\nPosition Size: " + positionSizeShort  
  3398.                        
  3399.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3400.                     }
  3401.                    
  3402.                 }
  3403.                        
  3404.                     #endregion
  3405.                    
  3406.                         #region Tick Mode
  3407.                        
  3408.                 if (tickMode)
  3409.                 {
  3410.                     RemoveDrawObject("EntryLine");
  3411.                     RemoveDrawObject("StopLine");
  3412.                    
  3413.                    
  3414.                     Draw.HorizontalLine(this, "EntryLine", enterShort, Brushes.Green);
  3415.                     Draw.HorizontalLine(this, "StopLine", enterShort + candleBarOffsetStop, Brushes.Red);
  3416.                    
  3417.                     if (DisplayText)
  3418.                     {
  3419.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(enterShort, 4) + ("("+CandleLookBackEntry+")")
  3420.                         + "\nStop Line: " + Math.Round(enterShort + candleBarOffsetStop, 4) + ("("+candleBarOffsetStop / TickSize+")")
  3421.                            
  3422.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  3423.                         + "\nRange($): " + candleBarOffsetStop
  3424.                         + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  3425.                         + "\nPosition Size: " + positionSizeShort  
  3426.                        
  3427.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3428.                     }
  3429.                    
  3430.                 }
  3431.                        
  3432.                     #endregion
  3433.                    
  3434.                 #endregion
  3435.                
  3436.                 }
  3437.             }
  3438.            
  3439.             #endregion 
  3440.            
  3441.                     #region W/O Offset
  3442.             /* Removed for simplicity of use
  3443.             if (AddOffset == false)
  3444.             {  
  3445.                 //Long Trades
  3446.                 if (longButtonHLClicked == true || longButtonMarketClicked == true || longLineButtonClicked == true || customLongClicked == true)
  3447.                 {
  3448.                
  3449.                     #region Position Size Long
  3450.                
  3451.                 if (autoPositionSize)
  3452.                 {
  3453.                     riskOffset = MaxLossPerTrade / ( ( (LongValues) / TickSize) * myDbl);
  3454.                 }
  3455.                
  3456.                 else if (customPositionSize)
  3457.                 {
  3458.                     riskOffset = CustomPositionAmount;
  3459.                 }
  3460.                
  3461.                 positionSize = (Convert.ToInt32(riskOffset));
  3462.                
  3463.                
  3464.                     //Single Target
  3465.                     if (dualTarget == false)
  3466.                     {
  3467.                         positionSize = (Convert.ToInt32(riskOffset));
  3468.                        
  3469.                         if (positionSize < 1)
  3470.                         {
  3471.                             positionSize = 1;
  3472.                         }
  3473.                     }
  3474.                    
  3475.                     //Dual Target
  3476.                     if (dualTarget)
  3477.                     {
  3478.                        
  3479.                     firstTargetPosition = (Convert.ToInt32(positionSize * splitPercent));
  3480.                        
  3481.                         if (firstTargetPosition < 1)
  3482.                         {
  3483.                             firstTargetPosition = 1;
  3484.                         }
  3485.                
  3486.                     secondTargetPosition = positionSize - firstTargetPosition;
  3487.                        
  3488.                         if(secondTargetPosition < 1)
  3489.                         {
  3490.                             secondTargetPosition = 1;
  3491.                         }  
  3492.                     }
  3493.                    
  3494.                         #region Position Size Prints
  3495.                        
  3496.                         if (SystemPrint)
  3497.                         {
  3498.                             if (PositionSizePrints)
  3499.                             {
  3500.                                 Print("positionSize "+ positionSize + " " + Time[0]);
  3501.                                 Print("firstTargetPosition "+ firstTargetPosition + " " + Time[0]);
  3502.                                 Print("secondTargetPosition "+ secondTargetPosition + " " + Time[0]);
  3503.                             }
  3504.                         }
  3505.                        
  3506.                         #endregion
  3507.                        
  3508.                    
  3509.                    
  3510.                
  3511.                     #endregion
  3512.                    
  3513.                     #region Set Stop/Profit Long       
  3514.                    
  3515.                 if (Low[0] > stopAreaLong)
  3516.                 {
  3517.                     setStopLong = stopAreaLong;
  3518.                 }
  3519.                
  3520.                 else if (Low[0] <= stopAreaLong)
  3521.                 {
  3522.                     setStopLong = Low[0];
  3523.                 }
  3524.                
  3525.                 setFirstTarget = entryAreaLong + (LongValues * FirstTargetRR);
  3526.                 setFinalTarget = entryAreaLong + (LongValues * FinalTargetRR);
  3527.                
  3528.                 #endregion
  3529.                
  3530.                     #region Draw Lines / Text Long W/O Offset
  3531.                
  3532.                     #region RR mode
  3533.                
  3534.                 if (rrMode)
  3535.                 {
  3536.                     RemoveDrawObject("EntryLine");
  3537.                     RemoveDrawObject("StopLine");
  3538.                    
  3539.                    
  3540.                     Draw.HorizontalLine(this, "EntryLine", entryAreaLong, Brushes.Green);
  3541.                     Draw.HorizontalLine(this, "StopLine", stopAreaLong, Brushes.Red);
  3542.                    
  3543.                     if (DisplayText)
  3544.                     {
  3545.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaLong, 2) + ("("+CandleLookBackEntry+")")
  3546.                         + "\nStop Line: " + Math.Round(stopAreaLong, 2) + ("("+CandleLookBackStop+")")
  3547.                            
  3548.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  3549.                         + "\nRange($): " + LongValues  
  3550.                         + "\nRange(Ticks): " + LongValues / TickSize
  3551.                         + "\nPosition Size: " + positionSize   
  3552.                        
  3553.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3554.                     }
  3555.                 }
  3556.                    
  3557.                     #endregion
  3558.                
  3559.                     #region Tick mode
  3560.                
  3561.                 if (tickMode)
  3562.                 {
  3563.                     RemoveDrawObject("EntryLine");
  3564.                     RemoveDrawObject("StopLine");
  3565.                    
  3566.                    
  3567.                     Draw.HorizontalLine(this, "EntryLine", entryAreaLong, Brushes.Green);
  3568.                     Draw.HorizontalLine(this, "StopLine", entryAreaLong - candleBarOffsetStop, Brushes.Red);
  3569.                    
  3570.                     if (DisplayText)
  3571.                     {
  3572.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaLong, 2) + ("("+CandleLookBackEntry+")")
  3573.                         + "\nStop Line: " + Math.Round(entryAreaLong - candleBarOffsetStop, 2) + ("("+candleBarOffsetStop / TickSize+")")
  3574.                            
  3575.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  3576.                         + "\nRange($): " + candleBarOffsetStop 
  3577.                         + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  3578.                         + "\nPosition Size: " + positionSize   
  3579.                        
  3580.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3581.                     }
  3582.                 }
  3583.                    
  3584.                     #endregion
  3585.                    
  3586.                     #endregion
  3587.                
  3588.                 }
  3589.                
  3590.                 //Short Trades
  3591.                 if (shortButtonHLClicked == true || shortButtonMarketClicked == true || shortLineButtonClicked == true || customShortClicked == true)
  3592.                 {
  3593.                
  3594.                     #region Position Size Short
  3595.                
  3596.                 if (autoPositionSize)
  3597.                 {
  3598.                     riskOffset = MaxLossPerTrade / ( ( (ShortValues) / TickSize) * myDbl);
  3599.                 }
  3600.                
  3601.                 else if (customPositionSize)
  3602.                 {
  3603.                     riskOffset = CustomPositionAmount;
  3604.                 }
  3605.                
  3606.                 positionSize = (Convert.ToInt32(riskOffset));
  3607.                
  3608.                
  3609.                     //Single Target
  3610.                     if (dualTarget == false)
  3611.                     {
  3612.                         positionSize = (Convert.ToInt32(riskOffset));
  3613.                        
  3614.                         if (positionSize < 1)
  3615.                         {
  3616.                             positionSize = 1;
  3617.                         }
  3618.                     }
  3619.                    
  3620.                     //Dual Target
  3621.                     if (dualTarget)
  3622.                     {
  3623.                        
  3624.                     firstTargetPosition = (Convert.ToInt32(positionSize * splitPercent));
  3625.                        
  3626.                         if (firstTargetPosition < 1)
  3627.                         {
  3628.                             firstTargetPosition = 1;
  3629.                         }
  3630.                
  3631.                     secondTargetPosition = positionSize - firstTargetPosition;
  3632.                        
  3633.                         if(secondTargetPosition < 1)
  3634.                         {
  3635.                             secondTargetPosition = 1;
  3636.                         }  
  3637.                     }
  3638.                    
  3639.                         #region Position Size Prints
  3640.                        
  3641.                         if (SystemPrint)
  3642.                         {
  3643.                             if (PositionSizePrints)
  3644.                             {
  3645.                                 Print("positionSize "+ positionSize + " " + Time[0]);
  3646.                                 Print("firstTargetPosition "+ firstTargetPosition + " " + Time[0]);
  3647.                                 Print("secondTargetPosition "+ secondTargetPosition + " " + Time[0]);
  3648.                             }
  3649.                         }
  3650.                        
  3651.                         #endregion
  3652.                        
  3653.                    
  3654.                     #endregion
  3655.                    
  3656.                     #region Set Stop/Profit Short      
  3657.                    
  3658.                 if (High[0] < stopAreaShort)
  3659.                 {
  3660.                     setStopShort = stopAreaShort;
  3661.                 }
  3662.                
  3663.                 else if (High[0] >= stopAreaShort)
  3664.                 {
  3665.                     setStopShort = High[0];
  3666.                 }
  3667.                
  3668.                 setFirstTarget = entryAreaShort - (ShortValues * FirstTargetRR);
  3669.                 setFinalTarget = entryAreaShort - (ShortValues * FinalTargetRR);
  3670.                
  3671.                 #endregion
  3672.                
  3673.                     #region Draw Lines / Text Short W/O Offset
  3674.                
  3675.                     #region RR mode
  3676.                
  3677.                 if (rrMode)
  3678.                 {
  3679.                     RemoveDrawObject("EntryLine");
  3680.                     RemoveDrawObject("StopLine");
  3681.                    
  3682.                    
  3683.                     Draw.HorizontalLine(this, "EntryLine", entryAreaShort, Brushes.Green);
  3684.                     Draw.HorizontalLine(this, "StopLine", stopAreaShort, Brushes.Red);
  3685.                    
  3686.                     if (DisplayText)
  3687.                     {
  3688.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaShort, 2) + ("("+CandleLookBackEntry+")")
  3689.                         + "\nStop Line: " + Math.Round(stopAreaShort, 2) + ("("+CandleLookBackStop+")")
  3690.                            
  3691.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  3692.                         + "\nRange($): " + ShortValues 
  3693.                         + "\nRange(Ticks): " + ShortValues / TickSize
  3694.                         + "\nPosition Size: " + positionSize   
  3695.                        
  3696.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3697.                     }
  3698.                 }
  3699.                
  3700.                     #endregion
  3701.                
  3702.                     #region Tick mode
  3703.                
  3704.                 if (tickMode)
  3705.                 {
  3706.                     RemoveDrawObject("EntryLine");
  3707.                     RemoveDrawObject("StopLine");
  3708.                    
  3709.                    
  3710.                     Draw.HorizontalLine(this, "EntryLine", entryAreaShort, Brushes.Green);
  3711.                     Draw.HorizontalLine(this, "StopLine", entryAreaShort + candleBarOffsetStop, Brushes.Red);
  3712.                    
  3713.                     if (DisplayText)
  3714.                     {
  3715.                         Draw.TextFixed(this, "TextBox", "Entry Line: " + Math.Round(entryAreaShort, 2) + ("("+CandleLookBackEntry+")")
  3716.                         + "\nStop Line: " + Math.Round( entryAreaShort + candleBarOffsetStop, 2) + ("("+candleBarOffsetStop / TickSize+")")
  3717.                            
  3718.                         + "\n\nMax Loss($): " + MaxLossPerTrade
  3719.                         + "\nRange($): " + candleBarOffsetStop 
  3720.                         + "\nRange(Ticks): " + candleBarOffsetStop / TickSize
  3721.                         + "\nPosition Size: " + positionSize   
  3722.                        
  3723.                         ,TextPosition.BottomLeft, Brushes.White, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Gold, Brushes.Black, 100);
  3724.                     }
  3725.                 }
  3726.                
  3727.                     #endregion
  3728.                
  3729.                     #endregion
  3730.                
  3731.                 }
  3732.                
  3733.             }
  3734.             */
  3735.             #endregion //Removed for now
  3736.            
  3737.                 }
  3738.            
  3739.                 //ChartControl.Dispatcher.InvokeAsync((Action)(() =>
  3740.                     //{
  3741.                         //NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector = (Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown);
  3742.  
  3743.                         //quantitySelector.Value = positionSize;
  3744.                     //}));
  3745.                
  3746.                 #region Arm Market Order (Unlocked Lines) //Ensures Stop and Position size are calculated before triggering
  3747.                
  3748.                 if ((customLongClicked || customShortClicked) && armMarket == true && enterClosePrice == false)
  3749.                     {
  3750.                         armMarketCount ++;
  3751.                         Print(armMarketCount);
  3752.                     }
  3753.                    
  3754.                 if ((customLongClicked || customShortClicked)  && enterClosePrice == false && armMarketCount > 1) //&& armMarket == true)  
  3755.                     {
  3756.                         activateMarket = true;
  3757.                         Print("activateMarket Calcs " + activateMarket);
  3758.                         Print(armMarketCount);
  3759.                     }
  3760.                    
  3761.                 if ((customLongClicked || customShortClicked) && armMarket == true && enterClosePrice == false && armMarketCount < 1)
  3762.                 {
  3763.                     armMarketCount = 1;
  3764.                 }
  3765.  
  3766.                 #endregion
  3767.                        
  3768.                 countOnce = false;
  3769.             }
  3770.            
  3771.                 #region Arm Market Order (Locked Lines) //Stop and Position Size are already calculated
  3772.            
  3773.             if (IsFirstTickOfBar)
  3774.             {  
  3775.                 if (unlockButtonClicked && (customLongClicked || customShortClicked) && enterClosePrice == false)//armMarket == true && )
  3776.                 {
  3777.                     activateMarket = true;
  3778.                     Print("activateMarket Calcs Locked " + activateMarket);
  3779.                 }
  3780.             }
  3781.            
  3782.             #endregion
  3783.            
  3784.             if (unlockButtonClicked == false)
  3785.             {
  3786.                 if (IsFirstTickOfBar)
  3787.                 {
  3788.                     countOnce = true;
  3789.                 }
  3790.             }
  3791.            
  3792.             if (IsFirstTickOfBar || (trailButtonClicked && IsFirstTickOfBar))
  3793.             {
  3794.                 #region Trail Stop new bar Update
  3795.                
  3796.                 //If the strategy is in a position. This allows the trail stop to keep making calculations and continue moving every new candle
  3797.                 if (Position.MarketPosition != MarketPosition.Flat)
  3798.                 {
  3799.                     myFreeCandleTrail = true;
  3800.                    
  3801.                     if (SystemPrint)
  3802.                     {
  3803.                         if (TrailPrints)
  3804.                         {
  3805.                             Print("myFree Trail First Tick " + myFreeCandleTrail + " " + Time[1]);
  3806.                         }
  3807.                     }
  3808.                 }
  3809.  
  3810.                 #endregion
  3811.             }
  3812.            
  3813.             if ((IsFirstTickOfBar) && (isFib == true))
  3814.             {
  3815.                 fibCount ++;
  3816.             }
  3817.            
  3818.            
  3819.             /// Entries
  3820.        
  3821.             #region H/L Long
  3822.            
  3823.             if (
  3824.                 (longButtonHLClicked == true)
  3825.                     && (customLongClicked == false)
  3826.                         && (Position.MarketPosition == MarketPosition.Flat)
  3827.                             && (Close[0] >= enterLong)
  3828.                                 && (myFreeLimit)
  3829.                 )
  3830.             {
  3831.                 #region No Limit
  3832.                 //Enters With a Market Order After Entry Price has been crossed (Essentially a Stop Market Order)
  3833.                 if (useLimit == false)
  3834.                 {
  3835.                     if (dualTarget == false)
  3836.                     {
  3837.                         EnterLong(positionSizeLong, "MyEntryLong");
  3838.                     }
  3839.                    
  3840.                     else if (dualTarget)
  3841.                     {
  3842.                         EnterLong(firstTargetPositionLong, "MyEntryLong"); 
  3843.                        
  3844.                         EnterLong(secondTargetPositionLong, "MyEntryLong2");
  3845.                     }
  3846.                 }
  3847.                
  3848.                 #endregion
  3849.                
  3850.                 #region Use Limits
  3851.                 //Enters With Limit Orders After Entry Price has been crossed (Essentially a Stop Limit Order)
  3852.                 if (useLimit)
  3853.                 {
  3854.                     if (dualTarget == false)
  3855.                     {
  3856.                         EnterLongLimit(positionSizeLong, limitPriceSetLong, "MyEntryLong");
  3857.                     }
  3858.                    
  3859.                     else if (dualTarget)
  3860.                     {
  3861.                         EnterLongLimit(firstTargetPositionLong, limitPriceSetLong, "MyEntryLong");
  3862.                        
  3863.                         EnterLongLimit(secondTargetPositionLong, limitPriceSetLong, "MyEntryLong2");
  3864.                     }
  3865.                 }
  3866.                
  3867.                 #endregion
  3868.                
  3869.                 isFib                   = true;
  3870.                 myFreeTrade             = true;
  3871.                 longButtonHLClicked     = false;
  3872.             }
  3873.            
  3874.             #endregion
  3875.            
  3876.             #region H/L Short
  3877.            
  3878.             if (
  3879.                 (shortButtonHLClicked == true)
  3880.                     && (customLongClicked == false)
  3881.                         && (Position.MarketPosition == MarketPosition.Flat)
  3882.                             && (Close[0] <= enterShort)
  3883.                                 && (myFreeLimit)
  3884.                 )
  3885.             {
  3886.                 #region No Limit
  3887.                 //Enters With a Market Order After Entry Price has been crossed (Essentially a Stop Market Order)
  3888.                 if (useLimit == false)
  3889.                 {
  3890.                     if (dualTarget == false)
  3891.                     {
  3892.                         EnterShort(positionSizeShort, "MyEntryShort");
  3893.                     }
  3894.                    
  3895.                     else if (dualTarget)
  3896.                     {
  3897.                         EnterShort(firstTargetPositionShort, "MyEntryShort");  
  3898.                        
  3899.                         EnterShort(secondTargetPositionShort, "MyEntryShort2");
  3900.                     }
  3901.                 }
  3902.                
  3903.                 #endregion
  3904.                
  3905.                 #region Use Limits
  3906.                 //Enters With Limit Orders After Entry Price has been crossed (Essentially a Stop Limit Order)
  3907.                 if (useLimit)
  3908.                 {
  3909.                     if (dualTarget == false)
  3910.                     {
  3911.                         EnterShortLimit(positionSizeShort, limitPriceSetShort, "MyEntryShort");
  3912.                     }
  3913.                    
  3914.                     else if (dualTarget)
  3915.                     {
  3916.                         EnterShortLimit(firstTargetPositionShort, limitPriceSetShort, "MyEntryShort");
  3917.                        
  3918.                         EnterShortLimit(secondTargetPositionShort, limitPriceSetShort, "MyEntryShort2");
  3919.                     }
  3920.                 }
  3921.                
  3922.                 #endregion
  3923.                
  3924.                 isFib                   = true;
  3925.                 myFreeTrade             = true;
  3926.                 shortButtonHLClicked    = false;
  3927.             }
  3928.            
  3929.             #endregion
  3930.            
  3931.            
  3932.             #region Market Long
  3933.            
  3934.             if (
  3935.                 (longButtonMarketClicked == true)
  3936.                     && (Position.MarketPosition == MarketPosition.Flat)
  3937.                 )
  3938.             {
  3939.                 #region Market Long Entry
  3940.                
  3941.                     if (dualTarget == false)
  3942.                     {
  3943.                         EnterLong(positionSizeLong, "MyEntryLong");
  3944.                     }
  3945.                    
  3946.                     else if (dualTarget)
  3947.                     {
  3948.                         EnterLong(firstTargetPositionLong, "MyEntryLong"); 
  3949.                        
  3950.                         EnterLong(secondTargetPositionLong, "MyEntryLong2");
  3951.                     }
  3952.                    
  3953.                 #endregion
  3954.                    
  3955.                 isFib                   = true;
  3956.                 myFreeTrade             = true;
  3957.                 longButtonMarketClicked = false;
  3958.                    
  3959.             }
  3960.            
  3961.             #endregion
  3962.            
  3963.             #region Market Short
  3964.            
  3965.             if (
  3966.                 (shortButtonMarketClicked == true)
  3967.                     && (Position.MarketPosition == MarketPosition.Flat)
  3968.                 )
  3969.             {
  3970.                 #region Market Short Entry
  3971.                
  3972.                     if (dualTarget == false)
  3973.                     {
  3974.                         EnterShort(positionSizeShort, "MyEntryShort");
  3975.                     }
  3976.                    
  3977.                     else if (dualTarget)
  3978.                     {
  3979.                         EnterShort(firstTargetPositionShort, "MyEntryShort");  
  3980.                        
  3981.                         EnterShort(secondTargetPositionShort, "MyEntryShort2");
  3982.                     }
  3983.                    
  3984.                 #endregion
  3985.                
  3986.                 isFib                       = true;
  3987.                 myFreeTrade                 = true;
  3988.                 shortButtonMarketClicked    = false;       
  3989.             }
  3990.            
  3991.             #endregion
  3992.            
  3993.            
  3994.             #region Close Long
  3995.            
  3996.             if (
  3997.                 (customLongClicked == true)
  3998.                     && (armMarket == false)
  3999.                         && (Position.MarketPosition == MarketPosition.Flat)
  4000.                             && (Close[0] >= enterLong)
  4001.                                 && (myFreeLimit)
  4002.                 )
  4003.             {
  4004.                 #region No Limit
  4005.                 //Enters With a Market Order After Entry Price has been crossed (Essentially a Stop Market Order)
  4006.                 if (useLimit == false)
  4007.                 {
  4008.                     if (dualTarget == false)
  4009.                     {
  4010.                         EnterLong(positionSizeLong, "MyEntryLong");
  4011.                     }
  4012.                    
  4013.                     else if (dualTarget)
  4014.                     {
  4015.                         EnterLong(firstTargetPositionLong, "MyEntryLong"); 
  4016.                        
  4017.                         EnterLong(secondTargetPositionLong, "MyEntryLong2");
  4018.                     }
  4019.                 }
  4020.                
  4021.                 #endregion
  4022.                
  4023.                 #region Use Limits
  4024.                 //Enters With Limit Orders After Entry Price has been crossed (Essentially a Stop Limit Order)
  4025.                 if (useLimit)
  4026.                 {
  4027.                     if (dualTarget == false)
  4028.                     {
  4029.                         EnterLongLimit(positionSizeLong, limitPriceSetLong, "MyEntryLong");
  4030.                     }
  4031.                    
  4032.                     else if (dualTarget)
  4033.                     {
  4034.                         EnterLongLimit(firstTargetPositionLong, limitPriceSetLong, "MyEntryLong");
  4035.                        
  4036.                         EnterLongLimit(secondTargetPositionLong, limitPriceSetLong, "MyEntryLong2");
  4037.                     }
  4038.                 }
  4039.                
  4040.                 #endregion
  4041.                
  4042.                 isFib                   = true;
  4043.                 myFreeTrade             = true;
  4044.                 customLongClicked       = false;
  4045.             }
  4046.            
  4047.             #endregion
  4048.            
  4049.             #region Close Short
  4050.            
  4051.             if (
  4052.                 (customShortClicked == true)
  4053.                     && (armMarket == false)
  4054.                         && (Position.MarketPosition == MarketPosition.Flat)
  4055.                             && (Close[0] <= enterShort)
  4056.                                 && (myFreeLimit)
  4057.                 )
  4058.             {
  4059.                 #region No Limit
  4060.                 //Enters With a Market Order After Entry Price has been crossed (Essentially a Stop Market Order)
  4061.                 if (useLimit == false)
  4062.                 {
  4063.                     if (dualTarget == false)
  4064.                     {
  4065.                         EnterShort(positionSizeShort, "MyEntryShort");
  4066.                     }
  4067.                    
  4068.                     else if (dualTarget)
  4069.                     {
  4070.                         EnterShort(firstTargetPositionShort, "MyEntryShort");  
  4071.                        
  4072.                         EnterShort(secondTargetPositionShort, "MyEntryShort2");
  4073.                     }
  4074.                 }
  4075.                
  4076.                 #endregion
  4077.                
  4078.                 #region Use Limits
  4079.                 //Enters With Limit Orders After Entry Price has been crossed (Essentially a Stop Limit Order)
  4080.                 if (useLimit)
  4081.                 {
  4082.                     if (dualTarget == false)
  4083.                     {
  4084.                         EnterShortLimit(positionSizeShort, limitPriceSetShort, "MyEntryShort");
  4085.                     }
  4086.                    
  4087.                     else if (dualTarget)
  4088.                     {
  4089.                         EnterShortLimit(firstTargetPositionShort, limitPriceSetShort, "MyEntryShort");
  4090.                        
  4091.                         EnterShortLimit(secondTargetPositionShort, limitPriceSetShort, "MyEntryShort2");
  4092.                     }
  4093.                 }
  4094.                
  4095.                 #endregion
  4096.                
  4097.                 isFib                   = true;
  4098.                 myFreeTrade             = true;
  4099.                 customShortClicked      = false;
  4100.             }
  4101.            
  4102.             #endregion
  4103.            
  4104.            
  4105.             if (activateMarket == true)
  4106.             {
  4107.            
  4108.             #region Arm Market Long
  4109.            
  4110.             if (
  4111.                 (customLongClicked == true)
  4112.                     && (armMarket)
  4113.                 )
  4114.             {
  4115.                 #region Arm Market Long Entry
  4116.                
  4117.                     if (dualTarget == false)
  4118.                     {
  4119.                         EnterLong(positionSizeLong, "MyEntryLong");
  4120.                     }
  4121.                    
  4122.                     else if (dualTarget)
  4123.                     {
  4124.                         EnterLong(firstTargetPositionLong, "MyEntryLong"); 
  4125.                        
  4126.                         EnterLong(secondTargetPositionLong, "MyEntryLong2");
  4127.                     }
  4128.                    
  4129.                 #endregion
  4130.                
  4131.                 isFib                   = true;
  4132.                 myFreeTrade             = true;
  4133.                 customLongClicked       = false;
  4134.                        
  4135.             }
  4136.            
  4137.             #endregion
  4138.            
  4139.             #region Arm Market Short
  4140.            
  4141.             if (
  4142.                 (customShortClicked == true)
  4143.                     && (armMarket)
  4144.                 )
  4145.             {
  4146.                 #region Arm Market Short Entry
  4147.                
  4148.                     if (dualTarget == false)
  4149.                     {
  4150.                         EnterShort(positionSizeShort, "MyEntryShort");
  4151.                     }
  4152.                    
  4153.                     else if (dualTarget)
  4154.                     {
  4155.                         EnterShort(firstTargetPositionShort, "MyEntryShort");  
  4156.                        
  4157.                         EnterShort(secondTargetPositionShort, "MyEntryShort2");
  4158.                     }
  4159.                
  4160.                 #endregion
  4161.                    
  4162.                 isFib                   = true;
  4163.                 myFreeTrade             = true;
  4164.                 customShortClicked      = false;
  4165.    
  4166.             }
  4167.            
  4168.             #endregion
  4169.            
  4170.             }
  4171.            
  4172.            
  4173.             ///Set Stop/Profit/ Management Targets
  4174.             if (rrMode)
  4175.             {
  4176.                 //Long
  4177.                 #region Filled Long Position   
  4178.            
  4179.                 #region Stop/Profits           
  4180.            
  4181.                 if (Position.MarketPosition == MarketPosition.Long && myFreeTrade == true && Position.Quantity == positionSizeLong)
  4182.                 {
  4183.                     if (dualTarget == false)
  4184.                     {
  4185.                         if (stopLoss)
  4186.                         {
  4187.                             ExitLongStopMarket(0, true, Position.Quantity, setStopLong, "MyStopLong", "MyEntryLong");
  4188.                         }
  4189.                        
  4190.                         if (profitTarget)
  4191.                         {
  4192.                             ExitLongLimit(0, true, Position.Quantity, setFinalTargetLong, "MyTargetLong", "MyEntryLong");
  4193.                         }
  4194.                     }
  4195.                
  4196.                 if (dualTarget)
  4197.                 {
  4198.                     if(stopLoss)
  4199.                     {
  4200.                         ExitLongStopMarket(0, true, Position.Quantity, setStopLong, "MyStopLong", "MyEntryLong");
  4201.                         ExitLongStopMarket(0, true, Position.Quantity, setStopLong, "MyStopLong2", "MyEntryLong2");
  4202.                     }
  4203.                    
  4204.                     if(profitTarget)
  4205.                     {
  4206.                         ExitLongLimit(0, true, Position.Quantity, setFirstTargetLong, "MyTargetLong", "MyEntryLong");
  4207.                         ExitLongLimit(0, true, Position.Quantity, setFinalTargetLong, "MyTargetLong2", "MyEntryLong2");
  4208.                     }  
  4209.                 }
  4210.                
  4211.                 #endregion
  4212.                
  4213.                 #region Management Targets
  4214.                
  4215.                 //Breakeven Area
  4216.                 breakevenAreaTrigger = enterLong + (enterLong - stopLong) * breakevenAreaTarget;
  4217.                 breakevenAreaStopSet = breakevenAreaLong - candleBarOffsetBreakeven;
  4218.            
  4219.                 if (breakevenAreaSetAuto)
  4220.                 {
  4221.                     myFreeBEArea = true;
  4222.                 }
  4223.                
  4224.                 //Breakeven Actual
  4225.                 breakevenActualTrigger = enterLong + (enterLong - stopLong) * breakevenActualTarget;
  4226.                 breakevenActualStopSet = Position.AveragePrice - candleBarOffsetBreakeven;
  4227.                
  4228.                 if (breakevenActualSetAuto)
  4229.                 {
  4230.                     myFreeBEActual = true;
  4231.                 }
  4232.                
  4233.                 //Candle Trail Stop
  4234.                 candleTrailTrigger = enterLong + (enterLong - stopLong) * candleTrailTarget;
  4235.                 //candleTrailStopSet = Low[1]; We set the stop later for new candle.
  4236.                
  4237.                 if (candleTrailSetAuto)
  4238.                 {
  4239.                     myFreeCandleTrail = true;
  4240.                     activeTrail = true;
  4241.                 }
  4242.                
  4243.                 #endregion
  4244.                
  4245.                 #region Management Prints
  4246.                
  4247.                 if (SystemPrint)
  4248.                 {
  4249.                     #region Breakeven
  4250.                    
  4251.                     if (BreakevenPrints)
  4252.                     {
  4253.                         Print("breakeven(Area)Trigger " + breakevenAreaTrigger + " " +  Time[1]);
  4254.                         Print("breakeven(Area)StopSet " + breakevenAreaStopSet + " " + Time[1]);
  4255.                         Print("myFreeBE(Area) " + myFreeBEArea + " " + Time[1]);
  4256.                        
  4257.                         Print("breakeven(Actual)Trigger " + breakevenActualTrigger + " " +  Time[1]);
  4258.                         Print("breakeven(Actual)StopSet " + breakevenActualStopSet + " " + Time[1]);
  4259.                         Print("myFreeBE(Actual) " + myFreeBEActual + " " + Time[1]);
  4260.                     }
  4261.                    
  4262.                     #endregion
  4263.                 }
  4264.                
  4265.                 #endregion
  4266.                
  4267.                 myFreeTrade = false;
  4268.                
  4269.                 myFillCheck = true;
  4270.             }
  4271.                
  4272.             #endregion
  4273.                
  4274.                 #region Partial Fill Long Position
  4275.            
  4276.                 #region Stop/Profits
  4277.                
  4278.             if (Position.MarketPosition == MarketPosition.Long && myFreeTrade == true && Position.Quantity < positionSizeLong && IsFirstTickOfBar)
  4279.             {
  4280.                 if (dualTarget == false)
  4281.                     {
  4282.                         if (stopLoss)
  4283.                         {
  4284.                             ExitLongStopMarket(0, true, Position.Quantity, setStopLong, "MyStopLong", "MyEntryLong");
  4285.                         }
  4286.                        
  4287.                         if (profitTarget)
  4288.                         {
  4289.                             ExitLongLimit(0, true, Position.Quantity, setFinalTargetLong, "MyTargetLong", "MyEntryLong");
  4290.                         }
  4291.                     }
  4292.                
  4293.                 if (dualTarget)
  4294.                 {
  4295.                     if(stopLoss)
  4296.                     {
  4297.                         ExitLongStopMarket(0, true, Position.Quantity, setStopLong, "MyStopLong", "MyEntryLong");
  4298.                         ExitLongStopMarket(0, true, Position.Quantity, setStopLong, "MyStopLong2", "MyEntryLong2");
  4299.                     }
  4300.                    
  4301.                     if(profitTarget)
  4302.                     {
  4303.                         ExitLongLimit(0, true, Position.Quantity, setFirstTargetLong, "MyTargetLong", "MyEntryLong");
  4304.                         ExitLongLimit(0, true, Position.Quantity, setFinalTargetLong, "MyTargetLong2", "MyEntryLong2");
  4305.                     }  
  4306.                 }
  4307.                
  4308.                 #endregion
  4309.                
  4310.                 #region Management Targets
  4311.                
  4312.                 //Breakeven Area
  4313.                 breakevenAreaTrigger = enterLong + (enterLong - stopLong) * breakevenAreaTarget;
  4314.                 breakevenAreaStopSet = breakevenAreaLong - candleBarOffsetBreakeven;
  4315.            
  4316.                 if (breakevenAreaSetAuto)
  4317.                 {
  4318.                     myFreeBEArea = true;
  4319.                 }
  4320.                
  4321.                 //Breakeven Actual
  4322.                 breakevenActualTrigger = enterLong + (enterLong - stopLong) * breakevenActualTarget;
  4323.                 breakevenActualStopSet = Position.AveragePrice - candleBarOffsetBreakeven;
  4324.                
  4325.                 if (breakevenActualSetAuto)
  4326.                 {
  4327.                     myFreeBEActual = true;
  4328.                 }
  4329.                
  4330.                 //Candle Trail Stop
  4331.                 candleTrailTrigger = enterLong + (enterLong - stopLong) * candleTrailTarget;
  4332.                 //candleTrailStopSet = Low[1]; We set the stop later for new candle.
  4333.                
  4334.                 if (candleTrailSetAuto)
  4335.                 {
  4336.                     myFreeCandleTrail = true;
  4337.                     activeTrail = true;
  4338.                 }
  4339.                
  4340.                 #endregion
  4341.                
  4342.                 #region Management Prints
  4343.                
  4344.                 if (SystemPrint)
  4345.                 {
  4346.                     #region Breakeven
  4347.                    
  4348.                     if (BreakevenPrints)
  4349.                     {
  4350.                         Print("breakevenAreaTrigger " + breakevenAreaTrigger + " " +  Time[1]);
  4351.                         Print("breakevenAreaStopSet " + breakevenAreaStopSet + " " + Time[1]);
  4352.                         Print("myFreeBEArea " + myFreeBEArea + " " + Time[1]);
  4353.                     }
  4354.                    
  4355.                     #endregion
  4356.                 }
  4357.                
  4358.                 #endregion
  4359.                
  4360.                 myFreeTrade = false;
  4361.             }
  4362.            
  4363.             #endregion
  4364.            
  4365.  
  4366.                 //Short
  4367.                 #region Filled Short Position  
  4368.            
  4369.                 #region Stop/Profits
  4370.            
  4371.                 if (Position.MarketPosition == MarketPosition.Short && myFreeTrade == true && Position.Quantity == positionSizeShort)
  4372.                 {
  4373.                     if (dualTarget == false)
  4374.                     {
  4375.                         if (stopLoss)
  4376.                         {
  4377.                             ExitShortStopMarket(0, true, Position.Quantity, setStopShort, "MyStopShort", "MyEntryShort");
  4378.                         }
  4379.                        
  4380.                         if (profitTarget)
  4381.                         {
  4382.                             ExitShortLimit(0, true, Position.Quantity, setFinalTargetShort, "MyTargetShort", "MyEntryShort");
  4383.                         }
  4384.                     }
  4385.                
  4386.                 if (dualTarget)
  4387.                 {
  4388.                     if(stopLoss)
  4389.                     {
  4390.                         ExitShortStopMarket(0, true, Position.Quantity, setStopShort, "MyStopShort", "MyEntryShort");
  4391.                         ExitShortStopMarket(0, true, Position.Quantity, setStopShort, "MyStopShort2", "MyEntryShort2");
  4392.                     }
  4393.                    
  4394.                     if(profitTarget)
  4395.                     {
  4396.                         ExitShortLimit(0, true, Position.Quantity, setFirstTargetShort, "MyTargetShort", "MyEntryShort");
  4397.                         ExitShortLimit(0, true, Position.Quantity, setFinalTargetShort, "MyTargetShort2", "MyEntryShort2");
  4398.                     }  
  4399.                 }
  4400.                
  4401.                 #endregion
  4402.                
  4403.                 #region Management Targets
  4404.                
  4405.                 //Breakeven Area
  4406.                 breakevenAreaTrigger = enterShort - (stopShort - enterShort) * breakevenAreaTarget;
  4407.                 breakevenAreaStopSet = breakevenAreaShort + candleBarOffsetBreakeven;
  4408.            
  4409.                 if (breakevenAreaSetAuto)
  4410.                 {
  4411.                     myFreeBEArea = true;
  4412.                 }
  4413.                
  4414.                 //Breakeven Actual
  4415.                 breakevenActualTrigger = enterShort - (stopShort - enterShort) * breakevenActualTarget;
  4416.                 breakevenActualStopSet = Position.AveragePrice + candleBarOffsetBreakeven;
  4417.                
  4418.                 if (breakevenActualSetAuto)
  4419.                 {
  4420.                     myFreeBEActual = true;
  4421.                 }
  4422.                
  4423.                 //Candle Trail Stop
  4424.                 candleTrailTrigger = enterShort - (stopShort - enterShort) * candleTrailTarget;
  4425.                
  4426.                
  4427.                 if (candleTrailSetAuto)
  4428.                 {
  4429.                     myFreeCandleTrail = true;
  4430.                     activeTrail = true;
  4431.                 }
  4432.                
  4433.                 #endregion
  4434.                
  4435.                 #region Management Prints
  4436.                
  4437.                 if (SystemPrint)
  4438.                 {
  4439.                     #region Breakeven
  4440.                    
  4441.                     if (BreakevenPrints)
  4442.                     {
  4443.                         Print("breakeven(Area)Trigger " + breakevenAreaTrigger + " " +  Time[1]);
  4444.                         Print("breakeven(Area)StopSet " + breakevenAreaStopSet + " " + Time[1]);
  4445.                         Print("myFreeBE(Area) " + myFreeBEArea + " " + Time[1]);
  4446.                        
  4447.                         Print("breakeven(Actual)Trigger " + breakevenActualTrigger + " " +  Time[1]);
  4448.                         Print("breakeven(Actual)StopSet " + breakevenActualStopSet + " " + Time[1]);
  4449.                         Print("myFreeBE(Actual) " + myFreeBEActual + " " + Time[1]);
  4450.                     }
  4451.                    
  4452.                     #endregion
  4453.                 }
  4454.                
  4455.                 #endregion
  4456.                
  4457.                 myFreeTrade = false;
  4458.                
  4459.                 myFillCheck = true;
  4460.             }
  4461.                
  4462.             #endregion
  4463.                
  4464.                 #region Partial Fill Short Position
  4465.                
  4466.                 #region Stop/Profits
  4467.                
  4468.             if (Position.MarketPosition == MarketPosition.Short && myFreeTrade == true && Position.Quantity < positionSizeShort && IsFirstTickOfBar)
  4469.             {
  4470.                 if (dualTarget == false)
  4471.                     {
  4472.                         if (stopLoss)
  4473.                         {
  4474.                             ExitShortStopMarket(0, true, Position.Quantity, setStopShort, "MyStopShort", "MyEntryShort");
  4475.                         }
  4476.                        
  4477.                         if (profitTarget)
  4478.                         {
  4479.                             ExitShortLimit(0, true, Position.Quantity, setFinalTargetShort, "MyTargetShort", "MyEntryShort");
  4480.                         }
  4481.                     }
  4482.                
  4483.                 if (dualTarget)
  4484.                 {
  4485.                     //positionSizeShort = myPosition;
  4486.                    
  4487.                     if(stopLoss)
  4488.                     {      
  4489.                         ExitShortStopMarket(0, true, Position.Quantity, setStopShort, "MyStopShort", "MyEntryShort");
  4490.                         ExitShortStopMarket(0, true, Position.Quantity, setStopShort, "MyStopShort2", "MyEntryShort2");
  4491.                        
  4492.                         Print("after Fill: " + Position.Quantity);
  4493.                     }
  4494.                    
  4495.                     if(profitTarget)
  4496.                     {
  4497.                         ExitShortLimit(0, true, Position.Quantity, setFirstTargetShort, "MyTargetShort", "MyEntryShort");
  4498.                         ExitShortLimit(0, true, Position.Quantity, setFinalTargetShort, "MyTargetShort2", "MyEntryShort2");
  4499.                     }  
  4500.                 }
  4501.                
  4502.                 #endregion
  4503.                
  4504.                 #region Management Targets
  4505.                
  4506.                 //Breakeven Area
  4507.                 breakevenAreaTrigger = enterShort - (stopShort - enterShort) * breakevenAreaTarget;
  4508.                 breakevenAreaStopSet = breakevenAreaShort + candleBarOffsetBreakeven;
  4509.            
  4510.                 if (breakevenAreaSetAuto)
  4511.                 {
  4512.                     myFreeBEArea = true;
  4513.                 }
  4514.                
  4515.                 //Breakeven Actual
  4516.                 breakevenActualTrigger = enterShort - (stopShort - enterShort) * breakevenActualTarget;
  4517.                 breakevenActualStopSet = Position.AveragePrice + candleBarOffsetBreakeven;
  4518.                
  4519.                 if (breakevenActualSetAuto)
  4520.                 {
  4521.                     myFreeBEActual = true;
  4522.                 }
  4523.                
  4524.                 //Candle Trail Stop
  4525.                 candleTrailTrigger = enterShort - (stopShort - enterShort) * candleTrailTarget;
  4526.                 //candleTrailStopSet = Low[1]; We set the stop later for new candle.
  4527.                
  4528.                 if (candleTrailSetAuto)
  4529.                 {
  4530.                     myFreeCandleTrail = true;
  4531.                     activeTrail = true;
  4532.                 }
  4533.                
  4534.                 #endregion
  4535.                
  4536.                 #region Management Prints
  4537.                
  4538.                 if (SystemPrint)
  4539.                 {
  4540.                     #region Breakeven
  4541.                    
  4542.                     if (BreakevenPrints)
  4543.                     {
  4544.                         Print("breakeven(Area)Trigger " + breakevenAreaTrigger + " " +  Time[1]);
  4545.                         Print("breakeven(Area)StopSet " + breakevenAreaStopSet + " " + Time[1]);
  4546.                         Print("myFreeBE(Area) " + myFreeBEArea + " " + Time[1]);
  4547.                        
  4548.                         Print("breakeven(Actual)Trigger " + breakevenActualTrigger + " " +  Time[1]);
  4549.                         Print("breakeven(Actual)StopSet " + breakevenActualStopSet + " " + Time[1]);
  4550.                         Print("myFreeBE(Actual) " + myFreeBEActual + " " + Time[1]);
  4551.                     }
  4552.                    
  4553.                     #endregion
  4554.                 }
  4555.                
  4556.                 #endregion
  4557.                
  4558.                 myFreeTrade = false;
  4559.             }
  4560.            
  4561.             #endregion
  4562.            
  4563.             }
  4564.            
  4565.             if (tickMode)
  4566.             {
  4567.                 //Long
  4568.                 #region Filled Long Position   
  4569.            
  4570.                 #region Stop/Profits           
  4571.            
  4572.                 if (Position.MarketPosition == MarketPosition.Long && myFreeTrade == true && Position.Quantity == positionSizeLong)
  4573.                 {
  4574.                     if (dualTarget == false)
  4575.                     {
  4576.                         if (stopLoss)
  4577.                         {
  4578.                             ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - candleBarOffsetStop, "MyStopLong", "MyEntryLong");
  4579.                         }
  4580.                        
  4581.                         if (profitTarget)
  4582.                         {
  4583.                             ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (FinalTargetRR * TickSize), "MyTargetLong", "MyEntryLong");
  4584.                         }
  4585.                     }
  4586.                
  4587.                 if (dualTarget)
  4588.                 {
  4589.                     if(stopLoss)
  4590.                     {
  4591.                         ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - candleBarOffsetStop, "MyStopLong", "MyEntryLong");
  4592.                         ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - candleBarOffsetStop, "MyStopLong2", "MyEntryLong2");
  4593.                     }
  4594.                    
  4595.                     if(profitTarget)
  4596.                     {
  4597.                         ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (FirstTargetRR * TickSize),  "MyTargetLong", "MyEntryLong");
  4598.                         ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (FinalTargetRR * TickSize), "MyTargetLong2", "MyEntryLong2");
  4599.                     }  
  4600.                 }
  4601.                
  4602.                 #endregion
  4603.                
  4604.                 #region Management Targets
  4605.                
  4606.                 //Breakeven Area
  4607.                 breakevenAreaTrigger = Position.AveragePrice + (breakevenAreaTarget * TickSize);
  4608.                 breakevenAreaStopSet = breakevenAreaLong - candleBarOffsetBreakeven;
  4609.            
  4610.                 if (breakevenAreaSetAuto)
  4611.                 {
  4612.                     myFreeBEArea = true;
  4613.                 }
  4614.                
  4615.                 //Breakeven Actual
  4616.                 breakevenActualTrigger = Position.AveragePrice + (breakevenActualTarget * TickSize);
  4617.                 breakevenActualStopSet = Position.AveragePrice - candleBarOffsetBreakeven;
  4618.                
  4619.                 if (breakevenActualSetAuto)
  4620.                 {
  4621.                     myFreeBEActual = true;
  4622.                 }
  4623.                
  4624.                 //Candle Trail Stop
  4625.                 candleTrailTrigger = Position.AveragePrice + (candleTrailTarget * TickSize);
  4626.                
  4627.                 if (candleTrailSetAuto)
  4628.                 {
  4629.                     myFreeCandleTrail = true;
  4630.                     activeTrail = true;
  4631.                 }
  4632.                
  4633.                 #endregion
  4634.                
  4635.                 #region Management Prints
  4636.                
  4637.                 if (SystemPrint)
  4638.                 {
  4639.                     #region Breakeven
  4640.                    
  4641.                     if (BreakevenPrints)
  4642.                     {
  4643.                         Print("breakeven(Area)Trigger " + breakevenAreaTrigger + " " +  Time[1]);
  4644.                         Print("breakeven(Area)StopSet " + breakevenAreaStopSet + " " + Time[1]);
  4645.                         Print("myFreeBE(Area) " + myFreeBEArea + " " + Time[1]);
  4646.                        
  4647.                         Print("breakeven(Actual)Trigger " + breakevenActualTrigger + " " +  Time[1]);
  4648.                         Print("breakeven(Actual)StopSet " + breakevenActualStopSet + " " + Time[1]);
  4649.                         Print("myFreeBE(Actual) " + myFreeBEActual + " " + Time[1]);
  4650.                     }
  4651.                    
  4652.                     #endregion
  4653.                 }
  4654.                
  4655.                 #endregion
  4656.                
  4657.                 myFreeTrade = false;
  4658.                
  4659.                 myFillCheck = true;
  4660.             }
  4661.                
  4662.             #endregion
  4663.                
  4664.                 #region Partial Fill Long Position
  4665.            
  4666.                 #region Stop/Profit
  4667.                
  4668.             if (Position.MarketPosition == MarketPosition.Long && myFreeTrade == true && Position.Quantity < positionSizeLong && IsFirstTickOfBar)
  4669.             {
  4670.                 if (dualTarget == false)
  4671.                     {
  4672.                         if (stopLoss)
  4673.                         {
  4674.                             ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - candleBarOffsetStop, "MyStopLong", "MyEntryLong");
  4675.                         }
  4676.                        
  4677.                         if (profitTarget)
  4678.                         {
  4679.                             ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (FinalTargetRR * TickSize), "MyTargetLong", "MyEntryLong");
  4680.                         }
  4681.                     }
  4682.                
  4683.                 if (dualTarget)
  4684.                 {
  4685.                     if(stopLoss)
  4686.                     {
  4687.                         ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - candleBarOffsetStop, "MyStopLong", "MyEntryLong");
  4688.                         ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - candleBarOffsetStop, "MyStopLong2", "MyEntryLong2");
  4689.                     }
  4690.                    
  4691.                     if(profitTarget)
  4692.                     {
  4693.                         ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (FirstTargetRR * TickSize), "MyTargetLong", "MyEntryLong");
  4694.                         ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (FinalTargetRR * TickSize), "MyTargetLong2", "MyEntryLong2");
  4695.                     }  
  4696.                 }
  4697.                
  4698.                 #endregion
  4699.                
  4700.                 #region Management Targets
  4701.                
  4702.                 //Breakeven Area
  4703.                 breakevenAreaTrigger = Position.AveragePrice + (breakevenAreaTarget * TickSize);
  4704.                 breakevenAreaStopSet = breakevenAreaLong - candleBarOffsetBreakeven;
  4705.            
  4706.                 if (breakevenAreaSetAuto)
  4707.                 {
  4708.                     myFreeBEArea = true;
  4709.                 }
  4710.                
  4711.                 //Breakeven Actual
  4712.                 breakevenActualTrigger = Position.AveragePrice + (breakevenActualTarget * TickSize);
  4713.                 breakevenActualStopSet = Position.AveragePrice - candleBarOffsetBreakeven;
  4714.                
  4715.                 if (breakevenActualSetAuto)
  4716.                 {
  4717.                     myFreeBEActual = true;
  4718.                 }
  4719.                
  4720.                 //Candle Trail Stop
  4721.                 candleTrailTrigger = Position.AveragePrice + (candleTrailTarget * TickSize);
  4722.                
  4723.                 if (candleTrailSetAuto)
  4724.                 {
  4725.                     myFreeCandleTrail = true;
  4726.                     activeTrail = true;
  4727.                 }
  4728.                
  4729.                 #endregion
  4730.                
  4731.                 #region Management Prints
  4732.                
  4733.                 if (SystemPrint)
  4734.                 {
  4735.                     #region Breakeven
  4736.                    
  4737.                     if (BreakevenPrints)
  4738.                     {
  4739.                         Print("breakevenAreaTrigger " + breakevenAreaTrigger + " " +  Time[1]);
  4740.                         Print("breakevenAreaStopSet " + breakevenAreaStopSet + " " + Time[1]);
  4741.                         Print("myFreeBEArea " + myFreeBEArea + " " + Time[1]);
  4742.                     }
  4743.                    
  4744.                     #endregion
  4745.                 }
  4746.                
  4747.                 #endregion
  4748.                
  4749.                 myFreeTrade = false;
  4750.             }
  4751.            
  4752.             #endregion
  4753.            
  4754.  
  4755.                 //Short
  4756.                 #region Filled Short Position  
  4757.            
  4758.                 #region Stop/Profits
  4759.            
  4760.                 if (Position.MarketPosition == MarketPosition.Short && myFreeTrade == true && Position.Quantity == positionSizeShort)
  4761.                 {
  4762.                     if (dualTarget == false)
  4763.                     {
  4764.                         if (stopLoss)
  4765.                         {
  4766.                             ExitShortStopMarket(0, true, Position.Quantity, Position.AveragePrice + candleBarOffsetStop, "MyStopShort", "MyEntryShort");
  4767.                         }
  4768.                        
  4769.                         if (profitTarget)
  4770.                         {
  4771.                             ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (FinalTargetRR * TickSize), "MyTargetShort", "MyEntryShort");
  4772.                         }
  4773.                     }
  4774.                
  4775.                 if (dualTarget)
  4776.                 {              
  4777.            
  4778.                     if(stopLoss)
  4779.                     {
  4780.                         ExitShortStopMarket(0, true, Position.Quantity, Position.AveragePrice + candleBarOffsetStop, "MyStopShort", "MyEntryShort");
  4781.                         ExitShortStopMarket(0, true, Position.Quantity, Position.AveragePrice + candleBarOffsetStop, "MyStopShort2", "MyEntryShort2");
  4782.                     }
  4783.                    
  4784.                     if(profitTarget)
  4785.                     {
  4786.                         ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (FirstTargetRR * TickSize), "MyTargetShort", "MyEntryShort");
  4787.                         ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (FinalTargetRR * TickSize), "MyTargetShort2", "MyEntryShort2");
  4788.                     }  
  4789.                 }
  4790.                
  4791.                 #endregion
  4792.                
  4793.                 #region Management Targets
  4794.                
  4795.                 //Breakeven Area
  4796.                 breakevenAreaTrigger = Position.AveragePrice - (breakevenAreaTarget * TickSize);
  4797.                 breakevenAreaStopSet = breakevenAreaShort + candleBarOffsetBreakeven;
  4798.            
  4799.                 if (breakevenAreaSetAuto)
  4800.                 {
  4801.                     myFreeBEArea = true;
  4802.                 }
  4803.                
  4804.                 //Breakeven Actual
  4805.                 breakevenActualTrigger = Position.AveragePrice - (breakevenActualTarget * TickSize);
  4806.                 breakevenActualStopSet = Position.AveragePrice + candleBarOffsetBreakeven;
  4807.                
  4808.                 if (breakevenActualSetAuto)
  4809.                 {
  4810.                     myFreeBEActual = true;
  4811.                 }
  4812.                
  4813.                 //Candle Trail Stop
  4814.                 candleTrailTrigger = Position.AveragePrice - (candleTrailTarget * TickSize);
  4815.                
  4816.                 if (candleTrailSetAuto)
  4817.                 {
  4818.                     myFreeCandleTrail = true;
  4819.                     activeTrail = true;
  4820.                 }
  4821.                
  4822.                 #endregion
  4823.                
  4824.                 #region Management Prints
  4825.                
  4826.                 if (SystemPrint)
  4827.                 {
  4828.                     #region Breakeven
  4829.                    
  4830.                     if (BreakevenPrints)
  4831.                     {
  4832.                         Print("breakeven(Area)Trigger " + breakevenAreaTrigger + " " +  Time[1]);
  4833.                         Print("breakeven(Area)StopSet " + breakevenAreaStopSet + " " + Time[1]);
  4834.                         Print("myFreeBE(Area) " + myFreeBEArea + " " + Time[1]);
  4835.                        
  4836.                         Print("breakeven(Actual)Trigger " + breakevenActualTrigger + " " +  Time[1]);
  4837.                         Print("breakeven(Actual)StopSet " + breakevenActualStopSet + " " + Time[1]);
  4838.                         Print("myFreeBE(Actual) " + myFreeBEActual + " " + Time[1]);
  4839.                     }
  4840.                    
  4841.                     #endregion
  4842.                 }
  4843.                
  4844.                 #endregion
  4845.                
  4846.                 myFreeTrade = false;
  4847.                
  4848.                 myFillCheck = true;
  4849.             }
  4850.                
  4851.             #endregion
  4852.                
  4853.                 #region Partial Fill Short Position
  4854.                
  4855.                 #region Stop/Profits
  4856.                
  4857.             if (Position.MarketPosition == MarketPosition.Short && myFreeTrade == true && Position.Quantity < positionSizeShort && IsFirstTickOfBar)
  4858.             {
  4859.                
  4860.                
  4861.                 if (dualTarget == false)
  4862.                     {
  4863.                         if (stopLoss)
  4864.                         {
  4865.                             ExitShortStopMarket(0, true, Position.Quantity, Position.AveragePrice + candleBarOffsetStop, "MyStopShort", "MyEntryShort");
  4866.                         }
  4867.                        
  4868.                         if (profitTarget)
  4869.                         {
  4870.                             ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (FinalTargetRR * TickSize), "MyTargetShort", "MyEntryShort");
  4871.                         }
  4872.                     }
  4873.                
  4874.                 if (dualTarget)
  4875.                 {
  4876.  
  4877.                    
  4878.                     if(stopLoss)
  4879.                     {
  4880.                         ExitShortStopMarket(0, true, Position.Quantity, Position.AveragePrice + candleBarOffsetStop, "MyStopShort", "MyEntryShort");
  4881.                         ExitShortStopMarket(0, true, Position.Quantity, Position.AveragePrice + candleBarOffsetStop, "MyStopShort2", "MyEntryShort2");
  4882.                     }
  4883.                    
  4884.                     if(profitTarget)
  4885.                     {
  4886.                         ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (FirstTargetRR * TickSize), "MyTargetShort", "MyEntryShort");
  4887.                         ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (FinalTargetRR * TickSize), "MyTargetShort2", "MyEntryShort2");
  4888.                     }  
  4889.                    
  4890.                    
  4891.                 }
  4892.                
  4893.                 #endregion
  4894.                
  4895.                 #region Management Targets
  4896.                
  4897.                 //Breakeven Area
  4898.                 breakevenAreaTrigger = Position.AveragePrice - (breakevenAreaTarget * TickSize);
  4899.                 breakevenAreaStopSet = breakevenAreaShort + candleBarOffsetBreakeven;
  4900.            
  4901.                 if (breakevenAreaSetAuto)
  4902.                 {
  4903.                     myFreeBEArea = true;
  4904.                 }
  4905.                
  4906.                 //Breakeven Actual
  4907.                 breakevenActualTrigger = Position.AveragePrice - (breakevenActualTarget * TickSize);
  4908.                 breakevenActualStopSet = Position.AveragePrice + candleBarOffsetBreakeven;
  4909.                
  4910.                 if (breakevenActualSetAuto)
  4911.                 {
  4912.                     myFreeBEActual = true;
  4913.                 }
  4914.                
  4915.                 //Candle Trail Stop
  4916.                 candleTrailTrigger = Position.AveragePrice - (candleTrailTarget * TickSize);
  4917.                
  4918.                 if (candleTrailSetAuto)
  4919.                 {
  4920.                     myFreeCandleTrail = true;
  4921.                     activeTrail = true;
  4922.                 }
  4923.                
  4924.                 #endregion
  4925.                
  4926.                 #region Management Prints
  4927.                
  4928.                 if (SystemPrint)
  4929.                 {
  4930.                     #region Breakeven
  4931.                    
  4932.                     if (BreakevenPrints)
  4933.                     {
  4934.                         Print("breakeven(Area)Trigger " + breakevenAreaTrigger + " " +  Time[1]);
  4935.                         Print("breakeven(Area)StopSet " + breakevenAreaStopSet + " " + Time[1]);
  4936.                         Print("myFreeBE(Area) " + myFreeBEArea + " " + Time[1]);
  4937.                        
  4938.                         Print("breakeven(Actual)Trigger " + breakevenActualTrigger + " " +  Time[1]);
  4939.                         Print("breakeven(Actual)StopSet " + breakevenActualStopSet + " " + Time[1]);
  4940.                         Print("myFreeBE(Actual) " + myFreeBEActual + " " + Time[1]);
  4941.                     }
  4942.                    
  4943.                     #endregion
  4944.                 }
  4945.                
  4946.                 #endregion
  4947.                
  4948.                 myFreeTrade = false;
  4949.             }
  4950.            
  4951.             #endregion
  4952.            
  4953.             }
  4954.            
  4955.            
  4956.             ///Management Logic - Breakeven/Trail Stop
  4957.        
  4958.             #region Breakeven Area
  4959.            
  4960.                 #region Long
  4961.            
  4962.             if (
  4963.                 (Position.MarketPosition == MarketPosition.Long)
  4964.                     && ((Close[0] >= breakevenAreaTrigger) || (breakevenButtonClicked))
  4965.                         && (myFreeBEArea == true)
  4966.                 )
  4967.             {
  4968.                 #region Filled Long Position   
  4969.            
  4970.                 if (Position.MarketPosition == MarketPosition.Long && myFreeBEArea == true && Position.Quantity == positionSizeLong)
  4971.                 {
  4972.                     if (dualTarget == false)
  4973.                     {
  4974.                         ExitLongStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopLong", "MyEntryLong");
  4975.                     }
  4976.                
  4977.                     if (dualTarget)
  4978.                     {
  4979.                         ExitLongStopMarket(0, true, firstTargetPositionLong, breakevenAreaStopSet, "MyStopLong", "MyEntryLong");
  4980.                         ExitLongStopMarket(0, true, secondTargetPositionLong, breakevenAreaStopSet, "MyStopLong2", "MyEntryLong2");
  4981.                     }
  4982.                
  4983.                 breakevenButtonClicked = false;
  4984.                 myFreeBEArea = false;
  4985.             }
  4986.                
  4987.             #endregion
  4988.                
  4989.                 #region Partial Fill Long Position
  4990.                
  4991.             if (Position.MarketPosition == MarketPosition.Long && myFreeBEArea == true && Position.Quantity < positionSizeLong)// && IsFirstTickOfBar)
  4992.             {
  4993.                 if (dualTarget == false)
  4994.                     {
  4995.                         ExitLongStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopLong", "MyEntryLong");
  4996.                     }
  4997.                    
  4998.                 if (dualTarget == true && myFillCheck == true)
  4999.                 {
  5000.                     ExitLongStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopLong", "MyEntryLong");
  5001.                     ExitLongStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopLong2", "MyEntryLong2");
  5002.                 }
  5003.            
  5004.                 breakevenButtonClicked = false;
  5005.                 myFreeBEArea = false;;
  5006.             }
  5007.            
  5008.             #endregion
  5009.             }
  5010.            
  5011.                 #endregion
  5012.            
  5013.                 #region Short
  5014.            
  5015.             if (
  5016.                 (Position.MarketPosition == MarketPosition.Short)
  5017.                     && ((Close[0] <= breakevenAreaTrigger) || (breakevenButtonClicked))
  5018.                         && (myFreeBEArea == true)
  5019.                 )
  5020.             {
  5021.                 #region Filled Short Position  
  5022.            
  5023.                 if (Position.MarketPosition == MarketPosition.Short && myFreeBEArea == true && Position.Quantity == positionSizeShort)
  5024.                 {
  5025.                     if (dualTarget == false)
  5026.                     {
  5027.                         ExitShortStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopShort", "MyEntryShort");
  5028.                     }
  5029.                
  5030.                 if (dualTarget)
  5031.                 {
  5032.                         ExitShortStopMarket(0, true, firstTargetPositionShort, breakevenAreaStopSet, "MyStopShort", "MyEntryShort");
  5033.                         ExitShortStopMarket(0, true, secondTargetPositionShort, breakevenAreaStopSet, "MyStopShort2", "MyEntryShort2");
  5034.                 }
  5035.                
  5036.                 breakevenButtonClicked = false;
  5037.                 myFreeBEArea = false;
  5038.             }
  5039.                
  5040.             #endregion
  5041.                
  5042.                 #region Partial Fill Short Position
  5043.                
  5044.             if (Position.MarketPosition == MarketPosition.Short && myFreeBEArea == true && Position.Quantity < positionSizeShort)
  5045.             {
  5046.                 if (dualTarget == false)
  5047.                 {
  5048.                     ExitShortStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopShort", "MyEntryShort");
  5049.                 }
  5050.                    
  5051.                 if (dualTarget == true && myFillCheck == true)
  5052.                 {
  5053.                     ExitShortStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopShort", "MyEntryShort");
  5054.                     ExitShortStopMarket(0, true, Position.Quantity, breakevenAreaStopSet, "MyStopShort2", "MyEntryShort2");
  5055.                 }
  5056.            
  5057.                 breakevenButtonClicked = false;
  5058.                 myFreeBEArea = false;;
  5059.             }
  5060.            
  5061.             #endregion
  5062.             }
  5063.            
  5064.                 #endregion
  5065.            
  5066.             #endregion
  5067.            
  5068.             #region Breakeven Actual
  5069.            
  5070.                 #region Long
  5071.            
  5072.             if (
  5073.                 (Position.MarketPosition == MarketPosition.Long)
  5074.                     && ((Close[0] >= breakevenActualTrigger) || (breakevenButtonClicked))
  5075.                         && (myFreeBEActual == true)
  5076.                 )
  5077.             {
  5078.                 #region Filled Long Position   
  5079.            
  5080.                 if (Position.MarketPosition == MarketPosition.Long && myFreeBEActual == true && Position.Quantity == positionSizeLong)
  5081.                 {
  5082.                     if (dualTarget == false)
  5083.                     {
  5084.                         ExitLongStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopLong", "MyEntryLong");
  5085.                     }
  5086.                
  5087.                 if (dualTarget)
  5088.                 {
  5089.                         ExitLongStopMarket(0, true, firstTargetPositionLong, breakevenActualStopSet, "MyStopLong", "MyEntryLong");
  5090.                         ExitLongStopMarket(0, true, secondTargetPositionLong, breakevenActualStopSet, "MyStopLong2", "MyEntryLong2");  
  5091.                 }
  5092.                
  5093.                 breakevenButtonClicked = false;
  5094.                 myFreeBEActual = false;
  5095.             }
  5096.                
  5097.             #endregion
  5098.                
  5099.                 #region Partial Fill Long Position
  5100.                
  5101.             if (Position.MarketPosition == MarketPosition.Long && myFreeBEActual == true && Position.Quantity < positionSizeLong)// && IsFirstTickOfBar)
  5102.             {
  5103.                 if (dualTarget == false)
  5104.                     {
  5105.                         ExitLongStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopLong", "MyEntryLong");
  5106.                     }
  5107.                    
  5108.                 if (dualTarget == true && myFillCheck == true)
  5109.                 {
  5110.                     ExitLongStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopLong", "MyEntryLong");
  5111.                     ExitLongStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopLong2", "MyEntryLong2");
  5112.                 }
  5113.                
  5114.                 breakevenButtonClicked = false;
  5115.                 myFreeBEActual = false;
  5116.             }
  5117.            
  5118.             #endregion
  5119.             }
  5120.            
  5121.                 #endregion
  5122.            
  5123.                 #region Short
  5124.            
  5125.             if (
  5126.                 (Position.MarketPosition == MarketPosition.Short)
  5127.                     && ((Close[0] <= breakevenActualTrigger) || (breakevenButtonClicked))
  5128.                         && (myFreeBEActual == true)
  5129.                 )
  5130.             {
  5131.                 #region Filled Short Position  
  5132.            
  5133.                 if (Position.MarketPosition == MarketPosition.Short && myFreeBEActual == true && Position.Quantity == positionSizeShort)
  5134.                 {
  5135.                     if (dualTarget == false)
  5136.                     {
  5137.                         ExitShortStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopShort", "MyEntryShort");
  5138.                     }
  5139.                
  5140.                     if (dualTarget)
  5141.                     {
  5142.                         ExitShortStopMarket(0, true, firstTargetPositionShort, breakevenActualStopSet, "MyStopShort", "MyEntryShort");
  5143.                         ExitShortStopMarket(0, true, secondTargetPositionShort, breakevenActualStopSet, "MyStopShort2", "MyEntryShort2");  
  5144.                     }
  5145.                
  5146.                 breakevenButtonClicked = false;
  5147.                 myFreeBEActual = false;
  5148.             }
  5149.                
  5150.             #endregion
  5151.                
  5152.                 #region Partial Fill Short Position
  5153.                
  5154.             if (Position.MarketPosition == MarketPosition.Short && myFreeBEActual == true && Position.Quantity < positionSizeShort) //&& IsFirstTickOfBar)
  5155.             {
  5156.                 if (dualTarget == false)
  5157.                     {
  5158.                         ExitShortStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopShort", "MyEntryShort");
  5159.                     }
  5160.                
  5161.                 if (dualTarget == true && myFillCheck == true)
  5162.                 {
  5163.                     ExitShortStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopShort", "MyEntryShort");
  5164.                     ExitShortStopMarket(0, true, Position.Quantity, breakevenActualStopSet, "MyStopShort2", "MyEntryShort2");
  5165.                    
  5166.                     Print("At Breakeven: " + Position.Quantity);
  5167.                 }
  5168.                
  5169.                 breakevenButtonClicked = false;
  5170.                 myFreeBEActual = false;
  5171.             }
  5172.            
  5173.             #endregion
  5174.             }
  5175.            
  5176.                 #endregion
  5177.                
  5178.             #endregion
  5179.            
  5180.             #region Custom Stop Move
  5181.             ///Will add this at a later date
  5182.             #endregion
  5183.            
  5184.             #region Trail Stop
  5185.            
  5186.             if (
  5187.                 (myFreeCandleTrail == true && activeTrail)
  5188.                    
  5189.                 && ((Position.MarketPosition == MarketPosition.Long && (Close[0] >= candleTrailTrigger || trailButtonClicked))
  5190.                    
  5191.                     || (Position.MarketPosition == MarketPosition.Short && (Close[0] <= candleTrailTrigger || trailButtonClicked)))
  5192.                 )
  5193.            
  5194.                 {
  5195.                
  5196.                     #region Trail Offset
  5197.            
  5198.                     //Define the area where stop will be set           
  5199.                     trailAreaLong       = Low[1];
  5200.                     trailAreaShort      = High[1];
  5201.                    
  5202.                     //Adds offset to your trail stop area. Gives user customization.       
  5203.                     percentageCalcTrail         = ((High[2] - Low[2]) * PercentageOffsetTrail);
  5204.                     priceCalcTrail          = PriceOffsetTrail;
  5205.                     tickCalcTrail           = TickOffsetTrail * TickSize;
  5206.                    
  5207.                     //Picks the highest of the 3 numbers           
  5208.                     candleBarOffsetTrail = Math.Max(percentageCalcTrail, Math.Max(priceCalcTrail, tickCalcTrail));
  5209.                    
  5210.                     //Add both of them together to define final entry point        
  5211.                     candleTrailStopSetLong = trailAreaLong - candleBarOffsetTrail;
  5212.                     candleTrailStopSetShort = trailAreaShort + candleBarOffsetTrail;
  5213.                    
  5214.                     #region Prints
  5215.                    
  5216.                     if (SystemPrint)
  5217.                     {
  5218.                         if (TrailPrints)
  5219.                         {
  5220.                             Print("Current Trail Price Offset is :  " + priceCalcTrail + " " + Time[1]);
  5221.                             Print("Current Trail Percent Offset is :  " + percentageCalcTrail + " " + Time[1]);
  5222.                             Print("Current Trail Tick Offset is :  " + tickCalcTrail + " " + Time[1]);
  5223.                            
  5224.                             Print("Current Trail Highest Offset Selected is :  " + candleBarOffsetTrail + " " + Time[1]);
  5225.                            
  5226.                             Print("candleTrailStopSetLong is :  " + candleTrailStopSetLong + " " + Time[1]);   
  5227.                             Print("candleTrailStopSetShort is :  " + candleTrailStopSetShort + " " + Time[1]); 
  5228.                        
  5229.                             Print("myFree Trail Offset " + myFreeCandleTrail + " " + Time[1]);
  5230.                         }
  5231.                        
  5232.                     }
  5233.                     #endregion
  5234.            
  5235.            
  5236.                     #endregion  
  5237.                    
  5238.                     trailTriggeredCandle = true; //Allows condition to move stop freely.
  5239.                     myFreeCandleTrail = false; //Sets bool back to false. Needs to wait another candle for calculations to happen again
  5240.                 }  
  5241.        
  5242.                 #region Long Trail
  5243.                
  5244.                 #region Filled Long Position   
  5245.            
  5246.                 if (Position.MarketPosition == MarketPosition.Long && trailTriggeredCandle == true && Position.Quantity == positionSizeLong && (Low[1] > Low[2]) && Open[0] > Low[1])
  5247.                 {
  5248.                     Print("Open[0] " + Open[0]);
  5249.                     Print("High[1]" + High[1]);
  5250.                     if (dualTarget == false)
  5251.                     {
  5252.                         ExitLongStopMarket(0, true, Position.Quantity, candleTrailStopSetLong , "MyStopLong", "MyEntryLong");
  5253.                     }
  5254.                
  5255.                     if (dualTarget)
  5256.                     {
  5257.                         ExitLongStopMarket(0, true, firstTargetPositionLong, candleTrailStopSetLong, "MyStopLong", "MyEntryLong");
  5258.                         ExitLongStopMarket(0, true, secondTargetPositionLong, candleTrailStopSetLong, "MyStopLong2", "MyEntryLong2");  
  5259.                     }
  5260.                
  5261.                 //trailButtonClicked        = false;
  5262.                 trailTriggeredCandle    = false;
  5263.             }
  5264.                
  5265.             #endregion
  5266.                
  5267.                 #region Partial Fill Long Position
  5268.                
  5269.             if (Position.MarketPosition == MarketPosition.Long && trailTriggeredCandle == true && Position.Quantity < positionSizeLong && (Low[1] > Low[2]) && Open[0] > Low[1])
  5270.             {
  5271.                 if (dualTarget == false)
  5272.                 {
  5273.                     ExitLongStopMarket(0, true, Position.Quantity, candleTrailStopSetLong, "MyStopLong", "MyEntryLong");
  5274.                 }
  5275.                
  5276.                 if (dualTarget == true && myFillCheck == true)
  5277.                 {
  5278.                     ExitLongStopMarket(0, true, Position.Quantity, candleTrailStopSetLong, "MyStopLong", "MyEntryLong");
  5279.                     ExitLongStopMarket(0, true, Position.Quantity, candleTrailStopSetLong, "MyStopLong2", "MyEntryLong2");
  5280.                 }
  5281.                
  5282.                 trailTriggeredCandle    = false;
  5283.             }
  5284.            
  5285.             #endregion
  5286.            
  5287.                 #endregion
  5288.            
  5289.                 #region Short Trail
  5290.                
  5291.                 #region Filled Short Position  
  5292.            
  5293.                 if (Position.MarketPosition == MarketPosition.Short && trailTriggeredCandle == true && Position.Quantity == positionSizeShort && (High[1] < High[2]) && Open[0] < High[1])
  5294.                 {
  5295.                     if (dualTarget == false)
  5296.                     {
  5297.                         ExitShortStopMarket(0, true, Position.Quantity, candleTrailStopSetShort , "MyStopShort", "MyEntryShort");
  5298.                     }
  5299.                
  5300.                 if (dualTarget)
  5301.                 {
  5302.                         ExitShortStopMarket(0, true, firstTargetPositionShort, candleTrailStopSetShort, "MyStopShort", "MyEntryShort");
  5303.                         ExitShortStopMarket(0, true, secondTargetPositionShort, candleTrailStopSetShort, "MyStopShort2", "MyEntryShort2"); 
  5304.                 }
  5305.                
  5306.                 //trailButtonClicked        = false;
  5307.                 trailTriggeredCandle    = false;
  5308.             }
  5309.                
  5310.             #endregion
  5311.                
  5312.                 #region Partial Fill Short Position
  5313.                
  5314.             if (Position.MarketPosition == MarketPosition.Short && trailTriggeredCandle == true && Position.Quantity < positionSizeShort && (High[1] < High[2]) && Open[0] < High[1])
  5315.             {
  5316.                 if (dualTarget == false)
  5317.                 {
  5318.                     ExitShortStopMarket(0, true, Position.Quantity, candleTrailStopSetShort, "MyStopShort", "MyEntryShort");
  5319.                 }
  5320.                    
  5321.                 if (dualTarget == true && myFillCheck == true)
  5322.                 {
  5323.                     ExitShortStopMarket(0, true, Position.Quantity, candleTrailStopSetShort, "MyStopShort", "MyEntryShort");
  5324.                     ExitShortStopMarket(0, true, Position.Quantity, candleTrailStopSetShort, "MyStopShort2", "MyEntryShort2");
  5325.                 }
  5326.                
  5327.                 trailTriggeredCandle    = false;
  5328.  
  5329.             }
  5330.            
  5331.             #endregion
  5332.            
  5333.                 #endregion
  5334.                
  5335.             #endregion
  5336.            
  5337.         }
  5338.        
  5339.    
  5340.         protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
  5341.         {
  5342.             //myPosition = Position.Quantity;
  5343.            
  5344.             if (Position.MarketPosition == MarketPosition.Flat)
  5345.             {
  5346.                 countOnce       = true;
  5347.                 activateMarket  = false;
  5348.                 myFillCheck     = false;
  5349.             }
  5350.            
  5351.             if (Position.MarketPosition != MarketPosition.Flat)
  5352.             {
  5353.                 RemoveDrawObject("EntryLine");
  5354.                 RemoveDrawObject("StopLine");
  5355.             }
  5356.            
  5357.             #region Trail Stop Cancel
  5358.            
  5359.             if (Position.MarketPosition == MarketPosition.Flat)
  5360.             {
  5361.                 myFreeCandleTrail = false;
  5362.                
  5363.                 if (SystemPrint)
  5364.                 {
  5365.                     if (TrailPrints)
  5366.                     {
  5367.                         Print("myFree Trail ON Position " + myFreeCandleTrail + " " + Time[1]);
  5368.                     }
  5369.                 }
  5370.                
  5371.             }
  5372.            
  5373.             #endregion
  5374.            
  5375.             #region Fib Levels Updates
  5376.            
  5377.             if (Position.MarketPosition == MarketPosition.Flat)
  5378.             {
  5379.                 fibCount    = 1;
  5380.                 isFib       = false;;
  5381.                
  5382.                 RemoveDrawObject("FibLong");
  5383.                 RemoveDrawObject("FibShort");
  5384.             }
  5385.            
  5386.             if (fibButtonClicked && Position.MarketPosition == MarketPosition.Long)
  5387.             {
  5388.                 if (rrMode)
  5389.                 {
  5390.                     Draw.FibonacciRetracements(this, "FibLong", false, fibCount, setStopLong, fibCount, enterLong);
  5391.                 }
  5392.                
  5393.                 if (tickMode)
  5394.                 {
  5395.                     Draw.FibonacciRetracements(this, "FibLong", false, fibCount, Position.AveragePrice - candleBarOffsetStop, fibCount, Position.AveragePrice);
  5396.                 }
  5397.                
  5398.             }
  5399.            
  5400.             if (fibButtonClicked && Position.MarketPosition == MarketPosition.Short)
  5401.             {
  5402.                 if (rrMode)
  5403.                 {
  5404.                     Draw.FibonacciRetracements(this, "FibShort", false, fibCount, setStopShort, fibCount, enterShort);
  5405.                 }
  5406.                
  5407.                 if (tickMode)
  5408.                 {
  5409.                     Draw.FibonacciRetracements(this, "FibShort", false, fibCount, Position.AveragePrice + candleBarOffsetStop, fibCount, Position.AveragePrice);
  5410.                 }
  5411.             }
  5412.            
  5413.             #endregion
  5414.            
  5415.            
  5416.         }
  5417.        
  5418.            
  5419.         protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
  5420.         {
  5421.             #region Button Event Updates
  5422.            
  5423.             //Buy High
  5424.             if (Position.MarketPosition != MarketPosition.Flat)
  5425.                 {
  5426.                     ChartControl.Dispatcher.InvokeAsync(new Action(() =>
  5427.              {
  5428.                 longButtonHL.Content = "BUY HIGH";
  5429.                 longButtonHLClicked = false;
  5430.             }));
  5431.                    
  5432.                 }
  5433.            
  5434.             //Sell Low
  5435.             if (Position.MarketPosition != MarketPosition.Flat)
  5436.                 {
  5437.                     ChartControl.Dispatcher.InvokeAsync(new Action(() =>
  5438.              {
  5439.                 shortButtonHL.Content = "SELL LOW";
  5440.                 shortButtonHLClicked = false;
  5441.             }));
  5442.                    
  5443.                 }
  5444.                
  5445.             //Custom Long  
  5446.             if (Position.MarketPosition != MarketPosition.Flat)
  5447.                 {
  5448.                     ChartControl.Dispatcher.InvokeAsync(new Action(() =>
  5449.              {
  5450.                 customLong.Content = "Custom Long";
  5451.                 customLong.Background   = Brushes.MediumSeaGreen;
  5452.                 armMarketCount = 0;
  5453.                 customLongClicked = false;
  5454.             }));
  5455.                    
  5456.                 }
  5457.                
  5458.             //Custom Short 
  5459.             if (Position.MarketPosition != MarketPosition.Flat)
  5460.                 {
  5461.                     ChartControl.Dispatcher.InvokeAsync(new Action(() =>
  5462.              {
  5463.                 customShort.Content = "Custom Short";
  5464.                 customShort.Background  = Brushes.IndianRed;
  5465.                 armMarketCount = 0;
  5466.                 customShortClicked = false;
  5467.             }));
  5468.        
  5469.                 }  
  5470.                
  5471.                
  5472.             if (Position.MarketPosition == MarketPosition.Flat)
  5473.                 {
  5474.                     ChartControl.Dispatcher.InvokeAsync(new Action(() =>
  5475.              {
  5476.                 trailButton.Content = "Trail Stop";
  5477.                 trailButton.Background  = Brushes.LightGray;
  5478.                 trailButtonClicked = false;
  5479.             }));
  5480.        
  5481.                 }      
  5482.                
  5483.                 #endregion
  5484.         }
  5485.            
  5486.         protected void RemoveWPFControls()
  5487.         {
  5488.             #region Remove WPF
  5489.            
  5490.             if (!panelActive)
  5491.                 return;
  5492.            
  5493.             if (chartTraderButtonsGrid != null || lowerButtonsGrid != null)
  5494.             {
  5495.                 chartTraderGrid.Children.Remove(lowerButtonsGrid);
  5496.                 chartTraderGrid.RowDefinitions.Remove(addedRow);
  5497.             }
  5498.  
  5499.             panelActive = false;
  5500.            
  5501.             #endregion
  5502.         }
  5503.        
  5504.         private bool TabSelected()
  5505.         {
  5506.             #region TabSelcected
  5507.            
  5508.             bool tabSelected = false;
  5509.  
  5510.             // loop through each tab and see if the tab this indicator is added to is the selected item
  5511.             foreach (System.Windows.Controls.TabItem tab in chartWindow.MainTabControl.Items)
  5512.                 if ((tab.Content as Gui.Chart.ChartTab).ChartControl == ChartControl && tab == chartWindow.MainTabControl.SelectedItem)
  5513.                     tabSelected = true;
  5514.  
  5515.             return tabSelected;
  5516.                
  5517.             #endregion
  5518.         }
  5519.        
  5520.         private void TabChangedHandler(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  5521.         {
  5522.             #region TabHandler
  5523.            
  5524.             if (e.AddedItems.Count <= 0)
  5525.                 return;
  5526.  
  5527.             tabItem = e.AddedItems[0] as System.Windows.Controls.TabItem;
  5528.             if (tabItem == null)
  5529.                 return;
  5530.  
  5531.             chartTab = tabItem.Content as Gui.Chart.ChartTab;
  5532.             if (chartTab == null)
  5533.                 return;
  5534.  
  5535.             if (TabSelected())
  5536.                 InsertWPFControls();
  5537.             else
  5538.                 RemoveWPFControls();
  5539.            
  5540.             #endregion
  5541.         }
  5542.        
  5543.        
  5544.         #region Button Click Events
  5545.        
  5546.         private void OnButtonClick(object sender, RoutedEventArgs rea)
  5547.         {
  5548.             System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
  5549.            
  5550.             #region TradeSaber Socials
  5551.            
  5552.             if (showSocials)
  5553.             {
  5554.                 if (button == youtubeButton && button.Name == "YoutubeButton" && button.Content == "Youtube")
  5555.                 {
  5556.                     System.Diagnostics.Process.Start(youtube);
  5557.                     return;
  5558.                 }
  5559.                
  5560.                 if (button == discordButton && button.Name == "DiscordButton" && button.Content == "Discord")
  5561.                 {  
  5562.                     System.Diagnostics.Process.Start(discord);
  5563.                     return;
  5564.                 }
  5565.                
  5566.                 if (button == tradeSaberButton && button.Name == "TradeSaberButton" && button.Content == "TradeSaber")
  5567.                 {  
  5568.                     System.Diagnostics.Process.Start(tradeSaber);
  5569.                     return;
  5570.                 }
  5571.             }
  5572.            
  5573.             #endregion
  5574.         }
  5575.        
  5576.         #endregion
  5577.        
  5578.        
  5579.         #region Properties
  5580.            
  5581.         #region 01. Position Size
  5582.        
  5583.         [Display(Name = "Order Management Method", GroupName = "01. Position Size", Description="", Order = 0)]
  5584.         public OrderManagement  ManagementType
  5585.         {
  5586.             get { return managementType; }
  5587.             set { managementType = value; }
  5588.         }  
  5589.        
  5590.        
  5591.        
  5592.         [RefreshProperties(RefreshProperties.All)]
  5593.         [NinjaScriptProperty]
  5594.         [Display(Name = "Auto Position Size", Order = 1, GroupName = "01. Position Size")]
  5595.         public bool AutoPositionSize
  5596.         {
  5597.             get
  5598.            {
  5599.               return autoPositionSize;
  5600.            }
  5601.            set
  5602.            {
  5603.               if (value == true)
  5604.               {
  5605.                  CustomPositionSize = false;
  5606.               }
  5607.               autoPositionSize = value;
  5608.             }
  5609.         }
  5610.  
  5611.         [NinjaScriptProperty]
  5612.         [Range(1, double.MaxValue)]
  5613.         [Display(Name="Risk Size($)", Order=2, GroupName="01. Position Size")]
  5614.         public double MaxLossPerTrade
  5615.         { get; set; }
  5616.        
  5617.         [RefreshProperties(RefreshProperties.All)]
  5618.         [NinjaScriptProperty]
  5619.         [Display(Name = "Custom Position Size", Order = 3, GroupName = "01. Position Size")]
  5620.         public bool CustomPositionSize
  5621.         {
  5622.            get
  5623.            {
  5624.               return customPositionSize;
  5625.            }
  5626.            set
  5627.            {
  5628.               if (value == true)
  5629.               {
  5630.                  AutoPositionSize = false;
  5631.               }
  5632.               customPositionSize = value;
  5633.            }
  5634.         }
  5635.        
  5636.         [Range(1, int.MaxValue)]
  5637.         [NinjaScriptProperty]
  5638.         [Display(Name="Custom Position Amount", Order=4, GroupName="01. Position Size")]
  5639.         public int CustomPositionAmount
  5640.         { get; set; }
  5641.        
  5642.        
  5643.         [NinjaScriptProperty]
  5644.         [Display(Name="Use Candle Range", Order=5, GroupName="01. Position Size")]
  5645.         public bool CandleRange
  5646.         { get; set; }
  5647.        
  5648.         #endregion
  5649.    
  5650.         #region 02. Entry / Limit
  5651.        
  5652.         [NinjaScriptProperty]
  5653.         [Range(1, int.MaxValue)]
  5654.         [Display(Name="Entry Candle Used", Order=0, GroupName="02. Entry")]
  5655.         public int CandleLookBackEntry
  5656.         { get; set; }
  5657.        
  5658.         [NinjaScriptProperty]
  5659.         [Display(Name="Price Offset Entry", Order=1, GroupName="02. Entry")]
  5660.         public double PriceOffsetEntry
  5661.         { get; set; }
  5662.  
  5663.         [NinjaScriptProperty]
  5664.         [Display(Name="Percentage Offset Entry", Order=2, GroupName="02. Entry")]
  5665.         public double PercentageOffsetEntry
  5666.         { get; set; }
  5667.  
  5668.         [NinjaScriptProperty]
  5669.         [Display(Name="Tick Offset Entry", Order=3, GroupName="02. Entry")]
  5670.         public int TickOffsetEntry
  5671.         { get; set; }
  5672.  
  5673.        
  5674.         //Limit Orders
  5675.         [NinjaScriptProperty]
  5676.         [Display(Name="Limit Order Entry", Order=4, GroupName="02A. Limit Order")]
  5677.         public bool useLimit
  5678.         { get; set; }
  5679.        
  5680.         [NinjaScriptProperty]
  5681.         [Display(Name="Price Offset Limit", Order=5, GroupName="02A. Limit Order")]
  5682.         public double PriceOffsetLimit
  5683.         { get; set; }
  5684.  
  5685.         [NinjaScriptProperty]
  5686.         [Display(Name="Percentage Offset Limit", Order=6, GroupName="02A. Limit Order")]
  5687.         public double PercentageOffsetLimit
  5688.         { get; set; }
  5689.  
  5690.         [NinjaScriptProperty]
  5691.         [Display(Name="Tick Offset Limit", Order=7, GroupName="02A. Limit Order")]
  5692.         public int TickOffsetLimit
  5693.         { get; set; }
  5694.        
  5695.         #endregion
  5696.    
  5697.         #region 03. Stop
  5698.        
  5699.         [NinjaScriptProperty]
  5700.         [Display(Name="Set Stop Loss", Order=0, GroupName="03. Stop")]
  5701.         public bool stopLoss
  5702.         { get; set; }
  5703.        
  5704.         [NinjaScriptProperty]
  5705.         [Range(1, int.MaxValue)]
  5706.         [Display(Name="Stop Candle Used", Order=1, GroupName="03. Stop")]
  5707.         public int CandleLookBackStop
  5708.         { get; set; }
  5709.        
  5710.         [NinjaScriptProperty]
  5711.         [Display(Name="Price Offset Stop", Order=2, GroupName="03. Stop")]
  5712.         public double PriceOffsetStop
  5713.         { get; set; }
  5714.  
  5715.         [NinjaScriptProperty]
  5716.         [Display(Name="Percentage Offset Stop", Order=3, GroupName="03. Stop")]
  5717.         public double PercentageOffsetStop
  5718.         { get; set; }
  5719.  
  5720.         [NinjaScriptProperty]
  5721.         [Display(Name="Tick Offset Stop", Order=4, GroupName="03. Stop")]
  5722.         public int TickOffsetStop
  5723.         { get; set; }
  5724.  
  5725.         #endregion
  5726.    
  5727.         #region 04. Profit Targets
  5728.        
  5729.         [NinjaScriptProperty]
  5730.         [Display(Name="Set Profit Target", Order=0, GroupName="04. Target")]
  5731.         public bool profitTarget
  5732.         { get; set; }
  5733.  
  5734.         [NinjaScriptProperty]
  5735.         [Display(Name="Final Target", Order=2, GroupName="04. Target")]
  5736.         public double FinalTargetRR
  5737.         { get; set; }
  5738.        
  5739.         #endregion
  5740.        
  5741.         #region 04A. Dual Target
  5742.        
  5743.         [NinjaScriptProperty]
  5744.         [Display(Name="DualTarget", Order=1, GroupName="04A. Dual Target")]
  5745.         public bool dualTarget
  5746.         { get; set; }
  5747.        
  5748.         [NinjaScriptProperty]
  5749.         [Display(Name="Dual Entry Split Percent", Order=2, GroupName="04A. Dual Target")]
  5750.         public double splitPercent
  5751.         { get; set; }
  5752.        
  5753.         [NinjaScriptProperty]
  5754.         [Display(Name="First Target", Order=3, GroupName="04A. Dual Target")]
  5755.         public double FirstTargetRR
  5756.         { get; set; }
  5757.        
  5758.         #endregion
  5759.        
  5760.         #region 05. Custom Button
  5761.        
  5762.         [RefreshProperties(RefreshProperties.All)]
  5763.         [NinjaScriptProperty]
  5764.         [Display(Name = "'Close' Price", Order = 2, GroupName = "05. Custom Button")]
  5765.         public bool EnterClosePrice
  5766.         {
  5767.             get
  5768.            {
  5769.               return enterClosePrice;
  5770.            }
  5771.            set
  5772.            {
  5773.               if (value == true)
  5774.               {
  5775.                  ArmMarket = false;
  5776.               }
  5777.               enterClosePrice = value;
  5778.             }
  5779.         }
  5780.  
  5781.        
  5782.        
  5783.         [RefreshProperties(RefreshProperties.All)]
  5784.         [NinjaScriptProperty]
  5785.         [Display(Name = "Arm Market (New Candle)", Order = 3, GroupName = "05. Custom Button")]
  5786.         public bool ArmMarket
  5787.         {
  5788.            get
  5789.            {
  5790.               return armMarket;
  5791.            }
  5792.            set
  5793.            {
  5794.               if (value == true)
  5795.               {
  5796.                  EnterClosePrice = false;
  5797.               }
  5798.               armMarket = value;
  5799.            }
  5800.         }
  5801.        
  5802.         ///
  5803.        
  5804.         /*
  5805.         [NinjaScriptProperty]
  5806.         [Display(Name="Add Offset", Order=3, GroupName="01. Risk Parameters")]
  5807.         public bool AddOffset
  5808.         { get; set; }
  5809.         */
  5810.         #endregion
  5811.        
  5812.         #region 06. Breakeven Offset
  5813.        
  5814.         //Breakeven Offset
  5815.         [NinjaScriptProperty]
  5816.         [Display(Name="Price Offset Breakeven", Order=1, GroupName="06. Breakeven Offset")]
  5817.         public double PriceOffsetBreakeven
  5818.         { get; set; }
  5819.  
  5820.         [NinjaScriptProperty]
  5821.         [Display(Name="Percentage Offset Breakeven", Order=2, GroupName="06. Breakeven Offset")]
  5822.         public double PercentageOffsetBreakeven
  5823.         { get; set; }
  5824.  
  5825.         [NinjaScriptProperty]
  5826.         [Display(Name="Tick Offset Breakeven", Order=3, GroupName="06. Breakeven Offset")]
  5827.         public int TickOffsetBreakeven
  5828.         { get; set; }
  5829.        
  5830.         #endregion
  5831.        
  5832.         #region 06A. Breakeven Area
  5833.        
  5834.         //Breakeven Area
  5835.         [RefreshProperties(RefreshProperties.All)]
  5836.         [NinjaScriptProperty]
  5837.         [Display(Name="Breakeven (Area) Button", Order=4, GroupName="06A. Breakeven Area")]
  5838.         public bool BreakevenAreaSetButton
  5839.         {
  5840.             get
  5841.            {
  5842.               return breakevenAreaSetButton;
  5843.            }
  5844.            set
  5845.            {
  5846.               if (value == true)
  5847.               {
  5848.                  BreakevenActualSetButton = false;
  5849.               }
  5850.               breakevenAreaSetButton = value;
  5851.             }
  5852.         }
  5853.        
  5854.        
  5855.         [RefreshProperties(RefreshProperties.All)]
  5856.         [NinjaScriptProperty]
  5857.         [Display(Name="Breakeven (Area) Set Auto", Order=5, GroupName="06A. Breakeven Area")]
  5858.         public bool BreakevenAreaSetAuto
  5859.         {
  5860.             get
  5861.            {
  5862.               return breakevenAreaSetAuto;
  5863.            }
  5864.            set
  5865.            {
  5866.               if (value == true)
  5867.               {
  5868.                  BreakevenActualSetAuto = false;
  5869.               }
  5870.               breakevenAreaSetAuto = value;
  5871.             }
  5872.         }
  5873.        
  5874.         [NinjaScriptProperty]
  5875.         [Display(Name="Breakeven (Area) Target", Order=6, GroupName="06A. Breakeven Area")]
  5876.         public double breakevenAreaTarget  
  5877.         { get; set; }
  5878.        
  5879.         #endregion
  5880.        
  5881.         #region 06B. Breakeven Actual
  5882.        
  5883.         //Breakeven Actual
  5884.         [RefreshProperties(RefreshProperties.All)]
  5885.         [NinjaScriptProperty]
  5886.         [Display(Name=" Breakeven (Actual) Button", Order=7, GroupName="06B. Breakeven Actual")]   
  5887.         public bool BreakevenActualSetButton
  5888.         {
  5889.            get
  5890.            {
  5891.               return  breakevenActualSetButton;
  5892.            }
  5893.            set
  5894.            {
  5895.               if (value == true)
  5896.               {
  5897.                  BreakevenAreaSetButton = false;
  5898.               }
  5899.                breakevenActualSetButton = value;
  5900.            }
  5901.         }
  5902.        
  5903.        
  5904.        
  5905.         [RefreshProperties(RefreshProperties.All)]
  5906.         [NinjaScriptProperty]
  5907.         [Display(Name="Breakeven (Actual) Set Auto", Order=8, GroupName="06B. Breakeven Actual")]  
  5908.         public bool BreakevenActualSetAuto
  5909.         {
  5910.            get
  5911.            {
  5912.               return breakevenActualSetAuto;
  5913.            }
  5914.            set
  5915.            {
  5916.               if (value == true)
  5917.               {
  5918.                  BreakevenAreaSetAuto = false;
  5919.               }
  5920.               breakevenActualSetAuto = value;
  5921.            }
  5922.         }
  5923.        
  5924.        
  5925.         [NinjaScriptProperty]
  5926.         [Display(Name="Breakeven (Actual) Target", Order=9, GroupName="06B. Breakeven Actual")]
  5927.         public double breakevenActualTarget
  5928.         { get; set; }
  5929.        
  5930.         #endregion
  5931.        
  5932.         #region 07. Trail Stop Offset
  5933.  
  5934.         //Trail Offset
  5935.         [NinjaScriptProperty]
  5936.         [Display(Name="Price Offset Trail", Order=1, GroupName="07. Trail Stop Offset")]
  5937.         public double PriceOffsetTrail
  5938.         { get; set; }
  5939.  
  5940.         [NinjaScriptProperty]
  5941.         [Display(Name="Percentage Offset Trail", Order=2, GroupName="07. Trail Stop Offset")]
  5942.         public double PercentageOffsetTrail
  5943.         { get; set; }
  5944.  
  5945.         [NinjaScriptProperty]
  5946.         [Display(Name="Tick Offset Trail", Order=3, GroupName="07. Trail Stop Offset")]
  5947.         public int TickOffsetTrail
  5948.         { get; set; }
  5949.        
  5950.         #endregion
  5951.        
  5952.         #region 07A. Candle Trail
  5953.        
  5954.         [RefreshProperties(RefreshProperties.All)]
  5955.         [NinjaScriptProperty]
  5956.         [Display(Name = "Candle Trail (Button)", Order = 1, GroupName = "07A. Trail Stop")]
  5957.         public bool candleTrailSetButton
  5958.         { get; set; }
  5959.        
  5960.         [RefreshProperties(RefreshProperties.All)]
  5961.         [NinjaScriptProperty]
  5962.         [Display(Name = "Candle Trail (Auto)", Order = 2, GroupName = "07A. Trail Stop")]
  5963.         public bool candleTrailSetAuto
  5964.         { get; set; }
  5965.        
  5966.         [NinjaScriptProperty]
  5967.         [Display(Name="Candle Trail Target", Order=3, GroupName="07A. Trail Stop")]
  5968.         public double candleTrailTarget
  5969.         { get; set; }
  5970.        
  5971.         #endregion
  5972.  
  5973.         #region 9 Display Text Box
  5974.        
  5975.         [NinjaScriptProperty]
  5976.         [Display(Name="Display Text", Order=1, GroupName="9 Display Text Box")]
  5977.         public bool DisplayText
  5978.         { get; set; }
  5979.        
  5980.         #endregion
  5981.        
  5982.         #region For Later Use
  5983.         /*
  5984.         //custom Move Stop
  5985.         [NinjaScriptProperty]
  5986.         [Display(Name="customMoveStopSet", Order=15, GroupName="10. Management")]
  5987.         public bool customMoveStopSet
  5988.         { get; set; }
  5989.        
  5990.         [NinjaScriptProperty]
  5991.         [Display(Name="customeMoveStopTarget", Order=16, GroupName="10. Management")]
  5992.         public double customeMoveStopTarget
  5993.         { get; set; }
  5994.        
  5995.         //Custom Trail
  5996.         [NinjaScriptProperty]
  5997.         [Display(Name="customTrailSet", Order=7, GroupName="10. Trail Stop2")]
  5998.         public bool customTrailSet
  5999.         { get; set; }
  6000.        
  6001.         [NinjaScriptProperty]
  6002.         [Display(Name="customTrailTarget", Order=8, GroupName="10. Trail Stop2")]
  6003.         public double customTrailTarget
  6004.         { get; set; }
  6005.         */
  6006.         #endregion
  6007.        
  6008.         #region 29. TradeSaber Socials
  6009.        
  6010.         [NinjaScriptProperty]
  6011.         [Display(Name = "Show Social Media Buttons", Description = "", Order = 0, GroupName = "29. TradeSaber Socials")]
  6012.         public bool ShowSocials
  6013.         {
  6014.             get{return showSocials;}
  6015.             set{showSocials = (value);}
  6016.         }
  6017.        
  6018.         [NinjaScriptProperty]
  6019.         [Display(Name="Explanation Video", Order=1, GroupName="29. TradeSaber Socials")]
  6020.         public  string Youtube
  6021.         {
  6022.             get{return youtube;}
  6023.             set{youtube = (value);}
  6024.         }
  6025.        
  6026.         [NinjaScriptProperty]
  6027.         [Display(Name="Discord Link", Order=2, GroupName="29. TradeSaber Socials")]
  6028.         public  string Discord
  6029.         {
  6030.             get{return discord;}
  6031.             set{discord = (value);}
  6032.         }
  6033.        
  6034.         [NinjaScriptProperty]
  6035.         [Display(Name="TradeSaber Link", Order=3, GroupName="29. TradeSaber Socials")]
  6036.         public  string TradeSaber
  6037.         {
  6038.             get{return tradeSaber;}
  6039.             set{tradeSaber = (value);}
  6040.         }
  6041.        
  6042.         [NinjaScriptProperty]
  6043.         [ReadOnly(true)]
  6044.         [Display(Name = "Author", GroupName = "29. TradeSaber Socials", Order = 4)]
  6045.         public string Author
  6046.         {
  6047.             get{return author;}
  6048.             set{author = (value);}
  6049.         }
  6050.        
  6051.         [NinjaScriptProperty]
  6052.         [ReadOnly(true)]
  6053.         [Display(Name = "Version", GroupName = "29. TradeSaber Socials", Order = 5)]
  6054.         public string Version
  6055.         {
  6056.             get{return version;}
  6057.             set{version = (value);}
  6058.         }
  6059.        
  6060.         #endregion
  6061.        
  6062.         #region 99. Prints
  6063.        
  6064.         [NinjaScriptProperty]
  6065.         [Display(Name="SystemPrint", Order=1, GroupName="99. Prints")]
  6066.         public bool SystemPrint
  6067.         { get; set; }
  6068.        
  6069.         [NinjaScriptProperty]
  6070.         [Display(Name="EntryPrints", Order=3, GroupName="99. Prints")]
  6071.         public bool EntryPrints
  6072.         { get; set; }
  6073.        
  6074.         [NinjaScriptProperty]
  6075.         [Display(Name="LimitPrints", Order=4, GroupName="99. Prints")]
  6076.         public bool LimitPrints
  6077.         { get; set; }
  6078.        
  6079.         [NinjaScriptProperty]
  6080.         [Display(Name="StopPrints", Order=5, GroupName="99. Prints")]
  6081.         public bool StopPrints
  6082.         { get; set; }
  6083.        
  6084.         [NinjaScriptProperty]
  6085.         [Display(Name="PositionSizePrints", Order=5, GroupName="99. Prints")]
  6086.         public bool PositionSizePrints
  6087.         { get; set; }
  6088.        
  6089.         [NinjaScriptProperty]
  6090.         [Display(Name="ProfitTatgetPrintss", Order=6, GroupName="99. Prints")]
  6091.         public bool ProfitTatgetPrints
  6092.         { get; set; }
  6093.        
  6094.         [NinjaScriptProperty]
  6095.         [Display(Name="BreakevenPrints", Order=7, GroupName="99. Prints")]
  6096.         public bool BreakevenPrints
  6097.         { get; set; }
  6098.        
  6099.         [NinjaScriptProperty]
  6100.         [Display(Name="TrailPrints", Order=8, GroupName="99. Prints")]
  6101.         public bool TrailPrints
  6102.         { get; set; }
  6103.         //ProfitTatgetPrints
  6104.         #endregion
  6105.        
  6106.         #endregion
  6107.        
  6108.     }
  6109. }
  6110.  
  6111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement