コード例 #1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < Bars.Count - 1)
            {
                Value.Set(price);
                return;
            }

            IHorizontalLine alertLine  = null;
            IDrawObject     drawObject = DrawObjects["TriggerLine"];

            if (drawObject != null && drawObject.DrawType == DrawType.HorizontalLine)
            {
                alertLine = (drawObject as IHorizontalLine);
            }

            if (showTriggerLine && alertLine == null)
            {
                alertLine        = DrawHorizontalLine("TriggerLine", AutoScale, fixedPrice > 0 ? fixedPrice : Input[0], Plots[0].Pen.Color, Plots[0].Pen.DashStyle, (int)Plots[0].Pen.Width);
                alertLine.Locked = false;
                price            = Instrument.MasterInstrument.Round2TickSize(alertLine.Y);
            }

            double lineVal = showTriggerLine ? Instrument.MasterInstrument.Round2TickSize(alertLine.Y) : price;

            if (showTriggerLine && lineVal != price)
            {
                price      = lineVal;
                triggered  = false;
                triggerSet = false;
            }

            if (alertLine != null)
            {
                Plots[0].Pen.Color     = alertLine.Pen.Color;
                Plots[0].Pen.Width     = alertLine.Pen.Width;
                Plots[0].Pen.DashStyle = alertLine.Pen.DashStyle;
                alertLine.Y            = lineVal;
            }
            Value.Set(lineVal);

            if (Historical || triggered)
            {
                return;
            }

            if (!triggerSet)
            {
                triggerOnGreaterThan = Input[0] >= price - (TickSize * 0.5) ? false : true;
                triggerSet           = true;
            }

            if ((triggerOnGreaterThan && Input[0] >= price - (TickSize * 0.5)) || (!triggerOnGreaterThan && Input[0] <= price + (TickSize * 0.5)))
            {
                triggered = true;
                Alert(DateTime.Now.Millisecond.ToString(), Cbi.Priority.Medium, "Price level '" + price + "' hit!", Cbi.Core.InstallDir + @"\sounds\Alert4.wav", 0, Color.Yellow, Color.Black);
            }
        }
コード例 #2
0
        private void rewardRiskButtonClick(object s, EventArgs e)
        {
            if (toolStripButton.Checked)
            {
                // Change the button text to Bold Green color.
                toolStripButton.Font      = btnBoldFont;
                toolStripButton.ForeColor = Color.Green;

                if (ChartControl != null)
                {
                    stopPrice   = High[LowestBar(Low, ChartControl.BarsPainted)];
                    targetPrice = Low[HighestBar(High, ChartControl.BarsPainted)];
                    entryPrice  = stopPrice + ((targetPrice - stopPrice) / 2);

                    DrawHorizontalLine("Target", true, targetPrice, Color.Green, DashStyle.Solid, 3);
                    DrawHorizontalLine("Entry", true, entryPrice, Color.Sienna, DashStyle.Solid, 3);
                    DrawHorizontalLine("Stop", true, stopPrice, Color.Red, DashStyle.Solid, 3);

                    ChartControl.Refresh();
                } // if (ChartControl != null)

                rewardRiskMgtEnabled = true;
            }
            else
            {
                // Revert button text to its default.
                toolStripButton.Font      = btnDefFont;
                toolStripButton.ForeColor = Color.Black;

                if (ChartControl != null)
                {
                    RemoveDrawObject("Target");
                    RemoveDrawObject("Entry");
                    RemoveDrawObject("Stop");

                    entry  = null;
                    target = null;
                    stop   = null;

                    ChartControl.Refresh();
                } // if (ChartControl != null)

                rewardRiskMgtEnabled = false;
            }
        }
