计算具体发生金叉死叉位置得价格
大佬们好! 我在听计算跨周期课程中,刘风老师曾经用大周期(15分钟)双均线金叉死叉结合小周期(5分钟)的价格计算得出真正发生金叉(或死叉)的价格位,而非笼统的开盘价、收盘价。老师我想请问,我想套用在macd指标中,我想计算出当金叉MACDDIFF > MACDDIFF[1](或者死叉MACDDIFF < MACDDIFF[1])时候,通过计算得出发生转变的具体价格,但我不知如何计算,请指教 Params //此处添加参数 Numeric length1(5); Numeric length2(10); Numeric lots(0); Vars //此处添加变量 Numeric ma5; Numeric ma10; Array<Numeric> myarray1; Array<Numeric> myarray2; Numeric result; bool boollong; bool boolshort; Numeric price; Events //此处实现事件函数 //初始化事件函数,策略运行期间,首先运行且只有一次 OnInit() { //SubscribeBar(data0.Symbol,"5m",data0.BeginDateTime); SubscribeBar(data0.Symbol,"15m",data0.BeginDateTime); //SubscribeBar(data0.Symbol,"30m",data0.BeginDateTime); } //Bar更新事件函数,参数indexs表示变化的数据源图层ID数组 OnBar(ArrayRef<Integer> indexs) { Range[ 1 : DataSourceSize -1] { ma5 = Average(close,length1); ma10 = Average(Close,length2); PlotNumeric("ma5",ma5); PlotNumeric("ma10",ma10); } data1.seriestoarray(data1.close,length1,data0.myarray1); data1.seriestoarray(data1.close,length2,data0.myarray2); /*Numeric i; for i = 0 to GetArraySize(myarray) -1 { Commentary("myarray[" + text(i)+ "]" +Text(myarray[i])); }*/ If(data1.ma5 > data1.ma10) { data0.myarray1[0] = l; data0.myarray2[0] = l; } If(data1.ma5 < data1.ma10) { data0.myarray1[0] = h; data0.myarray2[0] = h; } ma5 = AverageArray(myarray1); ma10 = AverageArray(myarray2); PlotNumeric("ma5",ma5); PlotNumeric("ma10",ma10); boollong = CrossOver(data0.ma5,data0.ma10); boolshort = CrossUnder(data0.ma5,data0.ma10); //SummationArray(myarray2) - myarray2[0] + price = 2*( SummationArray(myarray1) -myarray1[0] + price) price = SummationArray(myarray2) - myarray2[0] - 2*( SummationArray(myarray1) -myarray1[0] ); If( MarketPosition <> 1 and boollong) { Buy(lots,price); } If( MarketPosition <> -1 and boolshort) { SellShort(lots,price); } 这是老师在视频课堂上的原文代码,我很想了解到套用在macd的公式,但我不知计算如何得出计算公式 Numeric FastLength(12); Numeric SlowLength(26); 就是下面的这条计算公式: MACDDiff = XAverage(Close, FastLength ) - XAverage(Close, SlowLength ) ; 下面是我按照理解写的内容: seriestoarray(close,FastLength,myarray1); seriestoarray(Close,SlowLength,myarray2); If(MACDDiff > MACDDiff[1]) //金叉等死叉的状态 { myarray1[0] = low; myarray2[0] = low; } If(MACDDiff < MACDDiff[1]) //死叉等金叉的状态 { myarray1[0] = high; myarray2[0] = high; } //13* SummationArray(myarray1) - 6* SummationArray(myarray2) = 13 * (SummationArray(myarray1)-myarray1 但我还是不知对不对,希望有老师指点一下