[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 295

 
isCloseLastPosByStop - Returns the flag to close the last position by stop
isCloseLastPosByTake - Returns the flag to close the last position by take profit.
 

Help fix, standard stockistik, added an alert that doesn't work correctly, can't figure out where the error is....

Thanks

//+------------------------------------------------------------------+
//|                                                   Stochastic.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property  indicator_width1 1
#property  indicator_width2 1
#property indicator_level1 20
#property indicator_level2 50
#property indicator_level3 80
#property indicator_levelcolor DimGray
//---- input parameters
//+------------------------------------------------------------------+
extern bool Alerts  = true;
//+------------------------------------------------------------------+
extern int AlertBar = 1; 
//+------------------------------------------------------------------+
extern int KPeriod  = 5;
//+------------------------------------------------------------------+
extern int DPeriod  = 2;
//+------------------------------------------------------------------+
extern int Slowing  = 3;
//+------------------------------------------------------------------+
extern int MAMethod = 3; // 0=SMA,1=EMA,2=SSMA,3=LWMA
//+------------------------------------------------------------------+
//-------------------------------------------------------------------+
//-----
datetime LastAlertTime = -333;
//---- Buffers
double MainBuffer[];
double SignalBuffer[];
double HighesBuffer[];
double LowesBuffer[];
//----
int    MAMode;
string strMAType;
//----
int draw_begin1=0;
int draw_begin2=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  string short_name;
//---- 2 additional buffers are used for counting.
  IndicatorBuffers(4);
//---- indicator lines
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(0,MainBuffer);
  SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(1,SignalBuffer);
//----
  SetIndexBuffer(2,HighesBuffer);
  SetIndexBuffer(3,LowesBuffer);
//----
  switch(MAMethod)
  {
    case 1:  strMAType="EMA";  MAMode=MODE_EMA;  break;
    case 2:  strMAType="SMMA"; MAMode=MODE_SMMA; break;
    case 3:  strMAType="LWMA"; MAMode=MODE_LWMA; break;
    default: strMAType="SMA";  MAMode=MODE_SMA;  break;
  }
//---- name for DataWindow and indicator subwindow label
  short_name="Stochastic ("+KPeriod+","+DPeriod+","+Slowing+","+strMAType+")";
  IndicatorShortName(short_name);
  SetIndexLabel(0,short_name);
  SetIndexLabel(1,"Signal");
//----
  draw_begin1=KPeriod+Slowing;
  draw_begin2=draw_begin1+DPeriod;
  SetIndexDrawBegin(0,draw_begin1);
  SetIndexDrawBegin(1,draw_begin2);
//----
  return(0);
}
//+------------------------------------------------------------------+
//| Stochastic oscillator                                            |
//+------------------------------------------------------------------+
int start()
{
  int i,k;
  int counted_bars=IndicatorCounted();
  double price;
//----
  if(Bars<=draw_begin2) return(0);
//---- initial zero
  if(counted_bars<1)
  {
    for(i=1;i<=draw_begin1;i++) MainBuffer[Bars-i]=0;
    for(i=1;i<=draw_begin2;i++) SignalBuffer[Bars-i]=0;
  }
//---- minimums counting
  i=Bars-KPeriod;
  if(counted_bars>KPeriod) i=Bars-counted_bars-1;
  while(i>=0)
  {
    double min=1000000;
    k=i+KPeriod-1;
    while(k>=i)
    {
      price=Low[k];
      if(min>price) min=price;
      k--;
    }
    LowesBuffer[i]=min;
    i--;
  }
//---- maximums counting
  i=Bars-KPeriod;
  if(counted_bars>KPeriod) i=Bars-counted_bars-1;
  while(i>=0)
  {
    double max=-1000000;
    k=i+KPeriod-1;
    while(k>=i)
    {
      price=High[k];
      if(max<price) max=price;
      k--;
    }
    HighesBuffer[i]=max;
    i--;
  }
//---- %K line
  i=Bars-draw_begin1;
  if(counted_bars>draw_begin1) i=Bars-counted_bars-1;
  while(i>=0)
  {
    double sumlow=0.0;
    double sumhigh=0.0;
    for(k=(i+Slowing-1);k>=i;k--)
    {
      sumlow+=Close[k]-LowesBuffer[k];
      sumhigh+=HighesBuffer[k]-LowesBuffer[k];
    }
    if(sumhigh==0.0) MainBuffer[i]=100.0;
    else MainBuffer[i]=sumlow/sumhigh*100;
    i--;
  }
//---- last counted bar will be recounted
  if(counted_bars>0) counted_bars--;
  int limit=Bars-counted_bars;
//---- signal line is simple movimg average
  for(i=0; i<limit; i++)
  SignalBuffer[i]=iMAOnArray(MainBuffer,Bars,DPeriod,0,MAMethod,i);
//+------------------------------------------------------------------+ 
  if(Alerts)
  {
    if(AlertBar >= 0 && Time[0] > LastAlertTime)
    {
      if(MainBuffer[i+AlertBar] > SignalBuffer[i+AlertBar] && MainBuffer[i+AlertBar+1] <= SignalBuffer[i+AlertBar+1])
      {
        Alert("Stochastic BULL! ",Symbol()," TF: ",Period());
      }
      if(MainBuffer[i+AlertBar] < SignalBuffer[i+AlertBar] && MainBuffer[i+AlertBar+1] >= SignalBuffer[i+AlertBar+1])
      { 
        Alert("Stochastic BEAR! ",Symbol()," TF: ",Period());
      }
    }
    LastAlertTime = Time[0];
  }
//----
  return(0);
}
//+------------------------------------------------------------------+
 

I want to make a multi MA. I.e. 2 MAs should be visible on the chart - one for the current instrument, the other for the second instrument:

There is a question of binding them to each other, because volatility and multiplicity of points of each instrument is different. I can't think of anything useful.... Help! :)

 
Cmu4:

I want to make a multi MA. I.e. 2 MAs should be visible on the chart - one for the current instrument, the other for the second instrument:

There is a question of binding them to each other, because volatility and multiplicity of points of each instrument is different. I can't think of anything useful.... Help! :)

With the subwindow I hope it does not cause problems.

It depends on the task, you can take a MA with a large period on both charts and take it as the basis.

For example, the working MA has a period of 12. For the main symbol we draw it as it is.

For other symbols, we find the difference between the MA 12 and 60; this difference multiplied by the coefficient should be added to the MA 60 of the main symbol.

 
artmedia70:

And to clarify? Should the first position be selected from those that are open (in the market) or those that are already closed? What if the first position was opened three years ago? Does it need to be selected?

And what is it all for?

To choose the first one out of the open positions.

It is necessary to check the distance in pips between the first open position and the last open position.

 
forexnew:
Tried using the IsConnected() - no effect. Any advice?

Maybe see what else returns IsTradeAllowed() ?

Please help. I am trying to build a trend according to two points attached to the bars for N bars ahead from the last point. I.e. incoming - time-price of the first and second point, and N expressed in number of bars ahead (checkbox beam = false). If the second point, assume, lies on bar 1 from the current bar 0, and I have to draw from it 10 bars ahead, how can I calculate the time and price of the bar from the future?

 

Please help.

How do I find out the time High[3]?

 
alex11230:

Please help.

How do I find out the time High[3]?


Time[3]
 
Roll:

Try it:
Thank you :)
 

How to portray:

/

in string?

For example:

string path=TerminalPath()+"/logs/"+tekTime+".log";

gives an error, and if you remove the slash "/"

string path=TerminalPath()+"logs "+tekTime+".log";

- no error.