コード例 #3
0
ファイル: RiskReward.cs プロジェクト: yuxi214/ninja-code
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            base.Plot(graphics, bounds, min, max);
            int          y      = 0;
            StringFormat format = new StringFormat();

            format.Alignment = StringAlignment.Far;

            foreach (IDrawObject draw in DrawObjects)
            {
                if (draw.UserDrawn && draw.DrawType == DrawType.HorizontalLine)
                {
                    if (draw.Tag.ToUpper().Contains("TARGET"))
                    {
                        target      = (IHorizontalLine)draw;
                        targetPrice = Instrument.MasterInstrument.Round2TickSize(target.Y);
                        y           = ChartControl.GetYByValue(Bars, targetPrice);
                        risk        = Math.Abs(entryPrice - stopPrice);
                        reward      = Math.Abs(targetPrice - entryPrice);
                        riskReward  = (risk > 0) ? reward / risk : 0;
                        graphics.DrawString("T: " + targetPrice.ToString("0.0000") + "\nR/R  " + riskReward.ToString("0.##") + ":1", boldFont, target.Pen.Brush, bounds.Width, y, format);
                    }
                    else
                    if (draw.Tag.ToUpper().CompareTo("ENTRY") == 0)
                    {
                        entry      = (IHorizontalLine)draw;
                        entryPrice = Instrument.MasterInstrument.Round2TickSize(entry.Y);
                        y          = ChartControl.GetYByValue(Bars, entryPrice);
                        graphics.DrawString("E: " + entryPrice.ToString("0.0000"), boldFont, entry.Pen.Brush, bounds.Width, y, format);
                    }
                    else
                    if (draw.Tag.ToUpper().CompareTo("STOP") == 0)
                    {
                        stop      = (IHorizontalLine)draw;
                        stopPrice = Instrument.MasterInstrument.Round2TickSize(stop.Y);
                        y         = ChartControl.GetYByValue(Bars, stopPrice);
                        graphics.DrawString("S: " + stopPrice.ToString("0.0000"), boldFont, stop.Pen.Brush, bounds.Width, y, format);
                    }
                }
            }
        }
コード例 #4
0
        private void rewardRiskButtonClick(object s, EventArgs e)
        {
            if ( toolStripButton.Checked )
            {
                // Change the button text to Bold Green color.
                toolStripButton.Font = btnBoldFont;
                toolStripButton.ForeColor = Color.Green;

                if ( ChartControl != null )
                {
                    stopPrice = High[LowestBar(Low, ChartControl.BarsPainted)];
                    targetPrice = Low[HighestBar(High, ChartControl.BarsPainted)];
                    entryPrice = stopPrice + ((targetPrice - stopPrice) / 2);

                    DrawHorizontalLine("Target", true, targetPrice, Color.Green, DashStyle.Solid, 3);
                    DrawHorizontalLine("Entry", true, entryPrice, Color.Sienna, DashStyle.Solid, 3);
                    DrawHorizontalLine("Stop", true, stopPrice, Color.Red, DashStyle.Solid, 3);

                    ChartControl.Refresh();
                } // if (ChartControl != null)

                rewardRiskMgtEnabled = true;
            }
            else
            {
                // Revert button text to its default.
                toolStripButton.Font = btnDefFont;
                toolStripButton.ForeColor = Color.Black;

                if ( ChartControl != null )
                {
                    RemoveDrawObject("Target");
                    RemoveDrawObject("Entry");
                    RemoveDrawObject("Stop");

                    entry = null;
                    target = null;
                    stop = null;

                    ChartControl.Refresh();
                } // if (ChartControl != null)

                rewardRiskMgtEnabled = false;
            }
        }
