//------------------------------------------------------------------------
// 简称: MAtrend
// 名称: MA趋势
// 类型: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
Params
Bool isRollover(False);//是否后复权
Bool isRolloverRealPrice(False);//是否映射真实价格
Bool isAutoSwapPosition(False);//是否自动换仓
Bool ignoreSwapSiganlCalc(False); //是否忽略换仓信号计算
Vars
Bool bVarCondition_buy_1;
Bool bVarCondition_buy_2;
Numeric nVarPlotValue_buy_2;
Bool bVarCondition_buy_3;
Numeric nVarPlotValue_buy_3;
Bool bVarCondition_buy_4;
Numeric nVarPlotValue_buy_4_left;
Numeric nVarPlotValue_buy_4_right;
Integer iVarSignal_Flag_Buy_1(0);
Numeric dVarPrice_buy_1;
Numeric dVarPrice_buy_1_volume;
Bool bVarCondition_sellShort_1;
Bool bVarCondition_sellShort_2;
Numeric nVarPlotValue_sellShort_2;
Bool bVarCondition_sellShort_3;
Numeric nVarPlotValue_sellShort_3;
Bool bVarCondition_sellShort_4;
Numeric nVarPlotValue_sellShort_4_left;
Numeric nVarPlotValue_sellShort_4_right;
Integer iVarSignal_Flag_SellShort_2(0);
Numeric dVarPrice_sellShort_2;
Numeric dVarPrice_sellShort_2_volume;
Bool bVarCondition_sell_1;
Bool bVarCondition_sell_2;
Numeric nVarPlotValue_sell_2;
Bool bVarCondition_sell_3;
Numeric nVarPlotValue_sell_3;
Bool bVarCondition_sell_4;
Numeric nVarPlotValue_sell_4_left;
Numeric nVarPlotValue_sell_4_right;
Integer iVarSignal_Flag_Sell_3(0);
Numeric dVarPrice_sell_3;
Numeric dVarPrice_sell_3_volume;
Bool bVarCondition_buyToCover_1;
Bool bVarCondition_buyToCover_2;
Numeric nVarPlotValue_buyToCover_2;
Bool bVarCondition_buyToCover_3;
Numeric nVarPlotValue_buyToCover_3;
Bool bVarCondition_buyToCover_4;
Numeric nVarPlotValue_buyToCover_4_left;
Numeric nVarPlotValue_buyToCover_4_right;
Integer iVarSignal_Flag_BuyToCover_4(0);
Numeric dVarPrice_buyToCover_4;
Numeric dVarPrice_buyToCover_4_volume;
Defs
Integer Cond_round_volume(Numeric volume, Numeric price = 0)
{
Return IntPart(Round(volume / BaseShares(), 0))*BaseShares();
}
Bool Cond_LocalTimeLimit(Numeric bTime, Numeric eTime)
{
If(MakeDateTime(Date(),Time()) >= bTime And MakeDateTime(Date(),Time()) <= eTime)
{
Return True;
}
Return False;
}
Bool buy_condition_1()
{
Return MarketPosition() <= 0.000000;
}
Bool buy_condition_2()
{
nVarPlotValue_buy_2=GetPlotNumericValue("MACD","MACD");
If(InvalidNumeric() == nVarPlotValue_buy_2)
{
Return False;
}
Return nVarPlotValue_buy_2 >= 0.000000;
}
Bool buy_condition_3()
{
nVarPlotValue_buy_3=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_buy_3)
{
Return False;
}
Return Close() >= nVarPlotValue_buy_3;
}
Bool buy_condition_4()
{
nVarPlotValue_buy_4_left=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_buy_4_left)
{
Return False;
}
nVarPlotValue_buy_4_right=GetPlotNumericValue("mayesterday","MA2");
If(InvalidNumeric() == nVarPlotValue_buy_4_right)
{
Return False;
}
Return nVarPlotValue_buy_4_left >= nVarPlotValue_buy_4_right;
}
Bool time_condition_Buy_1()
{
Return Cond_LocalTimeLimit(0, 20220124.120452);
}
Bool sellShort_condition_1()
{
Return MarketPosition() >= 0.000000;
}
Bool sellShort_condition_2()
{
nVarPlotValue_sellShort_2=GetPlotNumericValue("MACD","MACD");
If(InvalidNumeric() == nVarPlotValue_sellShort_2)
{
Return False;
}
Return nVarPlotValue_sellShort_2 <= 0.000000;
}
Bool sellShort_condition_3()
{
nVarPlotValue_sellShort_3=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_sellShort_3)
{
Return False;
}
Return Close() <= nVarPlotValue_sellShort_3;
}
Bool sellShort_condition_4()
{
nVarPlotValue_sellShort_4_left=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_sellShort_4_left)
{
Return False;
}
nVarPlotValue_sellShort_4_right=GetPlotNumericValue("mayesterday","MA2");
If(InvalidNumeric() == nVarPlotValue_sellShort_4_right)
{
Return False;
}
Return nVarPlotValue_sellShort_4_left <= nVarPlotValue_sellShort_4_right;
}
Bool time_condition_SellShort_2()
{
Return Cond_LocalTimeLimit(0, 20220126.095558);
}
Bool sell_condition_1()
{
Return MarketPosition() > 0.000000;
}
Bool sell_condition_2()
{
nVarPlotValue_sell_2=GetPlotNumericValue("MACD","MACD");
If(InvalidNumeric() == nVarPlotValue_sell_2)
{
Return False;
}
Return nVarPlotValue_sell_2 < 0.000000;
}
Bool sell_condition_3()
{
nVarPlotValue_sell_3=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_sell_3)
{
Return False;
}
Return Close() < nVarPlotValue_sell_3;
}
Bool sell_condition_4()
{
nVarPlotValue_sell_4_left=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_sell_4_left)
{
Return False;
}
nVarPlotValue_sell_4_right=GetPlotNumericValue("mayesterday","MA2");
If(InvalidNumeric() == nVarPlotValue_sell_4_right)
{
Return False;
}
Return nVarPlotValue_sell_4_left < nVarPlotValue_sell_4_right;
}
Bool time_condition_Sell_3()
{
Return Cond_LocalTimeLimit(0, 20220126.120539);
}
Bool buyToCover_condition_1()
{
Return MarketPosition() < 0.000000;
}
Bool buyToCover_condition_2()
{
nVarPlotValue_buyToCover_2=GetPlotNumericValue("MACD","MACD");
If(InvalidNumeric() == nVarPlotValue_buyToCover_2)
{
Return False;
}
Return nVarPlotValue_buyToCover_2 > 0.000000;
}
Bool buyToCover_condition_3()
{
nVarPlotValue_buyToCover_3=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_buyToCover_3)
{
Return False;
}
Return Close() > nVarPlotValue_buyToCover_3;
}
Bool buyToCover_condition_4()
{
nVarPlotValue_buyToCover_4_left=GetPlotNumericValue("mayesterday","MA1");
If(InvalidNumeric() == nVarPlotValue_buyToCover_4_left)
{
Return False;
}
nVarPlotValue_buyToCover_4_right=GetPlotNumericValue("mayesterday","MA2");
If(InvalidNumeric() == nVarPlotValue_buyToCover_4_right)
{
Return False;
}
Return nVarPlotValue_buyToCover_4_left > nVarPlotValue_buyToCover_4_right;
}
Bool time_condition_BuyToCover_4()
{
Return Cond_LocalTimeLimit(0, 20220126.095625);
}
Events
OnInit()
{
SetConsecEntries(99999999);
If(isRollover)
{
AddDataFlag(Enum_Data_RolloverBackWard());
}
If(isRolloverRealPrice)
{
AddDataFlag(Enum_Data_RolloverRealPrice());
}
If(isAutoSwapPosition)
{
AddDataFlag(Enum_Data_AutoSwapPosition());
}
If(ignoreSwapSiganlCalc)
{
AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());
}
}
OnBar(ArrayRef<Integer> indexs)
{
bVarCondition_buy_1 = buy_condition_1();
bVarCondition_buy_2 = buy_condition_2();
bVarCondition_buy_3 = buy_condition_3();
bVarCondition_buy_4 = buy_condition_4();
dVarPrice_buy_1 = Close();
dVarPrice_buy_1_volume = Cond_round_volume(10.000000,dVarPrice_buy_1);
if(time_condition_Buy_1() and (bVarCondition_buy_1 and bVarCondition_buy_2 and bVarCondition_buy_3 and bVarCondition_buy_4))
{
Buy(dVarPrice_buy_1_volume,dVarPrice_buy_1,iVarSignal_Flag_Buy_1);
}
bVarCondition_sellShort_1 = sellShort_condition_1();
bVarCondition_sellShort_2 = sellShort_condition_2();
bVarCondition_sellShort_3 = sellShort_condition_3();
bVarCondition_sellShort_4 = sellShort_condition_4();
dVarPrice_sellShort_2 = Close();
dVarPrice_sellShort_2_volume = Cond_round_volume(10.000000,dVarPrice_sellShort_2);
if(time_condition_SellShort_2() and (bVarCondition_sellShort_1 and bVarCondition_sellShort_2 and bVarCondition_sellShort_3 and bVarCondition_sellShort_4))
{
SellShort(dVarPrice_sellShort_2_volume,dVarPrice_sellShort_2,iVarSignal_Flag_SellShort_2);
}
bVarCondition_sell_1 = sell_condition_1();
bVarCondition_sell_2 = sell_condition_2();
bVarCondition_sell_3 = sell_condition_3();
bVarCondition_sell_4 = sell_condition_4();
dVarPrice_sell_3 = Close();
dVarPrice_sell_3_volume = Cond_round_volume(10.000000,dVarPrice_sell_3);
if(time_condition_Sell_3() and (bVarCondition_sell_1 and bVarCondition_sell_2 and bVarCondition_sell_3 and bVarCondition_sell_4))
{
Sell(dVarPrice_sell_3_volume,dVarPrice_sell_3,iVarSignal_Flag_Sell_3);
}
bVarCondition_buyToCover_1 = buyToCover_condition_1();
bVarCondition_buyToCover_2 = buyToCover_condition_2();
bVarCondition_buyToCover_3 = buyToCover_condition_3();
bVarCondition_buyToCover_4 = buyToCover_condition_4();
dVarPrice_buyToCover_4 = Close();
dVarPrice_buyToCover_4_volume = Cond_round_volume(10.000000,dVarPrice_buyToCover_4);
if(time_condition_BuyToCover_4() and (bVarCondition_buyToCover_1 and bVarCondition_buyToCover_2 and bVarCondition_buyToCover_3 and bVarCondition_buyToCover_4))
{
BuyToCover(dVarPrice_buyToCover_4_volume,dVarPrice_buyToCover_4,iVarSignal_Flag_BuyToCover_4);
}
}
//------------------------------------------------------------------------
// 编译版本: 2022/01/26 110257
// 版权所有 nickjayblack
// 更改声明 TradeBlazer Software保留对TradeBlazer平台
// 每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
策略编写问题 看置顶帖投稿吧