zoukankan      html  css  js  c++  java
  • MC-设置 止盈

    using System;
    using System.Drawing;
    using System.Linq;
    using PowerLanguage.Function;
    using ATCenterProxy.interop;
     
    namespace PowerLanguage.Strategy
    {
        [IOGMode(IOGMode.Enabled)]
        public class ExampleTakeProfit : SignalObject
        {
            private IOrderMarket buyOrder, sellTimeStopOrder;
            private IOrderPriced sellTPorder;
            private double takeProfitPrice;
     
            [Input]
            public int TakeProfitTicks { get; set; }
     
            public ExampleTakeProfit(object _ctx) : base(_ctx) { }
     
            protected override void Create()
            {
                buyOrder = OrderCreator.MarketNextBar(new SOrderParameters(
                    Contracts.Default, EOrderAction.Buy));
     
                sellTPorder = OrderCreator.Limit(new SOrderParameters(
                    Contracts.Default, "TakeProfit", EOrderAction.Sell));
     
                sellTimeStopOrder = OrderCreator.MarketNextBar(new SOrderParameters(
                    Contracts.Default, "TimeStop", EOrderAction.Sell));
     
                TakeProfitTicks = 200; // Default value
            }
     
            protected override void StartCalc()
            {
                Output.Clear();     // Clear Editor Output tab
            }
     
            protected override void CalcBar()
            {
                // When flat, enter a long position every fifth bar
                if ((StrategyInfo.MarketPosition == 0) && (Bars.CurrentBar % 5 == 0))
                {
                    // Submit the order at the open of the bar
                    if (Bars.Status == EBarState.Open)
                    {
                        buyOrder.Send();
     
                        Output.WriteLine("{0} - Submitted buy order",
                            Bars.Time[0].ToString("d-M HH:mm"));
                    }
                }
     
                // Management of open long position
                if (StrategyInfo.MarketPosition > 0)
                {
                    // First, when the position is just opened,
                    // we need to calculate the take profit price
                    int barsInPosition = Bars.CurrentBar -
                        Positions[0].OpenTrades[0].EntryOrder.BarNumber;
     
                    // When the position is just opened, calculate the take profit price
                    if (barsInPosition == 0)
                    {
                        takeProfitPrice = Positions[0].OpenTrades[0].EntryOrder.Price +
                            (TakeProfitTicks * (Bars.Info.MinMove / Bars.Info.PriceScale));
     
                        // Only output info to the Output log at the open
                        // of the bar (prevents cluttering the log)
                        if (Bars.Status == EBarState.Open)
                        {
                            Output.WriteLine("{0} - Take profit price: {1}",
                                Bars.Time[0].ToString("d-M HH:mm"),
                                takeProfitPrice);
                        }
                    }
     
                    // Submit take profit order as long as there is an open long position
                    sellTPorder.Send(takeProfitPrice);
     
                    if (Bars.Status == EBarState.Close)     // Prevents cluttering the output
                    {
                        Output.WriteLine("{0} - Sending limit order @ {1}",
                            Bars.Time[0].ToString("d-M HH:mm"),
                            takeProfitPrice);
                    }
     
                    // To prevent positions that are never closed, exit after more than 5 bars
                    if (barsInPosition > 5)
                    {
                        sellTimeStopOrder.Send();
     
                        if (Bars.Status == EBarState.Open)  // Prevents cluttering the output
                        {
                            Output.WriteLine("{0} - Sending time stop order",
                                Bars.Time[0].ToString("d-M HH:mm"));
                        }
                    }
                }
            }
        }
    }
  • 相关阅读:
    因浮动问题导致的IE6/7下的换行
    弹性回到顶部js代码
    页面图片的缩放问题
    js练习小结
    地址给的越精确,优先级越高
    判断IE浏览器的版本
    img图像对齐的方式
    三级导航收缩下拉框
    功能已经实现
    AE创建一个空白的Shapefile
  • 原文地址:https://www.cnblogs.com/aliblogs/p/5493818.html
Copyright © 2011-2022 走看看