コード例 #5
0
		public override void Plot(Graphics graphics, Rectangle bounds, double min, double max) {
			base.Plot(graphics, bounds, min, max);
			int y=0;

            // 28Mar12 CKKOH
            if ( rewardRiskMgtEnabled == false )
                return;

			try {
			if ( entry == null || stop == null || target == null ) {
			  foreach (IDrawObject draw in DrawObjects) {
    			if (draw.DrawType == DrawType.HorizontalLine) {
					draw.Locked = false;
			        switch (draw.Tag.ToUpper()) {
					case "ENTRY":
			        	entry = (IHorizontalLine) draw;
	            		break;
					case "STOP":
			        	stop = (IHorizontalLine) draw;
						break;         
					case "TARGET":
			        	target = (IHorizontalLine) draw;
						break;
					default:
						break;
			        }		
			    }
			  }
			}
			
			if ( entry != null ) {
				entryPrice = Instrument.MasterInstrument.Round2TickSize(entry.Y);
				y = ChartControl.GetYByValue(Bars, entryPrice);
				tradeSide  = ( stopPrice <= entryPrice ) ? 1 : -1;
				risk       = (entryPrice-stopPrice)*tradeSide;
				tickStop   = (int)Math.Round(risk/TickSize);
				reward     = (targetPrice-entryPrice)*tradeSide;
				tickTarget = (int)Math.Round(reward/TickSize);
				riskReward = ( risk != 0 ) ? reward/risk : 0;
				
					//### Risk Acct Percentage Specified
				if ( userAcctSize > 0 && userAcctRisk > 0 ) dollarRisk = userAcctSize * (userAcctRisk/100);
					//### Risk Explicit Dollar Amount Specified
				if ( userDollarRisk > 0 ) dollarRisk = userDollarRisk;
				
					//### Fixed Shares Specified
				if ( fixedShares > 0 ) {
					shares     = fixedShares;
					dollarRisk = shares * tickStop * dollarsPerTick;
				}
					//### Calculated Shares
				else {
					if ( tickStop > 0 && dollarsPerTick > 0 )
                        // Modified by CKKOH
						//shares = (int)(dollarRisk/(tickStop*dollarsPerTick));
                        shares = (int)((dollarRisk * sharesMultiplier)/ (tickStop * dollarsPerTick));
					else shares = 0;
				}
				graphics.DrawString( ((tradeSide>0)?"Long":"Short") +":  " +shares +" @ " +entryPrice.ToString(priceFormat) +"\n"  +tickStop +"T   [$"+dollarRisk.ToString("0") +"]", boldFont, entry.Pen.Brush, ChartControl.CanvasRight, y, format );
			}
			if ( stop != null ) {
				stopPrice = Instrument.MasterInstrument.Round2TickSize(stop.Y);
				y = ChartControl.GetYByValue(Bars, stopPrice);
                // Modified by CKKOH
				//graphics.DrawString("Stp:  " +shares +" @ " +((decimal)stopPrice).ToString(priceFormat) +"\n" +tickStop +"T   $"+(shares*tickStop*dollarsPerTick).ToString("0"), boldFont, stop.Pen.Brush, ChartControl.CanvasRight, y, format);
                graphics.DrawString("Stp:  " + shares + " @ " + ((decimal)stopPrice).ToString(priceFormat) + "\n" + tickStop + "T   $" + ((shares * tickStop * dollarsPerTick) / sharesMultiplier).ToString("0"), boldFont, stop.Pen.Brush, ChartControl.CanvasRight, y, format);
            }
			if ( target != null ) {
				targetPrice = Instrument.MasterInstrument.Round2TickSize(target.Y);
				y = ChartControl.GetYByValue(Bars, targetPrice);
                // Modified by CKKOH
                //graphics.DrawString("Tgt:  " +shares +" @ " +targetPrice.ToString(priceFormat) +"\n" +riskReward.ToString("0.##") +"R    " +tickTarget +"T   $" +(shares*tickTarget*dollarsPerTick).ToString("0"), boldFont, target.Pen.Brush, ChartControl.CanvasRight, y, format);
                graphics.DrawString("Tgt:  " + shares + " @ " + targetPrice.ToString(priceFormat) + "\n" + riskReward.ToString("0.##") + "R    " + tickTarget + "T   $" + ((shares * tickTarget * dollarsPerTick) / sharesMultiplier).ToString("0"), boldFont, target.Pen.Brush, ChartControl.CanvasRight, y, format);

			}
			} catch (Exception ex){
				//Print(ex.ToString());
				Print("(RISK_REWARD) Need Entry, Stop and Target lines");
				entry = null; stop = null; target = null;
				entryPrice = 0; stopPrice = 0; targetPrice = 0;
			}			
		}
