Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 971

 

Afternoon. I wrote a simple indicator for RSI exit from overbought/oversold zones.

right, draws arrows where it's supposed to. But only in real time.

Question: how to make it draw on history for n number of bars?

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 LimeGreen

double rsi,rsi1,rsi2;
double CrossUp[];
double CrossDown[];
int FLAG = 0;
int FLAG1 = 2;
bool New_Bar=false;
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW,5,1);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW,5,1);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
int start()
{

rsi = iRSI(NULL,0,4,PRICE_CLOSE,0);
rsi1 = iRSI(NULL,0,4,PRICE_CLOSE,1);
rsi2 = iRSI(NULL,0,4,PRICE_CLOSE,2);



Fun_New_Bar();
int limit, i, counter;
double Range, AvgRange;
for(i = 0; i <= limit; i++) {
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
if (FLAG<1 && rsi<rsi2 && rsi2>70 && rsi1<70)
{Alert ("RSI DOWN!!! on ", Symbol());
CrossDown[i] = High[i]+ Range*1.8;
FLAG = 1;}
if(FLAG1>1 && rsi>rsi2 && rsi2<30 && rsi1>30)
{Alert ("RSI UP!!! on ", Symbol());
CrossUp[i] = Low[i]- Range*1.8;
FLAG1 = 1; }
if( New_Bar==true)
{FLAG=0;}
if( New_Bar==true)
{FLAG1=2;}
}
return(0);
}
void Fun_New_Bar()
{
static datetime New_Time=0;
New_Bar=false;
if(New_Time!=Time[0])
{
New_Time=Time[0];
New_Bar=true;
}
}
 
Vinin:
You can't tell anything without the code.
//==================================================================+
extern ENUM_TIMEFRAMES PERIOD_=PERIOD_H1;//Периоды графиков
//==================================================================+

string _ChartSymbol;
long   _ChartID,
       _ChartFirst,
       _ChartPeriod;
int start()
{//---идентификатор графика начиная с первого 
    _ChartFirst=ChartFirst();
if(_ChartFirst>0)//если идентификатор больше ноля
{
 _ChartSymbol=ChartSymbol(_ChartFirst);//символ графика
 _ChartPeriod=ChartPeriod(_ChartFirst);//Периоды графика
 //---выполним функцию конвертации периода если не совпадает
if( _ChartPeriod!=PERIOD_)
 {
  bool  ch=ChartSetSymbolPeriod(_ChartFirst,_ChartSymbol,PERIOD_);
 } 
}
return(0);
}
int  deinit()
{
Alert("скрипт закончил работу");
return(0);
}
This is only for the first graph, I didn't do any further, the pop-up window is in the way.
 
Red_Manticore:

Afternoon. I wrote a simple indicator for RSI exit from overbought/oversold zones.

right, draws arrows where it's supposed to. But only in real time.

Question: how to make it draw on history for n number of bars?


Insert the code according to the rules, get acquainted earlier! Click on the SRC to the left of the video button, and delete the "sheet"!

#property indicator_chart_window
#property indicator_buffers 2
#property  indicator_color1 LimeGreen
#property  indicator_color2 LimeGreen

double rsi,rsi1,rsi2;
double CrossUp[];
double CrossDown[];
int FLAG = 0;
int FLAG1 = 2;
bool New_Bar=false; 
 
int init()
  {
//---- indicators
  SetIndexStyle(0, DRAW_ARROW,5,1);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW,5,1);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
int start()
{  

rsi = iRSI(NULL,0,4,PRICE_CLOSE,0);
rsi1 = iRSI(NULL,0,4,PRICE_CLOSE,1);
rsi2 = iRSI(NULL,0,4,PRICE_CLOSE,2);



Fun_New_Bar(); 
  
   int limit, i, counter;
   double Range, AvgRange;
    for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
      if (FLAG<1 && rsi<rsi2 && rsi2>70 && rsi1<70)
      {Alert ("RSI DOWN!!! on ", Symbol());
      CrossDown[i] = High[i]+ Range*1.8;
          FLAG = 1;} 
      if(FLAG1>1 && rsi>rsi2 && rsi2<30 && rsi1>30)
      {Alert ("RSI UP!!! on ", Symbol());
      CrossUp[i] = Low[i]- Range*1.8;
         FLAG1 = 1; } 
   
       if( New_Bar==true)
       {FLAG=0;}
       if( New_Bar==true)
       {FLAG1=2;} 
   
   }
  return(0);
  } 
  
  void Fun_New_Bar()                              
  {                                             
   static datetime New_Time=0;                  
   New_Bar=false;                               
   if(New_Time!=Time[0])                        
     { 
      New_Time=Time[0];                         
      New_Bar=true;                            
     } 
  }     
