MC- 交易并设置止损
using System;using System.Drawing;using System.Linq;using PowerLanguage.Function;using ATCenterProxy.interop;namespace PowerLanguage.Strategy{ public class Example_StopLimit : SignalObject { private IOrderMarket buyMarketOrder, sellMarketOrder; private IOrderStopLimit sellStopLimitOrder; private double sellStopPrice, sellLimitPrice; public Example_StopLimit(object _ctx) : base(_ctx) { } protected override void Create() { buyMarketOrder = OrderCreator.MarketNextBar(new SOrderParameters( Contracts.Default, "EnterLong", EOrderAction.Buy)); sellMarketOrder = OrderCreator.MarketNextBar(new SOrderParameters( Contracts.Default, "ExitLong", EOrderAction.Sell)); sellStopLimitOrder = OrderCreator.StopLimit(new SOrderParameters( Contracts.Default, "StopLMT", EOrderAction.Sell)); } protected override void StartCalc() { Output.Clear(); // Clear PowerLanguage Editor output tab } protected override void CalcBar() { // When flat, enter long on first bar of day if ((StrategyInfo.MarketPosition == 0) && (Bars.Time[0].Date != Bars.Time[1].Date)) { buyMarketOrder.Send(); sellStopPrice = Bars.Low[0] - Bars.Range(); sellLimitPrice = Bars.Low[0] - (Bars.Range() * 1.5); Output.WriteLine("{0} - Buy order submitted. Sell stop calculated @ {1} with limit {2}", Bars.Time[0].ToString("d-M HH:mm:ss"), sellStopPrice, sellLimitPrice); } // Long order management if (StrategyInfo.MarketPosition > 0) { // Submit the stop-limit order as long as there is an open position sellStopLimitOrder.Send(sellStopPrice, sellLimitPrice); Output.WriteLine("{0} - Submitting sell stop @ {1} with limit {2}", Bars.Time[0].ToString("d-M HH:mm:ss"), sellStopPrice, sellLimitPrice); // Time stop; exit the position after 15 bars double barsInPosition = Bars.CurrentBar - CurrentPosition.OpenTrades[0].EntryOrder.BarNumber; if (barsInPosition >= 15) { sellMarketOrder.Send(); Output.WriteLine("{0} - Position open for {1} bars, submitting exit long market order", Bars.Time[0].ToString("d-M HH:mm:ss"), barsInPosition); } } } }}
|
MC- 交易并设置止损的更多相关文章
- 止损+TS
单策略单品种单策略多品种多策略单品种和加仓多策略多品种静态仓位和动态仓位 金肯特钠(kingKeltner)布林强盗(BollingerBandit)动态突破(DynamicBreakOutII)恒温 ...
- discuz全局数组变量 后台各项设置 完整版
$_G 保存了 Discuz! 中所有的预处理数据 缓存能够很好的提高程序的性能,一些配置数据没必要每次都查询数据库,只要在修改了的时候更新下缓存即可. Discuz! 中所有的缓存保存在 $_G[c ...
- 《零起点,python大数据与量化交易》
<零起点,python大数据与量化交易>,这应该是国内第一部,关于python量化交易的书籍. 有出版社约稿,写本量化交易与大数据的书籍,因为好几年没写书了,再加上近期"前海智库 ...
- just555 对话
网易 新闻 2005-03-31 16:37:47 空!(19194697)555,你在大连炒单,单日最大盈利率多少? 2005-03-31 16:37:59 just555(79610908)最大1 ...
- R与金钱游戏:均线黄金交叉2
从上一篇分析已经得知均线黄金交叉原则并不适用于震荡期,那有什么办法可以规避震荡期呢或者说有什么办法可以减少无脑跟的损失?我们继续玩一下. Required Packages library(quant ...
- 吐血整理,一文读懂中国金融衍生品市场的前世今生和未来[z]
[z]https://www.gfedu.cn/cfrm/content_22687.shtml 从定义上来说,金融衍生工具(derivativesecurity)是在货币.债券.股票等传统金融工具的 ...
- LR12.53—第7课:分析场景
第7课:分析场景 在前面的课程中,您学习如何设计,控制和执行方案运行.一旦您已加载您的服务器,你要分析的运行,并确定需要被淘汰,以提高系统性能的问题. 在图表和报告中有关方案的性能您的分析会议上提出的 ...
- python---Memcached
Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
- 17.Python笔记之memcached&redis
作者:刘耀 博客:www.liuyao.me 博客园:www.cnblogs.com/liu-yao 一.Memcached 1.介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动 ...
随机推荐
- UGUI事件系统
UGUI系统 将UI可能触发的事件分为12个类型,即EventTriggerType枚举的12个值. PointerEnter-- PointerExit-- PointerDown-- Pointe ...
- Spring Security(17)——基于方法的权限控制
目录 1.1 intercept-methods定义方法权限控制 1.2 使用pointcut定义方法权限控制 1.3 使用注解定义方法权限控制 1.3.1 JSR-25 ...
- hadoop操作
常用命令: https://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html ls命令 /usr/bin/hadoop/software/hadoop/ ...
- LeetCode 328. Odd Even Linked List C#
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- C#中string.Substring 的用法
String.SubString(int startIndex,int length) startIndex:截取字符串开始的位置 length:截取字符串的长度 例子:用户 输 ...
- Math 对象 识记
Math 对象用于执行数学任务. 1.使用 Math 的属性和方法的语法: var pi_value=Math.PI; var sqrt_value=Math.sqrt(15); 注释:Math 对象 ...
- GitHub上优秀的ThirdParty
仅为个人记录. 1.SwiftyJSON GitHub地址:https://github.com/SwiftyJSON/SwiftyJSON 2.CryptoSwift GitHub地址:https: ...
- Python 第一课笔记
1.Hello World程序的两种方法 在windows下执行 1.编辑器里输入,不用编译 print("Hello World!") 直接就可以运行 2.可以 ...
- RF环境搭建
官网:http://robotframework.org/ 序号 安装包名 安装方法 下载地址 备注 1 python exe文件,直接双击安装 https://www.python.org/down ...
- jquery学习笔记2——jq效果
一.显示隐藏: 可以使用show()和hide()方法来显示隐藏: $("#hide").click(function(){ $("p").hide(); }) ...