コード例 #6
0
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            base.Plot(graphics, bounds, min, max);
            int y = 0;

            // 28Mar12 CKKOH
            if (rewardRiskMgtEnabled == false)
            {
                return;
            }

            try {
                if (entry == null || stop == null || target == null)
                {
                    foreach (IDrawObject draw in DrawObjects)
                    {
                        if (draw.DrawType == DrawType.HorizontalLine)
                        {
                            draw.Locked = false;
                            switch (draw.Tag.ToUpper())
                            {
                            case "ENTRY":
                                entry = (IHorizontalLine)draw;
                                break;

                            case "STOP":
                                stop = (IHorizontalLine)draw;
                                break;

                            case "TARGET":
                                target = (IHorizontalLine)draw;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }

                if (entry != null)
                {
                    entryPrice = Instrument.MasterInstrument.Round2TickSize(entry.Y);
                    y          = ChartControl.GetYByValue(Bars, entryPrice);
                    tradeSide  = (stopPrice <= entryPrice) ? 1 : -1;
                    risk       = (entryPrice - stopPrice) * tradeSide;
                    tickStop   = (int)Math.Round(risk / TickSize);
                    reward     = (targetPrice - entryPrice) * tradeSide;
                    tickTarget = (int)Math.Round(reward / TickSize);
                    riskReward = (risk != 0) ? reward / risk : 0;

                    //### Risk Acct Percentage Specified
                    if (userAcctSize > 0 && userAcctRisk > 0)
                    {
                        dollarRisk = userAcctSize * (userAcctRisk / 100);
                    }
                    //### Risk Explicit Dollar Amount Specified
                    if (userDollarRisk > 0)
                    {
                        dollarRisk = userDollarRisk;
                    }

                    //### Fixed Shares Specified
                    if (fixedShares > 0)
                    {
                        shares     = fixedShares;
                        dollarRisk = shares * tickStop * dollarsPerTick;
                    }
                    //### Calculated Shares
                    else
                    {
                        if (tickStop > 0 && dollarsPerTick > 0)
                        {
                            // Modified by CKKOH
                            //shares = (int)(dollarRisk/(tickStop*dollarsPerTick));
                            shares = (int)((dollarRisk * sharesMultiplier) / (tickStop * dollarsPerTick));
                        }
                        else
                        {
                            shares = 0;
                        }
                    }
                    graphics.DrawString(((tradeSide > 0)?"Long":"Short") + ":  " + shares + " @ " + entryPrice.ToString(priceFormat) + "\n" + tickStop + "T   [$" + dollarRisk.ToString("0") + "]", boldFont, entry.Pen.Brush, ChartControl.CanvasRight, y, format);
                }
                if (stop != null)
                {
                    stopPrice = Instrument.MasterInstrument.Round2TickSize(stop.Y);
                    y         = ChartControl.GetYByValue(Bars, stopPrice);
                    // Modified by CKKOH
                    //graphics.DrawString("Stp:  " +shares +" @ " +((decimal)stopPrice).ToString(priceFormat) +"\n" +tickStop +"T   $"+(shares*tickStop*dollarsPerTick).ToString("0"), boldFont, stop.Pen.Brush, ChartControl.CanvasRight, y, format);
                    graphics.DrawString("Stp:  " + shares + " @ " + ((decimal)stopPrice).ToString(priceFormat) + "\n" + tickStop + "T   $" + ((shares * tickStop * dollarsPerTick) / sharesMultiplier).ToString("0"), boldFont, stop.Pen.Brush, ChartControl.CanvasRight, y, format);
                }
                if (target != null)
                {
                    targetPrice = Instrument.MasterInstrument.Round2TickSize(target.Y);
                    y           = ChartControl.GetYByValue(Bars, targetPrice);
                    // Modified by CKKOH
                    //graphics.DrawString("Tgt:  " +shares +" @ " +targetPrice.ToString(priceFormat) +"\n" +riskReward.ToString("0.##") +"R    " +tickTarget +"T   $" +(shares*tickTarget*dollarsPerTick).ToString("0"), boldFont, target.Pen.Brush, ChartControl.CanvasRight, y, format);
                    graphics.DrawString("Tgt:  " + shares + " @ " + targetPrice.ToString(priceFormat) + "\n" + riskReward.ToString("0.##") + "R    " + tickTarget + "T   $" + ((shares * tickTarget * dollarsPerTick) / sharesMultiplier).ToString("0"), boldFont, target.Pen.Brush, ChartControl.CanvasRight, y, format);
                }
            } catch (Exception ex) {
                //Print(ex.ToString());
                Print("(RISK_REWARD) Need Entry, Stop and Target lines");
                entry      = null; stop = null; target = null;
                entryPrice = 0; stopPrice = 0; targetPrice = 0;
            }
        }