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. shell实现四则运算简单方法

    在刚刚学习写shell 批处理时候,进行逻辑运算中,少不了需要进行基础的:四则运算,这里说说在linux shell 里面简单的实现方法.1.简单方法$ b=$((5*5+5-3/2)) $ echo ...

  2. sql第三天

    ->完整的select语句及执行顺序(必须记住) 5...select 5.2->distinct 7...top n [percent] 5.1->列名 聚合函数(1.2-> ...

  3. HDU 5895 Mathematician QSC

    矩阵快速幂,欧拉定理. $g(n)$递推式:$g(n)=5g(n-1)+5g(n-2)-g(n-3)$,可以构造矩阵快速求递$n$项,指数很大,可以利用欧拉定理降幂. #pragma comment( ...

  4. 关于FlagsAttribute

    最近在看C#本质论,有介绍FlagsAttribute的特性,看了下源码,发现只是一个简单的特性class和一个构造函数. 调试了一下.NET的源码,发现在console.writeline(***) ...

  5. 解锁Oracle数据库用户

    Oracle数据库,如何解除数据库用户账户的锁定呢???如何修改口令呢??? 请问各位高手:Oracle数据库,如何解除数据库用户账户的锁定呢???如何修改口令呢???[万分感激各位高手的帮忙] 00 ...

  6. [SQL基础教程] 3-1 对表进行聚合查询

    [SQL基础教程] 3-1 对表进行聚合查询 聚合函数 用于合计的函数称为聚合函数或者集合函数 COUNT SUM AVG MAX MIN SELECT COUNT(*) FROM table; SE ...

  7. sim808模块收发送短信

    一,简介 SIM 808发送短信分text模式和PDU模式.text模式已ascii码发送短信,这种模式比较简单,发送命令AT+CMGF=1就可以发送短信,而PDU模式比较复杂,首先发送命令AT+CM ...

  8. 《HTML5与CSS3权威指南》读书笔记(下册)—CSS3篇

    大而全的CSS3 API类型书,并带有一些实用案例讲解,层次分明分类明确,新增技术都做了详情介绍.个人觉得如果在细节和文字表达上再下些功夫会更出色,其中部分内容如:rem.Media Queries网 ...

  9. jQuery的9中构造函数

    // 接受一个字符串,其中包含了用于匹配元素集合的 CSS 选择器 jQuery([selector,[context]]) // 传入单个 DOM jQuery(element) // 传入 DOM ...

  10. 快速挂载和分离VHD文件的小脚本

      =======代码开始======== echo select vdisk file= %VHD文件路径% echo attach vdisk exit 分离VHD的脚本,只需要将上述代码中 at ...