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

 
I've already asked, but I haven't heard back. Does anyone have a Range Bar Chart indicator with accumulation, i.e. combining unidirectional bars? It looks like this:
 

Guys, please advise - I downloaded the terminal set-up from brokerage company site, I want to test the owls with quotes of this particular brokerage company in the strategy tester, but when I press F2 and download quotes, the tester displays this window... Is it possible to download quotes from the selected brokerage company?


 
Help me get rid of the zero divide error in the EA.

Thank you in advance.

double BullSumm()
{
  double MySummBull=0;
  for(int Cnt=0;Cnt<OrdersTotal();Cnt++)
  { 
    OrderSelect(Cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()==OP_BUY)
    {
      MySummBull+=OrderOpenPrice()*OrderLots();
    }
  }
  return(MySummBull);
}
//--------------------------------------
double SummBullLots()
{
  double MySummBullLots=0;
  for(int Cnt=0;Cnt<OrdersTotal();Cnt++)
  { 
    OrderSelect(Cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()==OP_BUY)
    {
      MySummBullLots+=OrderLots();
    }
  }
  return(MySummBullLots);
}
//---------------------------------------
..............
..............
  double BullAveragePrice = NormalizeDouble(BullSummOpenPrice()/SummBullLots(),Digits);
...............
...............

 
charter:
Just as you were uploading to your now closed down terminal.
And I don't remember how the story was downloaded back then, please forgive me.
 
rustein:
Help me get rid of the zero divide error in the EA.

Thank you in advance.

A special case of this code is lack of buy orders. That is why it divides by zero.
 
Zhunko:
A particular case of the code is that there are no buy orders. That's why it divides by zero.

Thank you, I tried it with the condition:

int TotalBullOrders()
{
  int TotalBullOrders = 0;
  for(int Cnt=0;Cnt<OrdersTotal();Cnt++)
  { 
    OrderSelect(Cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderMagicNumber()==Magic && OrderType()==OP_BUY)
    {
      TotalBullOrders++;
    }
  }
  return(TotalBullOrders);
} 
 if(TotalBullOrders()>0){double BullAveragePrice = NormalizeDouble(BullSummOpenPrice()/SummBullLots(),Digits);}

it still gives an error.

 
rustein:

Thank you, I tried it with the condition:

It still gives me an error.

What difference does it make? If it doesn't go into the inside of the condition, it outputs zero. That's what it's divided by.
 
Zhunko:
What difference does it make? If it doesn't go into the inside of the condition, it's zero at the output. That's what it's divided by.
Yes, I see, thank you.

Put it that way, I don't know any other way.......)

//--------------------------------------
double SummBullLots()
{
  double MySummBullLots=0.000000000000000000000000000000001;
  for(int Cnt=0;Cnt<OrdersTotal();Cnt++)
  { 
    OrderSelect(Cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()==OP_BUY)
    {
      MySummBullLots+=OrderLots();
    }
  }
  return(MySummBullLots);
}
//---------------------------------------
..............
..............
  double BullAveragePrice = NormalizeDouble(BullSummOpenPrice()/SummBullLots(),Digits);
...............
...............

 
Good afternoon! In this version of stochastic I decided to add flat lines (on the chart)
on the overbought/oversold zones.

There was a problem with deleting "old" lines from the history. What is wrong and what should I pay attention to?

//+------------------------------------------------------------------+
//|                                              Stochastic_flat     |
//|                                         Copyright © 2012 Fox.RM  |
//|                                               fox.rm@mail.ru     |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012 Fox.RM"
#property link      "fox.rm@mail.ru"

//----
#property indicator_separate_window
#property indicator_buffers 4

//---- fan style
#property indicator_color1 Red
#property indicator_color2 Black
#property indicator_color3 Blue
#property indicator_color4 DarkGray

#property indicator_style1 0
#property indicator_style2 0
#property indicator_style3 0
#property indicator_style4 0
#property indicator_width4 2
#property indicator_level1 88.2
#property indicator_level2 11.8
 
#property indicator_levelcolor DarkGray
#property indicator_levelstyle 0

