Please use the SRC button to insert code. I have done it for you this time
-
Play videoPlease edit your post.
For large amounts of code, attach it. -
if(WithAlert==true && lastalert!=Time[0]){ if ( ExtBuffer2[0]){
Where do you check if it is the first change in color? Your code only checks for a new bar and the direction. - How to do your lookbacks correctly.
-
Play videoPlease edit your post.
For large amounts of code, attach it. - Where do you check if it is the first change in color? Your code only checks for a new bar and the direction.
- How to do your lookbacks correctly.
This two doubles print bar in the Histogram style,
double ExtBuffer1[]; double ExtBuffer2[]
When any of those are trigger, by the adx indicator, star printing (display) bar in the under the chart, as long the adx indicator keep the pattern, it keep printing bar, let say in the 1D chart in 5 days was bullish in this case green color bars, in the 6th to 9th day change to bear so start printing red 4 times,
so in 9 days I have 9 bars, 5 green and 4 red, but my alarm sound 9 times, I just want 2 times in the first bar either red or green in this case in the first day (bull) and in the 6th ( bear)
Thank you for your help.
Asked and answered (#2)
the code is like that, like the #2 and still sound every single bar even if I set a line instead Histogram, it sound in every new tick, of course become more long the line, is there a funtion or operation, to tell to the alarm just when buffers are trigger?
@Torgen, the user WHRoeder is telling you that the code statements "if ( ExtBuffer2[0])" and "if (ExtBuffer1[0])" don't do anything at all. If you want to check for a change you must compare it with something in order for a boolean result to be returned to the "if()" function.
Here is a simplified example of a possible solution to your code:
// Please note that this code is untested and serves only to demonstrate the concept for( i = limit - 1; i >= 0; i-- ) // Always count in reverse if using the old style "start()". { ... ExtBuffer1[i] = ( ADX1 > ADX2 ) ? ADX0 : EMPTY_VALUE; ExtBuffer2[i] = ( ADX1 < ADX2 ) ? ADX0 : EMPTY_VALUE; if( WithAlert && ( lastalert != Time[0] ) ) { if( ExtBuffer2[0] < EMPTY_VALUE ) Alert( "Sell ... " ); if( ExtBuffer1[0] < EMPTY_VALUE ) Alert( "Buy ... " ); } ... }
@Torgen, the user WHRoeder is telling you that the code statements "if ( ExtBuffer2[0])" and "if (ExtBuffer1[0])" don't do anything at all. If you want to check for a change you must compare it with something in order for a boolean result to be returned to the "if()" function.
Here is a simplified example of a possible solution to your code:
//+------------------------------------------------------------------+ //| Advanced_ADX.mq4 | //| Copyright © 2006, Eng. Waddah Attar | //| waddahattar@hotmail.com | //+------------------------------------------------------------------+ //---- #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red //---- extern int ADXPeriod = 13; //---- double ExtBuffer1[]; double ExtBuffer2[]; extern bool WithAlert=true; datetime lastalert=0; int NoOfBars = 2; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0, ExtBuffer1); SetIndexBuffer(1, ExtBuffer2); //---- SetIndexStyle(0, DRAW_HISTOGRAM, 0, 2); SetIndexStyle(1, DRAW_HISTOGRAM, 0, 2); //---- SetIndexEmptyValue(0, EMPTY_VALUE); SetIndexEmptyValue(1, EMPTY_VALUE); //---- IndicatorShortName("Advanced_ADX (" + ADXPeriod + ")"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int i, limit; double ADX0,ADX1,ADX2; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit = Bars - counted_bars; //int = baros , //int baros2; //baros = Bars; int = baros2 = counted_bars 2 ; //---- for(i = 0; i < limit ; i++) { ADX0 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MAIN, i); ADX1 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI, i); ADX2 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, i); //---- if(ADX1 >= ADX2) { ExtBuffer1[i] = ADX0; ExtBuffer2[i] = 0; } else { ExtBuffer1[i] = 0; ExtBuffer2[i] = ADX0; } // ExtBuffer1[i] = counted_bars => 2 ? ADX0 : EMPTY_VALUE; // ExtBuffer2[i] = counted_bars => 2 ? ADX0 : EMPTY_VALUE; if(WithAlert==true && lastalert!=Time[0]) { if ( ExtBuffer2[0] => counted_bars ) { Alert((string)"Sell " +Symbol()+"_"+Period()+" "+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_ASK),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); SendNotification ((string)"Sell " +Symbol()+"_"+Period()+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_BID),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); lastalert=Time[0]; } if (ExtBuffer1[0] > EMPTY_VALUE ) { Alert((string)"Buy " +Symbol()+"_"+Period()+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_BID),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); SendNotification ((string)"Buy " +Symbol()+"_"+Period()+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_BID),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); lastalert=Time[0]; } } } return(0); } //+------------------------------------------------------------------+please help I am novice in this field, when I call alarm doesnt work, and I belive I need to set the empty_value funtion I just need the alarm in the 1st bar of histogram draw.
ExtBuffer2[i]---ExtBuffer1[i]
please help I am novice in this field, when I call alarm doesnt work, and I belive I need to set the empty_value funtion I just need the alarm in the 1st bar of histogram draw.
Did I not just give you sample code to help you fix some things?
Yet, you just posted your new code with none of the suggestions and instead just invented new gibberish instead!
Are you trying to waste our time?
Just in case you you just don't get it, here is your full code with the sections changed and highlighted. Please make an effort and don't waste our time.
Please note, that I did not test the code. I am offering you advice! Not coding it for you. So, compile, test, verify, debug or whatever else you need to do, in order to continue developing your indicator.
#property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red //---- extern int ADXPeriod = 13; //---- double ExtBuffer1[]; double ExtBuffer2[]; extern bool WithAlert=true; datetime lastalert=0; input int bars; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0, ExtBuffer1); SetIndexStyle(0, DRAW_HISTOGRAM, 0, 2); //---- SetIndexBuffer(1, ExtBuffer2); SetIndexStyle(1, DRAW_HISTOGRAM, 0, 2); //---- IndicatorShortName("Advanced_ADX (" + ADXPeriod + ")"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int i, limit; double ADX0,ADX1,ADX2; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit = Bars - counted_bars; //---- for( i = limit - 1; i >= 0; i-- ) // Always count in reverse if using the old style "start()" { ADX0 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MAIN, i); ADX1 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI, i); ADX2 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, i); //---- ExtBuffer1[i] = ( ADX1 > ADX2 ) ? ADX0 : EMPTY_VALUE; // Changes by FMIC ExtBuffer2[i] = ( ADX1 < ADX2 ) ? ADX0 : EMPTY_VALUE; // Changes by FMIC if( WithAlert && ( lastalert!=Time[0] ) ) // Changes by FMIC { if( ExtBuffer2[0] < EMPTY_VALUE ) // Changes by FMIC { Alert((string)"Sell " +Symbol()+"_"+Period()+" "+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_ASK),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); SendNotification ((string)"Sell " +Symbol()+"_"+Period()+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_BID),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); lastalert=Time[0]; } if( ExtBuffer1[0] < EMPTY_VALUE ) // Changes by FMIC { Alert((string)"Buy " +Symbol()+"_"+Period()+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_BID),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); SendNotification ((string)"Buy " +Symbol()+"_"+Period()+ "M "+DoubleToStr(MarketInfo(Symbol(),MODE_BID),Digits)+ " "+TimeToStr(TimeCurrent(),TIME_MINUTES)); lastalert=Time[0]; } } } return(0); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello I been trading just 3 month and is intereted to do it, I learning the lenguage mql4 in my way to create a robot, but I just started it, I need some help I have a Adx indicator which draw in histogram bars under the chart, I set the alarm to it, but it sound in every single bar (histogram) and I just want the alarm in the first red and green bar, by the way there is 2 indicator buffers (red and green color), I been looking the documentation and I belive I can use the countedbar funtion, but I dont know how to set it up yet. here is the code, thank you for your help