SanMiguel:
But not for the first hour of the day (from midnight), since u keep reseting the variable 'DailyAlert' during that hour:[...] shouldn't they turn off after 1 alert?
int start() { if (Hour() == 0 && DailyAlert == 1) { int DailyAlert = 0; } //...
gordon:
But not for the first hour of the day (from midnight), since u keep resting the variable 'DailyAlert' during that hour:
But not for the first hour of the day (from midnight), since u keep resting the variable 'DailyAlert' during that hour:
But it's not midnight now and the alarm keeps sounding.
I agree that the code at midnight can be redone...
try this;
int start() { if (Hour() == 0 && DailyAlert == 1) { DailyAlert = 0; // ---- Here no initiation of an int... }
Enotrek
if (Hour() == 0 && DailyAlert == 1) { int DailyAlert = 0; }Each tick at the start of Start() DailyAlert is zero so the above code does nothing and the alarm always sounds. Make it static so the value is kept between ticks. Furthermore you can't use Hour() since you want to reset it once per day not every tick in hour zero.
static datetime DailyAlert; if (varBiasDirection == -1 && (Bid > varHigh) && TimeCurrent() > DailyAlert) { Alert(Symbol() + " Daily LWMA"); DailyAlert = TimeCurrent() + 24*60*60; }or
static int DailyAlert; if (varBiasDirection == -1 && (Bid > varHigh) && TimeDay(TimeCurrent()) != DailyAlert) { Alert(Symbol() + " Daily LWMA"); DailyAlert = TimeDay(TimeCurrent()); }
SanMiguel:
//| Daily 2LWMAs TP SL Diff.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net//"
I think I've set the flags properly but the alarms keep sounding, shouldn't they turn off after 1 alert?
//| Daily 2LWMAs TP SL Diff.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net//"
#property indicator_chart_window
string SonSinyal="";
int scaleX=5,
scaleY=5,
offsetX=0,
offsetY=0,
fontSize=10,
corner=2,
symbolCodeBuy=233, // a symbol code for a buy signal
symbolCodeSell=234, // sell signal
symbolCodeNoSignal=183; // no signal
extern color signalBuyColor=Green, // color of the symbol of a buy signal
signalSellColor=Red, // for a sell signal
noSignalColor=Gray, // no signal
textColor=Black; // color of all writings
ObjectCreate("highLWMA",OBJ_HLINE,0,0,0);
ObjectCreate("lowLWMA",OBJ_HLINE,0,0,0);
double varBiasDirection = 0;
int DailyAlert = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
string SonSinyal="";
int scaleX=5,
scaleY=5,
offsetX=0,
offsetY=0,
fontSize=10,
corner=2,
symbolCodeBuy=233, // a symbol code for a buy signal
symbolCodeSell=234, // sell signal
symbolCodeNoSignal=183; // no signal
extern color signalBuyColor=Green, // color of the symbol of a buy signal
signalSellColor=Red, // for a sell signal
noSignalColor=Gray, // no signal
textColor=Black; // color of all writings
ObjectCreate("highLWMA",OBJ_HLINE,0,0,0);
ObjectCreate("lowLWMA",OBJ_HLINE,0,0,0);
double varBiasDirection = 0;
int DailyAlert = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (Hour() == 0 && DailyAlert == 1) {
int DailyAlert = 0;
}
double varHigh = iMA(NULL, PERIOD_D1, 2, 0, MODE_LWMA, PRICE_HIGH, 0);
double varLow = iMA(NULL, PERIOD_D1, 2, 0, MODE_LWMA, PRICE_LOW, 0);
double HAvalHigh=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,0,0); //high ExtMapBuffer1
double HAvalLow=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,1,0); //low ExtMapBuffer2
double HAvalOpen=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,2,1);
double HAvalClose=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,3,1);
if (HAvalOpen<HAvalClose) varBiasDirection = 1;
if (HAvalOpen>HAvalClose) varBiasDirection = -1; //bearish
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (Hour() == 0 && DailyAlert == 1) {
int DailyAlert = 0;
}
double varHigh = iMA(NULL, PERIOD_D1, 2, 0, MODE_LWMA, PRICE_HIGH, 0);
double varLow = iMA(NULL, PERIOD_D1, 2, 0, MODE_LWMA, PRICE_LOW, 0);
double HAvalHigh=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,0,0); //high ExtMapBuffer1
double HAvalLow=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,1,0); //low ExtMapBuffer2
double HAvalOpen=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,2,1);
double HAvalClose=iCustom(NULL, PERIOD_D1, "Heiken Ashi",Red,Blue,Red,Blue,3,1);
if (HAvalOpen<HAvalClose) varBiasDirection = 1;
if (HAvalOpen>HAvalClose) varBiasDirection = -1; //bearish
ObjectSet("highLWMA",OBJPROP_COLOR,LimeGreen);
ObjectSet("lowLWMA",OBJPROP_COLOR,LimeGreen);
ObjectSet("highLWMA",OBJ_HLINE,varHigh);
ObjectSet("lowLWMA",OBJ_HLINE,varLow);
ObjectCreate("signal",OBJ_LABEL,0,0,0,0,0);
ObjectSet("signal",OBJPROP_CORNER,corner);
ObjectSet("signal",OBJPROP_XDISTANCE,scaleX+offsetX);
ObjectSet("signal",OBJPROP_YDISTANCE,scaleY+offsetY);
ObjectSetText("signal",CharToStr(symbolCodeNoSignal),fontSize,"Wingdings",noSignalColor);
//1 = up
//0 = neutral
//-1 = down
if (varBiasDirection == 1) {
ObjectSetText("signal",CharToStr(symbolCodeBuy),fontSize,"Wingdings",signalBuyColor);
}
if (varBiasDirection == 0) {
ObjectSetText("signal",CharToStr(symbolCodeNoSignal),fontSize,"Wingdings",noSignalColor);
}
if (varBiasDirection == -1) {
ObjectSetText("signal",CharToStr(symbolCodeSell),fontSize,"Wingdings",signalSellColor);
}
double varavHigh = 9999; //prevent divide by zero
double varavLow = 9999;
if (varBiasDirection == 1 && (Bid < varLow) && SonSinyal!="LOW") {
Alert(Symbol() + " Daily LWMA");
SonSinyal="LOW";
DailyAlert = 1;
}
if (varBiasDirection == -1 && (Bid > varHigh) && SonSinyal!="HIGH") {
Alert(Symbol() + " Daily LWMA");
SonSinyal="HIGH";
DailyAlert = 1;
}
ObjectSet("lowLWMA",OBJPROP_COLOR,LimeGreen);
ObjectSet("highLWMA",OBJ_HLINE,varHigh);
ObjectSet("lowLWMA",OBJ_HLINE,varLow);
ObjectCreate("signal",OBJ_LABEL,0,0,0,0,0);
ObjectSet("signal",OBJPROP_CORNER,corner);
ObjectSet("signal",OBJPROP_XDISTANCE,scaleX+offsetX);
ObjectSet("signal",OBJPROP_YDISTANCE,scaleY+offsetY);
ObjectSetText("signal",CharToStr(symbolCodeNoSignal),fontSize,"Wingdings",noSignalColor);
//1 = up
//0 = neutral
//-1 = down
if (varBiasDirection == 1) {
ObjectSetText("signal",CharToStr(symbolCodeBuy),fontSize,"Wingdings",signalBuyColor);
}
if (varBiasDirection == 0) {
ObjectSetText("signal",CharToStr(symbolCodeNoSignal),fontSize,"Wingdings",noSignalColor);
}
if (varBiasDirection == -1) {
ObjectSetText("signal",CharToStr(symbolCodeSell),fontSize,"Wingdings",signalSellColor);
}
double varavHigh = 9999; //prevent divide by zero
double varavLow = 9999;
if (varBiasDirection == 1 && (Bid < varLow) && SonSinyal!="LOW") {
Alert(Symbol() + " Daily LWMA");
SonSinyal="LOW";
DailyAlert = 1;
}
if (varBiasDirection == -1 && (Bid > varHigh) && SonSinyal!="HIGH") {
Alert(Symbol() + " Daily LWMA");
SonSinyal="HIGH";
DailyAlert = 1;
}
//if (DailyAlert == 0) string strAlert = "Not yet!";
//if (DailyAlert == 1) strAlert = "PA alarm has been triggered";
/*{
//if (DailyAlert == 1) strAlert = "PA alarm has been triggered";
/*{
Comment (
"Difference: " + DoubleToStr(varHigh - varLow, 5) +
"\nHA Range: " + DoubleToStr(HAvalLow, 5) + " - " + DoubleToStr(HAvalHigh, 5) +
"\nHigh: " + DoubleToStr(varHigh, 5) +
"\nLow: " + DoubleToStr(varLow, 5) +
"\nSL/TP: " + DoubleToStr((varHigh - varLow)/2, 5) +
"\nAccount trade size: " + DoubleToStr(AccountBalance()*0.0001, 2) +
"\nLot size: " + DoubleToStr((AccountBalance()*0.0001)/(MarketInfo(Symbol(), MODE_TICKVALUE)),5) +
"\nDaily Alert: " + strAlert
);
"Difference: " + DoubleToStr(varHigh - varLow, 5) +
"\nHA Range: " + DoubleToStr(HAvalLow, 5) + " - " + DoubleToStr(HAvalHigh, 5) +
"\nHigh: " + DoubleToStr(varHigh, 5) +
"\nLow: " + DoubleToStr(varLow, 5) +
"\nSL/TP: " + DoubleToStr((varHigh - varLow)/2, 5) +
"\nAccount trade size: " + DoubleToStr(AccountBalance()*0.0001, 2) +
"\nLot size: " + DoubleToStr((AccountBalance()*0.0001)/(MarketInfo(Symbol(), MODE_TICKVALUE)),5) +
"\nDaily Alert: " + strAlert
);
*/
//----
return(0);
}
//+------------------------------------------------------------------+
//----
return(0);
}
//+------------------------------------------------------------------+
Mehmet:
Please use the SRC button (and not the 'Quotation' style) for code. You can also use the SRC button inside a 'Quotation' block if you want to.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I think I've set the flags properly but the alarms keep sounding, shouldn't they turn off after 1 alert?