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. HDU 5904 LCIS

    $dp$. 这题的突破口在于要求数字是连续的. 可以分别记录两个串以某个数字为结尾的最长上升长度,然后枚举一下以哪个数字为结尾就可以得到答案了. 因为$case$有点多,不能每次$memset$,额外 ...

  2. VMware虚拟机服务的vmware-hostd自动启动和停止

    安装了虚拟机 任务管理器会出现vmware-hostd.exe  占用了80端口,导致xampp打不开,所以就想关闭vmware,解决方案如下: 开始——运行——services.msc,找到VM打头 ...

  3. 如何使用Git上传代码到GitHub

    1.在Github上面创建Github仓库: 2.下载Github Shell到本地:https://desktop.github.com/ 3.打开Github Shell,输入以下命令生成秘钥来验 ...

  4. struts2查询的数据的存放

    当我们查询数据的时候,把它存放到一个位置.以供页面显示. 1:使用***Map取代内置对象存放 public String query(){ ActionContext.getContext().pu ...

  5. 【简单并查集】Farm Irrigation

    Farm Irrigation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  6. ios 显示其他app的购买页面

    using UnityEngine; using System.Collections; using System.Runtime.InteropServices ; public class IOS ...

  7. Spring Boot--war发布

    启动main类继承SpringBootServletInitializer,并重写"protected SpringApplicationBuilder configure(SpringAp ...

  8. Shell学习笔记 ——第二天

    1.显示日期 date  |   cal   cal 2010  cal 2 2010 2.改变文件拥有者 chown 3.改变文件权限 chmod 4.显示当前目录 pwd 5.查看文件尾部内容,并 ...

  9. checkbox:获取所有已选中的值

    /**获取选中的checkbox值*/ function getChecked(){ var ids = ""; $("input:checkbox[name='id'] ...

  10. mybatis xml的无效判空

    <insert id="insert"> <if test="xxxMappingEntityList != null and xxxMappingEn ...