ответить
 
korobok777:
This is only for the first chart, I did not do further interferes with the pop-up window.

The script processes all open charts. The current one is processed last. As scripts terminate their work when changing timeframe, the window warning of the script terminating will be popped only once. On all charts, the timeframe will be changed for the specified one

//+------------------------------------------------------------------+
//|                                             ReplaceTimeFrame.mq4 |
//|                                            Copyright 2015, Vinin |
//|                                             http://vinin.ucoz.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Vinin"
#property link      "http://vinin.ucoz.ru"
#property version   "1.00"
#property strict

#property  show_inputs

input ENUM_TIMEFRAMES PERIOD_=PERIOD_H1;//Периоды графиков

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   long id=ChartFirst();
   long id_current=ChartID();
   int i=0;
   while(i<100)
     {
      ENUM_TIMEFRAMES _ChartPeriod=ChartPeriod(id);//Периоды графика
      if(_ChartPeriod!=PERIOD_ && id!=id_current)
        {
         bool  ch=ChartSetSymbolPeriod(id,ChartSymbol(id),PERIOD_);
        }

      id=ChartNext(id);
      if(id<0){break;}
      i++;
     }
   ENUM_TIMEFRAMES _ChartPeriod=ChartPeriod(id_current);//Периоды графика
   if(_ChartPeriod!=PERIOD_)
     {
      bool  ch=ChartSetSymbolPeriod(id_current,ChartSymbol(id_current),PERIOD_);
     }
  }
 
Vinin:

The script processes all open charts. The current one is processed last. As scripts terminate their work when changing timeframe, the window warning of the script terminating will be popped only once. On all charts the timeframe will be changed to the specified one


Ai)))well done!!!!Thank you!!!
 

Good afternoon,

I declare an array

double gdClose_array[];

ArrayResize(gdClose_array, 1);

Copying the data into the array with the last closed bar, from the current chart

iX=CopyClose(Symbol(),PERIOD_CURRENT,1,1,gdClose_array) ;

Output value of the array

double dX=NormalizeDouble(gdClose_array[0],Digits);

Print ("NormalizeDouble(dX,Digits) ", dX);

I get a number but it is obviously incorrect:

NormalizeDouble(dX,Digits) 1.0644.

Although there is no such value in the chart (according to the visualization)

And this value does not change in the course of testing.

I added

ArraySetAsSeries(gdClose_array,true);

situation has not changed.

Where is the error?

 
n0name:

Afternoon,

...

Copying data into an array with closing by the last closed bar, from the current chart

iX=CopyClose(Symbol(),PERIOD_CURRENT,1,1,gdClose_array) ;

Here you have written only the name of the array without specifying the index of the array element. Since you have previously ArrayResize(gdClose_array, 1); you have set the number of array elements as 1, its index is 0. That's why it must be done this way:

iX=CopyClose(Symbol(),PERIOD_CURRENT,1,1,gdClose_array[0]);


And a couple more questions/tips.

1) If you only need to store 1 value, you can use a variable instead of an array. Then instead of:

double gdClose_array[];
ArrayResize(gdClose_array, 1); 

make

double gdClose_array;

and then do the rest like your original code.

2) If you need an array, but know right away that it will only have 1 element, then declare a static array with 1 element instead of declaring a dynamic one and then resizing it. There's no need in extra operations.

Instead of

double gdClose_array[];
ArrayResize(gdClose_array, 1);

write

double gdClose_array[1];

then

iX=CopyClose(Symbol(),PERIOD_CURRENT,1,1,gdClose_array[0]);

and then like your original code.

 

Hi, Question to programmers.

I have an Expert Advisor that is triggered when an order is opened and places a Stop Loss and Take Profit on it according to a specified amount of points.

My question.

Can we change the code so that instead of the Stop Loss, the EA exposes a pending reverse stop order of the same size.

What should I change in the code for that?

Thank you.

 

Good afternoon !

Again I can't get out of what seems to be an elementary thing - why everything seems to be according to the help, but the result prints 0.0 ?

  double FractalDown_1 = iFractals(NULL,0,MODE_LOWER,1); Print("FractalDown_1=",FractalDown_1);

Why isn't the fractal value being extracted?

 
rapid_minus:

Good afternoon !

Again I can't get out of what seems to be an elementary thing - why everything seems to be according to the help, but the result prints 0.0 ?

Why isn't the fractal value being extracted?

You need at least three bars for a fractal