Update on the code ... in my opinion, the only condition that remains is false on plug 1 so we should "ciclarla" increasing by 1 the value of N2, N3 until the condition of the first candle will be Vera.
a1 or must be true, so if A1 is true while the cilo is skipped and the buffer viusalizza on the chart, or an increase of a candle conditions a1 until A1 will be false after which A1 will become the true cilo s 'stops and the buffer will be displayed in the graph.
The problem so that the code does not generate errors, but nailing the MT4 ... maybe in the while loop I made a few mistakes.
#property version "1.00" #property description "" #include <stdlib.mqh> #include <stderror.mqh> //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 1 #property indicator_color1 Red #property indicator_label1 "Sell" #property indicator_type2 DRAW_ARROW #property indicator_width2 1 #property indicator_color2 Green #property indicator_label2 "Buy" //--- indicator buffers double Buffer1[]; double Buffer2[]; extern string MedieMobili ="Parametri Medie Mobili Lenta/Veloce"; extern int MMLenta = 50; extern int MMVeloce = 5; extern string Prossimity = "Prossimità interna/esterna"; extern double PrInterna = 1; extern double PrEsterna = 1; extern double DistanzaIcone = 1; extern int InizioOra = 07; //time of the day extern int InizioMin = 00; //time of the day extern int FineOra = 21; //time of the day extern int FineMin = 00; //time of the day datetime time_alert; //used when sending alert extern bool Audible_Alerts = true; double myPoint; //initialized in OnInit bool inTimeInterval(datetime t, int TOD_From_Hour, int TOD_From_Min, int TOD_To_Hour, int TOD_To_Min) { string TOD = TimeToString(t, TIME_MINUTES); string TOD_From = StringFormat("%02d", TOD_From_Hour)+":"+StringFormat("%02d", TOD_From_Min); string TOD_To = StringFormat("%02d", TOD_To_Hour)+":"+StringFormat("%02d", TOD_To_Min); return((StringCompare(TOD, TOD_From) >= 0 && StringCompare(TOD, TOD_To) <= 0) || (StringCompare(TOD_From, TOD_To) > 0 && ((StringCompare(TOD, TOD_From) >= 0 && StringCompare(TOD, "23:59") <= 0) || (StringCompare(TOD, "00:00") >= 0 && StringCompare(TOD, TOD_To) <= 0)))); } void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | Base2 @ "+Symbol()+","+Period()+" | "+message); } else if(type == "order") { } else if(type == "modify") { } else if(type == "indicator") { if(Audible_Alerts) Alert(type+" | Base2 @ "+Symbol()+","+Period()+" | "+message); } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(2); SetIndexBuffer(0, Buffer1); SetIndexEmptyValue(0, 0); SetIndexArrow(0, 242); SetIndexBuffer(1, Buffer2); SetIndexEmptyValue(1, 0); SetIndexArrow(1, 241); //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 4 || Digits() == 3) { myPoint *= 10; } 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 limit = rates_total - prev_calculated; //--- counting from 0 to rates_total ArraySetAsSeries(Buffer1, true); ArraySetAsSeries(Buffer2, true); //--- initial zero if(prev_calculated < 1) { ArrayInitialize(Buffer1, 0); ArrayInitialize(Buffer2, 0); } else limit++; //--- main loop for(int i = limit-1; i >= 0; i--) { if (i >= MathMin(5000-1, rates_total-1-50)) continue; int N2 = i+2; int N3 = i+3; bool A= false; bool B= false; double CandleOpen = Open [N2], CandleClose = Close[N2], BodyHigh = fmax( CandleOpen, CandleClose ), BodyLow = fmin( CandleOpen, CandleClose ), GapBuy = MathAbs (BodyHigh - iMA(NULL, PERIOD_CURRENT, MMLenta , 0, MODE_SMA, PRICE_CLOSE, N2)), GapSell = MathAbs (iMA(NULL, PERIOD_CURRENT, MMLenta , 0, MODE_SMA, PRICE_CLOSE, N2) - BodyLow), Sell = MathAbs ( BodyLow - GapSell), Buy = MathAbs ( GapBuy + BodyHigh); // Condizione Sell bool a1= iMA(NULL, PERIOD_CURRENT, MMVeloce, 0, MODE_SMA, PRICE_CLOSE, N3+i) > iMA(NULL, PERIOD_CURRENT, MMLenta, 0, MODE_SMA, PRICE_CLOSE, N3) && iMA(NULL, PERIOD_CURRENT, MMVeloce, 0, MODE_SMA, PRICE_CLOSE, N2+i) < iMA(NULL, PERIOD_CURRENT, MMLenta, 0, MODE_SMA, PRICE_CLOSE, N2); // Condizione Buy bool a2= iMA(NULL, PERIOD_CURRENT, MMVeloce, 0, MODE_SMA, PRICE_CLOSE, N3+i) < iMA(NULL, PERIOD_CURRENT, MMLenta, 0, MODE_SMA, PRICE_CLOSE, N3) && iMA(NULL, PERIOD_CURRENT, MMVeloce, 0, MODE_SMA, PRICE_CLOSE, N2+i) > iMA(NULL, PERIOD_CURRENT, MMLenta, 0, MODE_SMA, PRICE_CLOSE, N2); A= Close[1+i] < Sell; B= Close[1+i] > Buy; //Indicator Buffer 1 Sell if (a1) while ( A==false ) { N2++; N3++;} { Buffer1[i] = High[i] + 1 *myPoint; if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0];} } //Indicator Buffer 2 BUY if (a2) while ( B== false ) { N2++; N3++;} { Buffer2[i] = Low[i] - 1 *myPoint; if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0];} } } return(rates_total); } //+------------------------------------------------------------------+
I can not understand this point!
when a1 / a2 conditions are true look that A / B are true. Perhaps the condition A / B is always false because the shift remains unchanged?
when a1 / a2 conditions are true look that A / B are true. Perhaps the condition A / B is always false because the shift remains unchanged?
I tried adding N1-- in the while loop but the result does not change.
while ( A==false ) { N2++; N3++; N1--;} while ( B== false ) { N2++; N3++; N1--;}
while ( A==false ) { N2++; N3++; N1--;}
You seem to be missing the point.
Where in the loop is there any possibility that A==true
Thank you all for your patience!
I may have the solution under the nose but just do not see it ... after the true condition of a1 / a2, I have to wait for the true condition A1 / A2 .... if A1/A2 is false use the while loop until you find true condition A1 / A2
I also tried to enter only N-- but nothing. I hope I explained!
I may have the solution under the nose but just do not see it ... after the true condition of a1 / a2, I have to wait for the true condition A1 / A2 .... if A1/A2 is false use the while loop until you find true condition A1 / A2
I also tried to enter only N-- but nothing. I hope I explained!
Thank you and I apologize for my lack of experience.
The thing that is not clear is this. having declared this part of the code is correct or not?
bool A= false; while (A==false) { N1--;}
I enter inside the while loop condition A that has to become true to exit the loop and continue with the code.
fly7680: A that has to become true to exit the loop and continue with the code.
| But no where inside that loop do you attempt to change A No change, no exit, infinite loop. |
WHRoeder:
But no where inside that loop do you attempt to change A No change, no exit, infinite loop. |
I have not figured out where I have to include this condition to wait their status ture.
I apologize, but unfortunately I did not understand the while loop. Maybe not good for my purpose?
bool A= false; while (A==false) { N1--;}
- is A==False if not exit loop
- decrement N1.
- is A==False if not exit loop
- decrement N1.
- ...
I thought by entering A == false, the interpreted code this condition until in the candle chart 1 confirmed the condition A, making it true and then the while loop ended.
Maybe I have to insert another condition A that meets my needs?
Maybe I have to insert another condition A that meets my needs?
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
hello to everyone, you can place in the while loop a false condition and when it is true I get out of the loop. I need the while loop but I have to get out of the cycle only when the condition is true.
I have to increase the N2 and N3 values of 1, until the loop condition becomes true
thank you