//---- basic fan indicator parameters
extern bool Show_STOCH_1=true;
extern int K_period1=13;
extern int S_period1=1;
extern bool Show_STOCH_2=true;
extern int K_period2=34;
extern int S_period2=1;
extern bool Show_STOCH_3=true;
extern int K_period3=89;
extern int S_period3=1;
extern bool Show_STOCH_4=true;
extern int K_period4=233;
extern int S_period4=1;
extern int delete=2;

//---- indicator buffers
double MainBuffer1[];
double MainBuffer2[];
double MainBuffer3[];
double MainBuffer4[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {
//---- stochastic line 1 (fast)
   if(Show_STOCH_1 ==true){Show_STOCH_1=DRAW_LINE; }
   else 
    {Show_STOCH_1=DRAW_NONE; }
   SetIndexBuffer(0,MainBuffer1);
   SetIndexStyle(0,Show_STOCH_1,0);
   SetIndexLabel(0,"fast WPR  ( "+K_period1+" )");
   
//---- stochastic line 2 (basic)
   if(Show_STOCH_2 ==true){Show_STOCH_2=DRAW_LINE; }
   else 
    {Show_STOCH_2=DRAW_NONE; }
   SetIndexBuffer(1,MainBuffer2);
   SetIndexStyle(1,Show_STOCH_2);
   SetIndexLabel(1,"basic WPR ( "+K_period2+" )");
   
//---- stochastic line 3 (flat)
   if(Show_STOCH_3 ==true){Show_STOCH_3=DRAW_LINE; }
   else 
    {Show_STOCH_3=DRAW_NONE; }
   SetIndexBuffer(2,MainBuffer3);
   SetIndexStyle(2,Show_STOCH_3,0);
   SetIndexLabel(2,"slow WPR ( "+K_period3+" )");
   
//---- stochastic line 4 (control)
   if(Show_STOCH_4 ==true){Show_STOCH_4=DRAW_LINE; }
   else
    {Show_STOCH_4=DRAW_NONE; }
   SetIndexBuffer(3,MainBuffer4);
   SetIndexStyle(3,Show_STOCH_4,0,2);
   SetIndexLabel(3,"control WPR ( "+K_period4+" )");

   
//---- name for DataWindow and indicator subwindow label   
   IndicatorShortName("Stochastic_flat");
  }

//----
   return(0);

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+

int deinit()
  {
//---- 
   ObjectsDeleteAll();
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Stochastic_fan                                                   |
//+------------------------------------------------------------------+

int start()
  {
   int    i,shift,limit,y=0,counted_bars=IndicatorCounted();
   double x1,x2;
   datetime y1,y11,y2,y22;
//---- Plot defined timeframe on to current timeframe   
 
   limit=Bars-counted_bars;
   //---stroim stohastik
   for(i=0,y=0;i<limit;i++,y++)
     {
      MainBuffer1[i]=iStochastic(NULL,0,K_period1,1,S_period1,0,0,MODE_MAIN,y);
      MainBuffer2[i]=iStochastic(NULL,0,K_period2,1,S_period2,0,0,MODE_MAIN,y);
      MainBuffer3[i]=iStochastic(NULL,0,K_period3,1,S_period3,0,0,MODE_MAIN,y);
      MainBuffer4[i]=iStochastic(NULL,0,K_period4,1,S_period4,0,0,MODE_MAIN,y);
    
     //---flat zona
  
     
     if (MainBuffer1[i] < 11.8) //---pervoe uslovie
     {
     x1=Low[i];
     y1=Time[i]; //--- opredelyaem koordinaty dlya x1,y1
     }
     if (MainBuffer1[i] > 88.2) //---vtoroe uslovie
     {
     x2=High[i];
     y2=Time[i];   //--- opredelyaem koordinaty dlya x2,y2
     }
     }
    for(i=Bars; i>0; i--)
    {
     //--- opredelyaem koordinaty dlya x11,y11 
     if (Low[i]<x1)
     {
     y11=Time[i];
     }
     //--- opredelyaem koordinaty dlya x22,y22
     if (High[i]>x2)
     {
     y22=Time[i];
     }
     }    
     
   
   string up_line = "upline";
  string down_line = "downline";
     flatlineup(up_line+TimeToStr(Time[i]), y2,x2,y22,x2,Red,1);
     flatlinedown(down_line+TimeToStr(Time[i]), y1,x1,y11,x1,Blue,1);
  
    
   dellline(up_line,i);
     
     //----
     
   return(0);
  }
//+------------------------------------------------------------------+
void flatlineup(string labebe,datetime time1,double price1,datetime time2,double price2,color colir, int W)
  {
     ObjectCreate(labebe, OBJ_TREND, 0,time1,price1,time2,price2);
   ObjectSet(labebe, OBJPROP_COLOR, colir);
   ObjectSet(labebe, OBJPROP_STYLE,0);
   ObjectSet(labebe, OBJPROP_RAY,0);
   ObjectSet(labebe, OBJPROP_WIDTH,W);   
   ObjectSet(labebe, OBJPROP_BACK, true);
   }
  void flatlinedown(string labebe1,datetime time1,double price1,datetime time2,double price2,color colir, int W)
  {
   ObjectCreate(labebe1, OBJ_TREND, 0,time1,price1,time2,price2);
   ObjectSet(labebe1, OBJPROP_COLOR, colir);
   ObjectSet(labebe1, OBJPROP_STYLE,0);
   ObjectSet(labebe1, OBJPROP_RAY,0);
   ObjectSet(labebe1, OBJPROP_WIDTH,W);   
   ObjectSet(labebe1, OBJPROP_BACK, true);
    }
   
void dellline(string name_line, int i)  //--- первый вариант с удалением линий
  {
    string name = ObjectName(i);
    if (StringFind(name,name_line)!=-1)ObjectDelete(name);

 // if (StringFind(name,name_line)!=-1)del1++;
 // if (del1>2)ObjectDelete(name);
   }
void dellline(string name_line)  //--- второй вариант с удалением линий  
{
string name, dellname; 
bool del = false;
for(int i=ObjectsTotal(); i>=0;i--)
    {
if (del == false){ //---при этом условии должна происходить идентификация первой линии 
name = ObjectName(i); //--выполняется при первом обращении к функции
dellname=name;
del = true;}
if (del == true){
if (StringFind(dellname,name_line)!=-1)ObjectDelete(dellname);
dellname=name;}
}   
} 
    //---Были и промежуточные варианты, которые также не дали желаемого результата.

In the version below, it worked. But not quite. The upper lines are deleted as new ones appear, the lower lines are deleted immediately. Why?

//------ функция удаляющая ненужные линии

void dellline(string name_line_up, string name_line_down) 
{
string name_l;
int obj=ObjectsTotal(OBJ_TREND); // --- в этой версии интуитивно добавил свойство OBJ_TREND
for (int i=obj; i>=0; i--)
{
name_l=ObjectName(i);
if(StringFind(name_l,name_line_up)!=-1)ObjectDelete(name_l);
if(StringFind(name_l,name_line_down)!=-1)ObjectDelete(name_l);
}}

Here we have an additional question why the function did not work as it should without adding

OBJ_TREND because it doesn't seem to make any fundamental changes in this case?

Then I ran some experiments with line names in the main code.

//-------------- первый вариант (рабочий)

string up_line = "upline_", down_line = "downline_";
 
     flatlineup(up_line+TimeToStr(Time[i]), y2,x2,y22,x2,Red,1);
     flatlinedown(down_line+TimeToStr(Time[i]), y1,x1,y11,x1,Blue,1);
     dellline(up_line, down_line);

//---TimeToStr(Time[i]) указывал в имени тренд лайн в теле функции

//--------------- второй вариант (нерабочий)

string up_line = "upline_"+TimeToStr(Time[i]); //--или пробовал StringConcatenate()
string down_line = "downline_"+TimeToStr(Time[i]); //--или пробовал StringConcatenate()
 
     flatlineup(up_line, y2,x2,y22,x2,Red,1);
     flatlinedown(down_line, y1,x1,y11,x1,Blue,1);
     dellline(up_line, down_line);

TimeToStr(Time[i]) was specified in a variable in the main code.


Question. Why did the second variant not work (meaning that the function

dellline(), when applied to the second variant, did not remove lines with names assigned to

to up_line and down_line variables?

И last question I'm going to duplicate it from a previous post, it's on the screenshot. The answer to it can be found

could not.

Thank you!

Files:
 
Could you please tell me if there is an indicator that displays the number of open positions at a given time? Even better, if it shows how many of them are BAY and how many are SELL.
Reason: