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 = ; // 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 == ) && (Bars.CurrentBar % == ))
{
// Submit the order at the open of the bar
if (Bars.Status == EBarState.Open)
{
buyOrder.Send(); Output.WriteLine("{0} - Submitted buy order",
Bars.Time[].ToString("d-M HH:mm"));
}
} // Management of open long position
if (StrategyInfo.MarketPosition > )
{
// First, when the position is just opened,
// we need to calculate the take profit price
int barsInPosition = Bars.CurrentBar -
Positions[].OpenTrades[].EntryOrder.BarNumber; // When the position is just opened, calculate the take profit price
if (barsInPosition == )
{
takeProfitPrice = Positions[].OpenTrades[].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[].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[].ToString("d-M HH:mm"),
takeProfitPrice);
} // To prevent positions that are never closed, exit after more than 5 bars
if (barsInPosition > )
{
sellTimeStopOrder.Send(); if (Bars.Status == EBarState.Open) // Prevents cluttering the output
{
Output.WriteLine("{0} - Sending time stop order",
Bars.Time[].ToString("d-M HH:mm"));
}
}
}
}
}
}

MC-设置 止盈的更多相关文章

  1. AJPFX:什么是止盈?什么是止损?

    在您进行外汇交易后,会碰到Take Profit(止盈)和 Stop Loss(止损)这两个词,均是用作控制风险的工具. 止盈(Take Profit):当单子达到预期的获利价格时锁定盈利.当订单在盈 ...

  2. Python之关于量化投资实现代码--根据策略提出的代码--还未完善

    # 根据缺口的模式选股买股票 ''' -------------------------------------------- 1.总体回测前要做的事情 initialize(context) 1.1 ...

  3. 玩好百家乐需要掌握些什么技巧和打法?来自ag老玩家的实战经验心得总结

    最近很多网友给我留言,说为什么学了很多技巧和打法这个游戏还是玩不好,坦白说,其实bjl想要玩得好,不是说你懂得多少技巧和掌握了多少种打法就可以的了,而是你要懂得如何把这些正确结合去运用,这些我之前都强 ...

  4. MC中间件WCCS

    一.问题描述 在大访问量的Web服务中,MC集群作为缓解后端数据源访问压力的中间层已经成为了不可缺少的一部分,机器数量越来越大,维护成本也变得越来越高了,其中的问题有: 故障机器自动剔除.后端某台MC ...

  5. just555 对话

    网易 新闻 2005-03-31 16:37:47 空!(19194697)555,你在大连炒单,单日最大盈利率多少? 2005-03-31 16:37:59 just555(79610908)最大1 ...

  6. 国外成熟的程序交易系统的思路 z

    波涛(1998)在<系统交易方法>中提出,一个设计良好的交易系统,必须对投资决策的各个相关环节做出相应明确的规定,同时还必须符合使用者的心理特征.投资对象的统计特征以及投资资金的风险特征. ...

  7. MT5基础知识

    获取账户相关信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 printf("ACCOUNT_BALANCE ...

  8. WeQuant交易策略—网格交易

    网格交易策略(Grid Trading) 策略介绍 网格策略本质上是一种低吸高抛的策略.标的物价格越低,吸纳的头寸越多:标的物价格越高,卖出的头寸越多.网格策略巧妙地借鉴了日常生活中渔翁撒网扑鱼的思路 ...

  9. WeQuant交易策略—Dual Thrust

    Dual Thrust策略 策略介绍 Dual Thrust是一个趋势跟踪系统,由Michael Chalek在20世纪80年代开发,曾被Future Thruth杂志评为最赚钱的策略之一. Dual ...

随机推荐

  1. filter怎么在程序里写,不用再web.xml中配置

  2. Servle资源注射

    Servle资源注射@WebServlet(name = "DownloadServlet",urlPatterns ="/DownloadServlet" ) ...

  3. 解决vs2013下创建的python文件,到其他平台(如linux)下中文乱码(或运行时报SyntaxError: (unicode error) 'utf-8' codec can't decode byte...)

    Vs2013中创建python文件,在文件中没输入中文时,编码为utf-8的,如图 接着,在里面输入几行中文后,再次用notepad++查看其编码如下,在vs下运行也报错(用cmd运行就不会): 根据 ...

  4. 高效开发之SASS篇

    作为通往前端大神之路的普通的一只学鸟,最近接触了一样稍微高逼格一点的神器,特与大家分享~ 他是谁? 作为前端开发人员,你肯定对css很熟悉,但是你知道css可以自定义吗?大家都知道,js中可以自定义变 ...

  5. USACO 3.3 Shopping Offers

    Shopping OffersIOI'95 In a certain shop, each kind of product has an integer price. For example, the ...

  6. sqlserver 操作xml

    1.xml.exist    输入为XQuery表达式,返回0,1或是Null.0表示不存在,1表示存在,Null表示输入为空 2.xml.value    输入为XQuery表达式,返回一个SQL ...

  7. 显示hibernate的sql语句

    <property name="show_sql">true</property> <property name="format_sql&q ...

  8. Centos6.5环境中安装vsftp服务

    1.检查vsftp是否安装 命令:rpm -qa|grep vsftpd 若已经安装,则显示相关的版本信息,否则什么也没有. 也可以输入find -name "vsftpd" -p ...

  9. 一、java自带的观察者模式

    Observer对象是观察者,Observable对象是被观察者. 官网api文档:http://docs.oracle.com/javase/7/docs/api/ 1. 实现观察者模式 实现观察者 ...

  10. 重新注册.netframework4.0

    IIS和.netfw4.0安装顺序是从前到后,如果不小心颠倒了,无所谓. 打开程序-运行-cmd:输入一下命令重新注册IIS C:\WINDOWS\Microsoft.NET\Framework\v4 ...