Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1941
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 all!
Please advise what should be added to the code to shift the MA not only forward (positive value) but also backward (negative value)
Here is the code from the Expert Advisor:
hello all!
Please advise what should be added to the code to shift the MA not only forward (positive value) but also backward (negative value)
Here is the code from the Expert Advisor:
Add to the shift the desired negative value, but the value + shift should not be less than zero.
Add the desired negative value to the shift, but make sure the value + shift is at least zero.
Thanks, I'll give it a try.
Good afternoon.
Help with the code, maybe there are examples.
Task:
There are several open orders, with different lots, in different directions. One of them is buried with profit, let us assume 20. However, there is an open order with the negative profit, let us assume -55 with 0.05 lots. I want to close a part of a negative order by the amount of the profit of a positively closed order to decrease the drawdown.
I have tried to write this using the while operator, but it did not go well.
Thank you in advance.
Hello, this code is from Fedoseev's book. Why is the indicator not drawn in the window, the log says that it is running, no errors during compilation, an additional window opens (empty), this code is from the book, with mine is exactly the same result. What is wrong?
//+------------------------------------------------------------------+
//| 015 Symbol.mq5 |
//+------------------------------------------------------------------+
#property copyright "Dmitry Fedoseev"
#property link "mailto:for-good-letter@yandex.ru"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 1
//--- plot bar
#property indicator_label1 "bar"
#property indicator_type1 DRAW_CANDLES
#property indicator_color1 clrGray,clrBlue,clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input string symbol="";
input bool drawBars=false;
string sym;
//--- indicator buffers
double barBuffer1[];
double barBuffer2[];
double barBuffer3[];
double barBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit()
{
sym=symbol;
StringTrimLeft(sym);
StringTrimRight(sym);
if(sym==""){
sym=Symbol();
}
if(!SymbolSelect(sym,true)){
Alert("Unknown symbol ",sym);
return(INIT_FAILED);
}
if(drawBars){
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_BARS);
}
else{
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_CANDLES);
}
//--- indicator buffers mapping
SetIndexBuffer(0,barBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,barBuffer2,INDICATOR_DATA);
SetIndexBuffer(2,barBuffer3,INDICATOR_DATA);
SetIndexBuffer(3,barBuffer4,INDICATOR_DATA);
//---
return(INIT_SUCCEEDED);
}
void OnDeinit(const int r){
Comment(");
EventKillTimer();
}
//+------------------------------------------------------------------+
//| 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 bars=Bars(sym,Period());
if(bars==0){
Comment("Forming timeframe ",sym,"...");
EventSetTimer(1);
return(0);
}
int start;
if(prev_calculated==0){
Comment(");
EventKillTimer();
datetime tm[1];
if(CopyTime(sym,Period(),bars-1,1,tm)==-1){
return(0);
}
start=0;
for(;start<rates_total;start++){
if(time[start]>=tm[0]){
break;
}
}
}
else{
start=prev_calculated-1;
}
MqlRates r[1];
for(int i=start;i<rates_total;i++){
if(CopyRates(sym,Period(),time[i],1,r)==-1){
return(0);
}
barBuffer1[i]=r[0].open;
barBuffer2[i]=r[0].high;
barBuffer3[i]=r[0].low;
barBuffer4[i]=r[0].close;
}
return(rates_total);
}
void OnTimer()
{
ChartSetSymbolPeriod(0,Symbol(),Period());
}
//+------------------------------------------------------------------+
Hello, this code is from Fedoseev's book. Why is the indicator not drawn in the window, the log says that it is running, no errors during compilation, an additional window opens (empty), this code is from the book, with mine is exactly the same result. What is wrong?
Alt s paste the code.
And when you cast the inductor do you enter the tool?
Alt s to insert the code.
And when you cast the inductor, do you enter the tool?
Hi, I have a problem, I have placed an indicator, but when I load the demo it goes to the EA section. What is the problem?
Before displaying products,you should read the rules of the marketplace.
Before displaying products,you should read the market rules.
I have read, only the indicator is set up as an indicator. But when I download the demo it appears in EAs