Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 252
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
> err=StringToInteger((string)err)
this should go down in the annals ;-)
originally in err you obviously got int from GetLastError(). Convert error code into readable description ErrorDescription(err); provided that #include <stdlib.mqh> is enabled.
but the way it's written is a bummer.
PS/ And don't learn MQL programming. MQL 4 and 5 are target languages for a particular platform.
Can you please tell me if you can write it this way. it does not want to open transactions. maybe the format of the calculated numbers is wrong? or other defects in the code?
double TakeLong(double shp)
{
int CurrentDayRange=0, fiveDayATR=0, take=0;
double TP_ATR=0;
//////Pivot inputs
double P, S1, R1, S2, R2, S3, R3;
double LastHigh, LastLow, x;
int counted_bars = IndicatorCounted();
int limit, i;
shp=iHigh(Symbol(),PERIOD_D1,0);
//---- Pivot indicator calculation
if(counted_bars == 0)
{
x = Period();
if(x > 240)
return(-1);
}
if(counted_bars < 0)
return(-1);
limit = (Bars - counted_bars) - 1;
//----
for(i = limit; i >= 0; i--)
{
if(High[i+1] > LastHigh)
LastHigh = High[i+1];
//----
if(Low[i+1] < LastLow)
LastLow=Low[i+1];
if(TimeDay(Time[i]) != TimeDay(Time[i+1])
{
P = (LastHigh + LastLow + Close[i+1]) / 3;
R1 = (2*P) - LastLow;
S1 = (2*P) - LastHigh;
R2 = P + (LastHigh - LastLow);
S2 = P - (LastHigh - LastLow);
R3 = (2*P) + (LastHigh - (2*LastLow));
S3 = (2*P) - ((2* LastHigh) - LastLow);
LastLow = Open[i];
LastHigh = Open[i];
}
}
////ATR calculation
for (i=1;i<6;i++)
{ if(iHigh(NULL, PERIOD_D1, i)-iLow(NULL, PERIOD_D1, i)>0) FiveDayATR += (iHigh(NULL, PERIOD_D1, i)-iLow(NULL, PERIOD_D1, i));}
FiveDayATR = NormalizeDouble(FiveDayATR/5,Digits());
CurrentDayRange = (iHigh(NULL, PERIOD_D1, i)-iLow(NULL, PERIOD_D1, i));
if(FiveDayATR-CurrentDayRange>0) TP_ATR=Ask+FiveDayATR-CurrentDayRange; else TP_ATR=0;
if (Bid>R1 && TP_ATR==0) take=shp;
else if (Bid<R1 && R1<TP_ATR) take=R1;
else take=TP_ATR;
return(take);
}
The suggested code looks like an indicator. The deals are opened by an Expert Advisor or a script. The OrderSend function call is not allowed in the indicator. The indicator can alarm - insert the Alert function call or sound in the appropriate place
The proposed code is similar to the indicator. The deals are opened by an Expert Advisor or a script. The OrderSend function call is prohibited in the indicator. The indicator may signal - insert the Alert function call or sound in the appropriate place
This is the TP definition code, which sends the result to OrderSend. without this complex algorithm, the trades are sent, but there is no way to send them. I call the function TP = TakeLong(SHP);
There are many ways of debugging - the process of finding an error when it is established that there is one. The first is F5 - start debugging in MetsEditor. 2) use Alerts to trace the execution. 3 and 4) output debugging information to text labels and Comment function. Choose the convenient way and debug this simple function - then you will become a programmer. A program with thousands of lines is considered complex.
Can you please tell me if you can write it that way. it doesn't want to open transactions. maybe the format of the calculated numbers is wrong? or some other defect in the code?
MathAbs( Close1[i] - Open1[i] ) / Point + 1
MathAbs( Close2[i] - Open2[i] ) / Point + 1
In full code it looks like this
double Close1 = iClose(Symbol(), 0, i);
double Open1 = iOpen(Symbol(), 0, i);
double Close2 = iClose(Symbol(), 0, i+1);
double Open2 = iOpen(Symbol(), 0, i+1);
MathAbs( Close1[i] - Open1[i] ) / Point + 1
MathAbs( Close2[i] - Open2[i] ) / Point + 1
if (Close1 < Open1 && Close2 > Open2){
BUY();
}
if (Close1 > Open1 && Close2 < Open2){
SELL();
}
Is it correct? How do I make it work?
Have you tried it on M1 demo account? What do you get?
Have you tried it on an M1 demo account? What's the result?
Can you tell me why the trawl is triggered on every tick?