Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 23

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'm completely confused.
double blevel=OrderStopLoss()<Bid-Point*TS; works for me. SL goes after the price only in profit.
double slevel=OrderStopLoss()>Ask+Point*TS; I do not know how to add this one to else
It's not a bool.
Not a bool, but it's called implicit conversion
What are you doing anyway? Trawl?
Not a bool, but it's called an implicit conversion
What are you doing anyway? Trawl?
Yes tried to make a trawl. the original script was just to close when the profit on the order was reached
Yes, I tried to make a trawl. the original scrip was just to close it when it reached profit on an order
Logic:
If the profit of the current order selected in the loop is greater than the set value, if its stoploss is less (for Buy)/more (for Sell) than the calculated stoploss trawl level, then shift the stop to the new value.
This is in a nutshell.
Isn't that what I suggested?
Yeah, well... I looked at your code so inattentively, it's better to say I didn't look at it at all. But that's half the trouble, then I've said such rubbish that I'm almost ashamed of. For some reason I suddenly had this crazy idea that ArrayMaximum() might be applied to an array of structures or even to a separate field of this array.
I repent, I do not advise anyone else to think so, it does not work...:)
Yeah, well... I looked at your code so inattentively, it's better to say I didn't look at it at all. But that's half the trouble, then I've said such rubbish that I'm almost ashamed of. For some reason I suddenly had this crazy idea that ArrayMaximum() could be applied to an array of structures or even a separate field of this array.
I repent, I do not advise anyone else to think so, it does not work...:)
Well... And what about me? I looked through your code in the same way and thanked you - because it's really shorter...
In short - both worth a joke...
Not a script, an Expert Advisor. You are confusing the types of programs. The script is executed once after it is loaded on the chart and then deleted. If it is not looped. Hardly anyone will make a looped script to close positions.
according to the author:
Here is a slightly modified standard MT4 close.mq4 scriptPut the file in the MetaTrader\experts\Scripts folder,
Well... And me? Just as I glanced at your code, I bowed in gratitude - it's really shorter...
In short - both worth a joke...
No, I don't agree. This code
CopyOpen(_Symbol, PERIOD_CURRENT, 1, 15, openCandle);
CopyClose(_Symbol, PERIOD_CURRENT, 1, 15, closeCandle);
double maxCandle = fmax(openCandle[ArrayMaximum(openCandle)], closeCandle[ArrayMaximum(closeCandle)]);
double minCandle = fmin(openCandle[ArrayMinimum(openCandle)], closeCandle[ArrayMinimum(closeCandle)]);
tested and works. There are simple user-defined double arrays, and CopyRates() fills an array of structures and therefore you can't choose maximum and minimum by using functions of working with arrays.
according to the author:
Here is a slightly modified standard MT4 close.mq4 scriptPut the file in MetaTrader\experts\Scripts folder,
So his script works only once - I put it on the chart, the script worked(closed positions) and unloaded.
You don't need a script, you need an EA.
Nope, I disagree. This code
CopyOpen(_Symbol, PERIOD_CURRENT, 1, 15, openCandle);
CopyClose(_Symbol, PERIOD_CURRENT, 1, 15, closeCandle);
double maxCandle = fmax(openCandle[ArrayMaximum(openCandle)], closeCandle[ArrayMaximum(closeCandle)]);
double minCandle = fmin(openCandle[ArrayMinimum(openCandle)], closeCandle[ArrayMinimum(closeCandle)]);
is tested and works. Here are simple custom double arrays, and CopyRates() fills an array of structures and therefore you can't select max and min using array functions.
Well, I'm telling you - I was watching your code super attentively too. So - the joke's about me.
SZY... But my code returns four values: High/Low/Highest/Lowest, yours returns only High and Low, and my code checks success of data copying (though not all of them), yours doesn't...
That's how my code checks for complete copying of required data:
//| sFindRangeByCandlesBody.mq4 |
//| Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//| https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link "https://login.mql5.com/ru/users/artmedia70"
#property version "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input int Begin=1; // Бар начала диапазона поиска
input int RangeBars=20; // Диапазон поиска
//---
int bars=Bars(Symbol(),PERIOD_CURRENT);
int begin=(Begin<0?0:Begin>bars-3?bars-3:Begin);
int rangeBars=(RangeBars<2?2:
RangeBars>bars-begin?bars-begin:
RangeBars); // Диапазон поиска
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
MqlRates array[];
double high=0, low=0;
int highest=-1, lowest=-1;
if(CopyRates(Symbol(),PERIOD_CURRENT,begin,rangeBars,array)==rangeBars) {
ArraySetAsSeries(array,true);
high=GetHighestValue(begin,array,highest);
low=GetLowestValue(begin,array,lowest);
}
Print("High=",DoubleToString(high,Digits()),", Highest=",highest,", Low=",DoubleToString(low,Digits()),", Lowest=",lowest);
}
//+------------------------------------------------------------------+
double GetHighestValue(int bar_begin, MqlRates &array[], int &bar_highest){
int sz=ArraySize(array);
if(sz==0) return(-1);
double high=DBL_MIN;
bar_highest=-1;
for(int i=0; i<sz; i++) {
double value=fmax(array[i].open,array[i].close);
if(value>high) {
high=value;
bar_highest=bar_begin+i;
}
}
return(high);
}
//+------------------------------------------------------------------+
double GetLowestValue(int bar_begin, MqlRates &array[], int &bar_lowest){
int sz=ArraySize(array);
if(sz==0) return(-1);
double low=DBL_MAX;
bar_lowest=-1;
for(int i=0; i<sz; i++) {
double value=fmin(array[i].open,array[i].close);
if(value<low) {
low=value;
bar_lowest=bar_begin+i;
}
}
return(low);
}
//+------------------------------------------------------------------+