Selamat pagi, saya ingin membuat trendline yang aktif bila ada crossover MA dan ada candlestick yang break highest high, titik trendline awal dari last highest high hingga candle yg break, mohon bantuannya.. karena trendline tidak muncul..
// Define two variables that can become true in case of a verified crossover:
bool CrossToBuy = false;
bool CrossToSell = false;
// Define the periods of the two indicators:
int MASlowPeriod = 62;
int MAFastPeriod = 23;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CrossToBuy = false;
CrossToSell = false;
static datetime timeCur; datetime timePre = timeCur; timeCur=Time[0];
bool isNewBar = timeCur != timePre;
if(isNewBar){
// iMA is the function to get the value of a moving average indicator.
double MASlowCurr = iMA(Symbol(), 0, MASlowPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);
double MASlowPrev = iMA(Symbol(), 0, MASlowPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
double MAFastCurr = iMA(Symbol(), 0, MAFastPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);
double MAFastPrev = iMA(Symbol(), 0, MAFastPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
// Compare the values and detect if one of the crossovers has happened.
if ((MASlowPrev > MAFastPrev) && (MAFastCurr > MASlowCurr))
{
CrossToBuy = true;
Comment("BUY Signal");
}
if ((MASlowPrev < MAFastPrev) && (MAFastCurr < MASlowCurr))
{
CrossToSell = true;
Comment("SELL Signal");
}
}
// Find highest high
double highestHigh = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 50, 0));
// Monitor for breakout
bool breakoutDetected = false;
int shift = 1;
while ((CrossToBuy) && !breakoutDetected && shift <= 50) {
if (iHigh(NULL, 0, shift) > highestHigh) {
breakoutDetected = true;
// Draw trendline
ObjectCreate(0, "Trendline", OBJ_TREND, 0, Time[shift], highestHigh, Time[0], iHigh(NULL, 0, 0));
}
shift++;
}
}
//+------------------------------------------------------------------+
// Define two variables that can become true in case of a verified crossover:
bool CrossToBuy = false;
bool CrossToSell = false;
// Define the periods of the two indicators:
int MASlowPeriod = 62;
int MAFastPeriod = 23;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CrossToBuy = false;
CrossToSell = false;
static datetime timeCur; datetime timePre = timeCur; timeCur=Time[0];
bool isNewBar = timeCur != timePre;
if(isNewBar){
// iMA is the function to get the value of a moving average indicator.
double MASlowCurr = iMA(Symbol(), 0, MASlowPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);
double MASlowPrev = iMA(Symbol(), 0, MASlowPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
double MAFastCurr = iMA(Symbol(), 0, MAFastPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);
double MAFastPrev = iMA(Symbol(), 0, MAFastPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
// Compare the values and detect if one of the crossovers has happened.
if ((MASlowPrev > MAFastPrev) && (MAFastCurr > MASlowCurr))
{
CrossToBuy = true;
Comment("BUY Signal");
}
if ((MASlowPrev < MAFastPrev) && (MAFastCurr < MASlowCurr))
{
CrossToSell = true;
Comment("SELL Signal");
}
}
// Find highest high
double highestHigh = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 50, 0));
// Monitor for breakout
bool breakoutDetected = false;
int shift = 1;
while ((CrossToBuy) && !breakoutDetected && shift <= 50) {
if (iHigh(NULL, 0, shift) > highestHigh) {
breakoutDetected = true;
// Draw trendline
ObjectCreate(0, "Trendline", OBJ_TREND, 0, Time[shift], highestHigh, Time[0], iHigh(NULL, 0, 0));
}
shift++;
}
}
//+------------------------------------------------------------------+
Last edited: