//------------------------------------------------------------------------
// 简称: cdft
// 名称: 抄底反弹
// 类别: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
Params
//此处添加参数
Numeric moneyRatio(0.1);
Numeric cd(0.001,0.001,0.01,0.001);
Numeric zy(0.005,0.0002,0.005,0.0001);
Numeric zs(0.005,0.0002,0.005,0.0001);
Vars
//此处添加变量
Numeric avg;
Global Numeric buyOpenPrice;
Global Numeric sellOpenPrice;
Global Integer timerId;
Defs
//此处添加公式函数
Numeric calcAvg(Numeric a,Numeric b)
{
return (a+b)/2;
}
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次,应用在订阅数据等操作
OnInit()
{
//timerId=createTimer(millsecs);
//与数据源有关
Range[0:DataCount-1]
{
//=========数据源相关设置==============
//AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权
//AddDataFlag(Enum_Data_RolloverRealPrice()); //设置映射真实价格
//AddDataFlag(Enum_Data_AutoSwapPosition()); //设置自动换仓
//AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //设置忽略换仓信号计算
//AddDataFlag(Enum_Data_OnlyDay()); //设置仅日盘
//AddDataFlag(Enum_Data_OnlyNight()); //设置仅夜盘
//AddDataFlag(Enum_Data_NotGenReport()); //设置数据源不参与生成报告标志
//=========交易相关设置==============
//MarginRate rate;
//rate.ratioType = Enum_Rate_ByFillAmount; //设置保证金费率方式为成交金额百分比
//rate.longMarginRatio = 0.1; //设置保证金率为10%
//rate.shortMarginRatio = 0.2; //设置保证金率为20%
//SetMarginRate(rate);
//CommissionRate tCommissionRate;
//tCommissionRate.ratioType = Enum_Rate_ByFillAmount;
//tCommissionRate.openRatio = 5; //设置开仓手续费为成交金额的5%%
//tCommissionRate.closeRatio = 2; //设置平仓手续费为成交金额的2%%
//tCommissionRate.closeTodayRatio = 0; //设置平今手续费为0
//SetCommissionRate(tCommissionRate); //设置手续费率
//SetSlippage(Enum_Rate_PointPerHand,2); //设置滑点为2跳/手
//SetOrderPriceOffset(2); //设置委托价为叫买/卖价偏移2跳
//SetOrderMap2MainSymbol(); //设置委托映射到主力
//SetOrderMap2AppointedSymbol(symbols, multiples); //设置委托映射到指定合约,symbols是映射合约数组,multiples是映射倍数数组
}
//与数据源无关
//SetBeginBarMaxCount(10); //设置最大起始bar数为10
//SetBackBarMaxCount(10); //设置最大回溯bar数为10
//=========交易相关设置==============
SetInitCapital(1000000); //设置初始资金为100万
//AddTradeFlag(Enum_Trade_Ignore_Buy()); //设置忽略多开
//AddTradeFlag(Enum_Trade_Ignore_Sell()); //设置忽略多平
//AddTradeFlag(Enum_Trade_Ignore_SellShort()); //设置忽略空开
//AddTradeFlag(Enum_Trade_Ignore_Buy2Cover()); //设置忽略空平
}
//在所有的数据源准备完成后调用,应用在数据源的设置等操作
OnReady()
{
}
//基础数据更新事件函数
OnDic(StringRef dicName,StringRef dicSymbol,DicDataRef dicValue)
{
}
//在新bar的第一次执行之前调用一次,参数为新bar的图层数组
OnBarOpen(ArrayRef<Integer> indexs)
{
}
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
Numeric price;
Numeric a;
Numeric b;
Numeric c;
//avg=calcAvg(high,low);
Numeric df = Low/open-1;
Numeric hf = High/open-1;
//print(\"close1:\"+Text(Close[1])+\" close0:\"+Text(Close[0]));
if(MarketPosition==1){
Numeric zf = high/buyOpenPrice-1;
Numeric df = low/buyOpenPrice-1;
if (zf>=zy){
//Print(\"buyOpenPrice:\" + Text(buyOpenPrice));
price = buyOpenPrice*(1+zy);
Print(\"zy:\" + Text(price));
Sell(0,price);
}Else if (df<=-zs){
price = buyOpenPrice*(1-zs);
Print(\"zs:\" + Text(price));
Sell(0,price);
}
}
if(MarketPosition==-1){
Numeric zf = high/sellOpenPrice-1;
Numeric df = low/sellOpenPrice-1;
if (df<=-zy){
//Print(\"openPrice:\" + Text(openPrice));
price = sellOpenPrice*(1-zy);
Print(\"zy:\" + Text(price));
//Sell(0,price);
BuyToCover(0,price);
}Else if (zf>=zs){
price = sellOpenPrice*(1+zs);
Print(\"zs:\" + Text(price));
//Sell(0,price);
BuyToCover(0,price);
}
}
if(MarketPosition==0){
if (df <= -cd){
Numeric ht = close/Low-1;
Numeric htyz = 0.0005;
if(ht>htyz){
Numeric TotalEquity = Portfolio_CurrentCapital() + Portfolio_UsedMargin();
Print(\"TotalEquity:\" + Text(TotalEquity));
Numeric TurtleUnits = (TotalEquity*moneyRatio) /(open * ContractUnit()*BigPointValue()*MarginRatio());
TurtleUnits = IntPart(TurtleUnits); // 对小数取整
Print(\"TurtleUnits:\" + Text(TurtleUnits));
//Buy(TurtleUnits,Open);
buyOpenPrice=Open*(1+df+htyz);
Print(\"buyOpenPrice:\" + Text(buyOpenPrice));
Buy(1,buyOpenPrice);
}
}else if(hf>=cd){
Numeric ht = close/h-1;
Numeric htyz = 0.0005;
if(ht<-htyz){
Numeric TotalEquity = Portfolio_CurrentCapital() + Portfolio_UsedMargin();
Print(\"TotalEquity:\" + Text(TotalEquity));
Numeric TurtleUnits = (TotalEquity*moneyRatio) /(open * ContractUnit()*BigPointValue()*MarginRatio());
TurtleUnits = IntPart(TurtleUnits); // 对小数取整
Print(\"TurtleUnits:\" + Text(TurtleUnits));
//Buy(TurtleUnits,Open);
sellOpenPrice=Open*(1+hf-htyz);
Print(\"sellOpenPrice:\" + Text(sellOpenPrice));
//Buy(1,openPrice);
SellShort(1,sellOpenPrice);
}
}
}
}
//下一个Bar开始前,重新执行当前bar最后一次,参数为当前bar的图层数组
OnBarClose(ArrayRef<Integer> indexs)
{
}
//Tick更新事件函数,需要SubscribeTick函数订阅后触发,参数evtTick表示更新的tick结构体
OnTick(TickRef evtTick)
{
}
//持仓更新事件函数,参数pos表示更新的持仓结构体
OnPosition(PositionRef pos)
{
}
//策略账户仓更新事件函数,参数pos表示更新的账户仓结构体
OnStrategyPosition(PositionRef pos)
{
}
//委托更新事件函数,参数ord表示更新的委托结构体
OnOrder(OrderRef ord)
{
}
//成交更新事件函数,参数ordFill表示更新的成交结构体
OnFill(FillRef ordFill)
{
}
//定时器更新事件函数,参数id表示定时器的编号,millsecs表示定时间的间隔毫秒值
OnTimer(Integer id,Integer intervalMillsecs)
{
}
//通用事件触发函数,参数evtName为事件名称,参数evtValue为事件内容
OnEvent(StringRef evtName,MapRef<String,String> evtValue)
{
}
//当前策略退出时触发
OnExit()
{
}
假得不要不要的
一看回测图就知道偷价了,或有未来
官方不会评价用户间购买的程序,你可以直接找卖家
楼里也说了 存在偷价
计算使用close,用了未来数据;买入价格使用open相关,偷了数据。
实盘不可能会有如此平滑的曲线,要么有未来函数
看曲线就知道不能用,这么好的策略还用在闲鱼上卖?
我送你个无源码的给你,不要钱。
行啊,聯係方式方便説下嗎
tianxin_000456
微信吗
@wangkaiming老师帮忙看看,行吗
不能
现在真的是骗子无处不在
他的这个交易逻辑,能给我讲述下吗?我是个新手,
你的受骗策略,和我一样吗
不能用吗?