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 = ; // 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-设置 止盈的更多相关文章
- AJPFX:什么是止盈?什么是止损?
在您进行外汇交易后,会碰到Take Profit(止盈)和 Stop Loss(止损)这两个词,均是用作控制风险的工具. 止盈(Take Profit):当单子达到预期的获利价格时锁定盈利.当订单在盈 ...
- Python之关于量化投资实现代码--根据策略提出的代码--还未完善
# 根据缺口的模式选股买股票 ''' -------------------------------------------- 1.总体回测前要做的事情 initialize(context) 1.1 ...
- 玩好百家乐需要掌握些什么技巧和打法?来自ag老玩家的实战经验心得总结
最近很多网友给我留言,说为什么学了很多技巧和打法这个游戏还是玩不好,坦白说,其实bjl想要玩得好,不是说你懂得多少技巧和掌握了多少种打法就可以的了,而是你要懂得如何把这些正确结合去运用,这些我之前都强 ...
- MC中间件WCCS
一.问题描述 在大访问量的Web服务中,MC集群作为缓解后端数据源访问压力的中间层已经成为了不可缺少的一部分,机器数量越来越大,维护成本也变得越来越高了,其中的问题有: 故障机器自动剔除.后端某台MC ...
- just555 对话
网易 新闻 2005-03-31 16:37:47 空!(19194697)555,你在大连炒单,单日最大盈利率多少? 2005-03-31 16:37:59 just555(79610908)最大1 ...
- 国外成熟的程序交易系统的思路 z
波涛(1998)在<系统交易方法>中提出,一个设计良好的交易系统,必须对投资决策的各个相关环节做出相应明确的规定,同时还必须符合使用者的心理特征.投资对象的统计特征以及投资资金的风险特征. ...
- 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 ...
- WeQuant交易策略—网格交易
网格交易策略(Grid Trading) 策略介绍 网格策略本质上是一种低吸高抛的策略.标的物价格越低,吸纳的头寸越多:标的物价格越高,卖出的头寸越多.网格策略巧妙地借鉴了日常生活中渔翁撒网扑鱼的思路 ...
- WeQuant交易策略—Dual Thrust
Dual Thrust策略 策略介绍 Dual Thrust是一个趋势跟踪系统,由Michael Chalek在20世纪80年代开发,曾被Future Thruth杂志评为最赚钱的策略之一. Dual ...
随机推荐
- Spring MVC中页面向后台传值的几种方式
在学习 Spring Mvc 过程中,有必要来先了解几个关键参数: @Controller: 在类上注解,则此类将编程一个控制器,在项目启动 Spring 将自动扫描此类,并进行对 ...
- pack://application:,,,/
FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid)); gridFactory.SetValu ...
- [Jenkins]怎么删除jenkins里项目配置的svn记录
问题出现原因: 当持续集成项目运行一段时间之后,你会发现不知不觉中,配置了不少过往的SVN账号,都已经不能用了,失效了,影响选择有时候,想要删除 问题解决办法: 1.选择$JENKINS_HOME/c ...
- Web网页数据抓取(C/S)
通过程序自动的读取其它网站网页显示的信息,类似于爬虫程序.比方说我们有一个系统,要提取BaiDu网站上歌曲搜索排名.分析系统在根据得到的数据进行数据分析.为业务提供参考数据. 为了完成以上的需求,我们 ...
- 职责链模式(Chain of Responsibility)(对象行为型)
1.概述 你去政府部门求人办事过吗?有时候你会遇到过官员踢球推责,你的问题在我这里能解决就解决,不能解决就推卸给另外个一个部门(对象).至于到底谁来解决这个问题呢?政府部门就是为了可以避免屁民的请求与 ...
- Django- 'WSGIRequest' object has no attribute 'user'
在用django建第一个blog的时候,进入localhost:8000/admin的时候报上面的错: 查了好多资料,最后还是没解决,最后发现原因是我第一次建这个blog工程的时候用的django的版 ...
- POJ 3414 Pots(BFS)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description You are g ...
- PL SQL Developer报错框乱码
在系统变量里设置 变量名:NLS_LANG 变量值设为:SIMPLIFIED CHINESE_CHINA.ZHS16GBK
- (ASP.NET )去除字符串中的HTML标签
string strDoContent = "执行增加<a href="/AdminCX/Admin_CompanyDetail.aspx?CompanyGuid=cd8e1 ...
- JavaFX基础学习之OkHttp/Gson
导入jar包,使用OkHttp/Okio/Gson请求解析 package application; import java.io.IOException; import java.net.URL; ...