|
我想在图表中有信号的地方显示文字或者箭头都可以,但是图表中一直都没有任何的显示,也没有任何的报错,不知道是哪里的问题 求教大佬帮忙改一下
#property indicator_chart_window
#property copyright "Copyright 2023, Your Name"
#property link "https://www.yourwebsite.com"
//property version "1.00"
//input ENUM_TIMEFRAMES Timeframe = PERIOD_H1;
extern bool ShowBBY = true;
extern bool ShowSSL = true;
extern bool ShowEveningStar = true;
extern bool ShowThreeInsideUp = true;
extern bool ShowThreeInsideDown = true;
extern color BBY_Color = clrRed;
extern color SSL_Color = clrLime;
extern color EveningStar_Color = clrYellow;
extern color ThreeInsideUp_Color = clrBlue;
extern color ThreeInsideDown_Color = clrMagenta;
string BBY_Signal = "BBY";
string SSL_Signal = "SSL";
string EveningStar_Signal = "EveningStar";
string ThreeInsideUp_Signal = "ThreeInsideUp";
string ThreeInsideDown_Signal = "ThreeInsideDown";
double ExtMapBuffer1[];
void DrawSignal(string signal, double price, color signal_color, int shift)
{
int signalObj = ObjectCreate(signal + "_" + TimeToStr(Time[shift], TIME_DATE | TIME_MINUTES), OBJ_TEXT, 0, Time[shift], price);
ObjectSet(signalObj, OBJPROP_CORNER, 2);
ObjectSet(signalObj, OBJPROP_XDISTANCE, 10);
ObjectSet(signalObj, OBJPROP_YDISTANCE, 20);
ObjectSet(signalObj, OBJPROP_COLOR, signal_color);
ObjectSetText(signalObj, "", 0, "Arial", signal_color);
ObjectSetText(signalObj, signal + ": " + DoubleToStr(price, Digits()), 10, "Arial", signal_color);
}
bool isEveningStar(int shift)
{
double firstCandleClose = Close[shift + 2];
double firstCandleOpen = Open[shift + 2];
double secondCandleClose = Close[shift + 1];
double secondCandleOpen = Open[shift + 1];
double thirdCandleClose = Close[shift];
double thirdCandleOpen = Open[shift];
bool firstCandleBullish = firstCandleClose > firstCandleOpen;
bool secondCandleSmallBullish = secondCandleClose > secondCandleOpen && (secondCandleClose - secondCandleOpen) < (secondCandleOpen - secondCandleClose) * 0.5;
bool thirdCandleBearish = thirdCandleClose < thirdCandleOpen;
bool noOverlap = secondCandleClose > firstCandleClose && secondCandleOpen < firstCandleOpen && thirdCandleOpen < secondCandleClose && thirdCandleClose < secondCandleOpen;
return firstCandleBullish && secondCandleSmallBullish && thirdCandleBearish && noOverlap;
}
bool isThreeInsideUp(int shift)
{
double firstCandleClose = Close[shift + 2];
double firstCandleOpen = Open[shift + 2];
double secondCandleClose = Close[shift + 1];
double secondCandleOpen = Open[shift + 1];
double thirdCandleClose = Close[shift];
double thirdCandleOpen = Open[shift];
bool firstCandleBearish = firstCandleClose < firstCandleOpen;
bool secondCandleBearish = secondCandleClose < secondCandleOpen;
bool thirdCandleBullish = thirdCandleClose > thirdCandleOpen;
bool noOverlap = secondCandleClose < firstCandleClose && secondCandleOpen > firstCandleOpen && thirdCandleOpen > secondCandleClose && thirdCandleClose > secondCandleOpen;
bool gap = secondCandleOpen > firstCandleClose && secondCandleOpen < firstCandleOpen && thirdCandleOpen > secondCandleClose && thirdCandleClose > secondCandleOpen;
return firstCandleBearish && secondCandleBearish && thirdCandleBullish && noOverlap && gap;
}
bool isThreeInsideDown(int shift)
{
double firstCandleClose = Close[shift + 2];
double firstCandleOpen = Open[shift + 2];
double secondCandleClose = Close[shift + 1];
double secondCandleOpen = Open[shift + 1];
double thirdCandleClose = Close[shift];
double thirdCandleOpen = Open[shift];
bool firstCandleBullish = firstCandleClose > firstCandleOpen;
bool secondCandleBullish = secondCandleClose > secondCandleOpen;
bool thirdCandleBearish= thirdCandleClose < thirdCandleOpen;
bool noOverlap = secondCandleClose > firstCandleClose && secondCandleOpen < firstCandleOpen && thirdCandleOpen < secondCandleClose && thirdCandleClose < secondCandleOpen;
bool gap = secondCandleOpen < firstCandleClose && secondCandleOpen > firstCandleOpen && thirdCandleOpen < secondCandleClose && thirdCandleClose < secondCandleOpen;
return firstCandleBullish && secondCandleBullish && thirdCandleBearish && noOverlap && gap;
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
IndicatorShortName("ZZS Indicator");
SetIndexBuffer(0, ExtMapBuffer1);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int start = 0;
if(prev_calculated > 0) start = prev_calculated - 1;
for(int i = start; i < rates_total; i++)
{
if(ShowBBY)
{
if (ExtMapBuffer1[i] == 1) //如果有买入信号
{
DrawSignal("BBY", Close[i], BBY_Color, i);
}
}
if(ShowSSL)
{
if (ExtMapBuffer1[i] == -1) //如果有卖出信号
{
DrawSignal("SSL", Close[i], SSL_Color, i);
}
}
if(ShowEveningStar && isEveningStar(i))
{
DrawSignal(EveningStar_Signal, Close[i], EveningStar_Color, i);
}
if(ShowThreeInsideUp && isThreeInsideUp(i))
{
DrawSignal(ThreeInsideUp_Signal, Close[i], ThreeInsideUp_Color, i);
}
if(ShowThreeInsideDown && isThreeInsideDown(i))
{
DrawSignal(ThreeInsideDown_Signal, Close[i], ThreeInsideDown_Color, i);
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
|
|