Questions from Beginners MQL5 MT5 MetaTrader 5 - page 169

 
sandex:

Declare the array to be static, of size 1:

One line appears after compilation, which is the same as in this and last version. Here is the whole code:

#property copyright ""
#property link      ""
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrMediumVioletRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_label1  ""
#property  indicator_type2   DRAW_LINE
#property  indicator_color2  clrRed
#property  indicator_style2  STYLE_SOLID
#property  indicator_label2  "Sell TP"
input int Period_ = 34;         //Период
int ma1Handle;
double ma1Val[1];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
SetIndexBuffer(0,ExtMapBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,ExtMapBuffer2,INDICATOR_DATA);
ma1Handle=iMA(_Symbol,_Period,Period_,0,MODE_EMA,PRICE_CLOSE); 
   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[])
  {
ArraySetAsSeries(ma1Val,true);
int bars=Bars(_Symbol,_Period);
for(int i=0;i<bars;i++)
    {
    CopyBuffer(ma1Handle,0,i,1,ma1Val);
    ExtMapBuffer2[i]=ma1Val[0] - ((ma1Val[0]/100)*0.3);//ЗДЕСЬ НЕ ПОЛУЧАЕТСЯ ПОЛУЧИТЬ ЛИНИЮ
    }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Working code.
Files:
Ind.mq5  3 kb
 

Hello.

I have decided to learn MQL5, I have read articles about how to generate EAs in MetaEditor, everything is clear but how to make indicators that are part of EAs to trade by your rules, for example CCI indicator does not do what I want; how to make a buy order open at crossing 100 and close it at the crossing 100 from upside down; the same for sell. I have also been working on this for a while now and I dont know how to do it.

 
vitan06:

Hello.

I have decided to learn MQL5, I have read articles about how to generate EAs in MetaEditor, everything is clear but how to make indicators that are part of EAs to trade by your rules, for example CCI indicator does not do what I want; how to make a buy order open at crossing 100 and close it at the crossing 100 from upside down; the same for sell. I have also been working on this for a while now and I dont know how to do it.

I have a distracted question. How do you use MQL4?
 
no way
 
sandex:
Working code.
Thank you! It works!!!
 
vitan06:
no way

then safely forget about the code generator.

Open a standard example from the delivery of MA or MACD

Change the indicator to CCI

and go

 

Hello!

Sorry for the, in my opinion, stupid question:

I wrote an EA on mql5, loaded it properly, tested it, tried it on a demo on my home laptop and now the demo is running on VPS.

I uninstalled it from my laptop. Tweaked something on the source on VPS.

Tried to load from VPS to laptop - does not see it MQL5!!! W7 Explorer has it where it should be, but MQL5 has not.

Metaeditor via Open file finds, edits and saves it.

When I try to compile it, the error cannot create interface of MQL compiler in the first line. What is this error?

What do I do?

 

Could you please advise how to get the current price in the indicator code and compare it with another indicator to draw a line?

I get the current price in the Expert Advisor:

MqlTick latest_price;       
double iclose=latest_price.bid;
But how do I get it in the indicator?
 
forexman77:

Could you please advise how to get the current price in the indicator code and compare it with another indicator to draw a line?

In the EA I get the current price as follows:

But how do I get it in the indicator?
Look in the code of indicator, function OnCalculate().