Trying to indicate on chart all open and close price of each trade

To add comments, please log in or register
Chim Wong
47
Chim Wong  

Hey guys, I wrote this code but really have no idea why it won't work. It is my first indicator. I have had experience with experts but really could use a helping hand here:

//+------------------------------------------------------------------+
//|                                                 Draw_History.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
double BOpen_Price[];
double BClose_Price[];
double SOpen_Price[];
double SClose_Price[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---------Bind Array----+
   bool BindBO=SetIndexBuffer(0,BOpen_Price);
   bool BindBC=SetIndexBuffer(1,BClose_Price);
   bool BindSO=SetIndexBuffer(2,SOpen_Price);
   bool BindSC=SetIndexBuffer(3,SClose_Price);
//---------Index Style---+
   SetIndexStyle(0,DRAW_ARROW,clrBlue);
   SetIndexArrow(0,241);
   SetIndexStyle(1,DRAW_ARROW,clrGreen);
   SetIndexArrow(1,242);
   SetIndexStyle(2,DRAW_ARROW,clrRed);
   SetIndexArrow(2,242);
   SetIndexStyle(3,DRAW_ARROW,clrGreen);
   SetIndexArrow(3,241);
//----------Set Arrow Label--------+

   SetIndexLabel(0,"Buy Order Entry");
   SetIndexLabel(1,"Buy Order Close");
   SetIndexLabel(2,"Sell Order Entry");
   SetIndexLabel(3,"Sell Order 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[])
                
                
                
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

void OnTick()
{
//--- indicator buffers mapping
      for(int n=OrdersHistoryTotal()-1;n<=0;n--)
   {
   bool SelectHistory=OrderSelect(n,SELECT_BY_POS,MODE_HISTORY);
   if(SelectHistory==1)
   {
   //-----------Select a Buy----------------+
   if(OrderType()==0)
   {
   BOpen_Price[n]=OrderOpenPrice();
   BClose_Price[n]=OrderClosePrice();
   }
   //-----------Select a Sell----------------+
   if(OrderType()==1)
   {
   SOpen_Price[n]=OrderOpenPrice();
   BClose_Price[n]=OrderClosePrice();
   }
   }
   if(SelectHistory==0)Comment("There is an error of "+GetLastError());
   Comment(n);
   }
   
}
William Roeder
19862
William Roeder  
  1. You are placing the nth order into the nth bar. Meaningless. Place the nth Order into the bar corresponding to the time of the Order.
  2. Don't use integers for True or false. Just if(condition) or if(!condition)
  3. Don't hard code numbers for Ordertype. Just use the appropriate symbol (OP_BUY).
  4. You will never see your error message because you remove it on the next line.
Zeegolf Golfpy
9
Zeegolf Golfpy  
whroeder1:
  1. You are placing the nth order into the nth bar. Meaningless. Place the nth Order into the bar corresponding to the time of the Order.
  2. Don't use integers for True or false. Just if(condition) or if(!condition)
  3. Don't hard code numbers for Ordertype. Just use the appropriate symbol (OP_BUY).
  4. You will never see your error message because you remove it on the next line.
Chim Wong
47
Chim Wong  
whroeder1:
  1. You are placing the nth order into the nth bar. Meaningless. Place the nth Order into the bar corresponding to the time of the Order.
  2. Don't use integers for True or false. Just if(condition) or if(!condition)
  3. Don't hard code numbers for Ordertype. Just use the appropriate symbol (OP_BUY).
  4. You will never see your error message because you remove it on the next line.

I saw that SetIndexBuffer only offers one dimensional array to be bound. How can I define time there? I guess I need another array to store iBarShift also?


Thank you for your reply :)

William Roeder
19862
William Roeder  
kei41202: I saw that SetIndexBuffer only offers one dimensional array to be bound. How can I define time there? I guess I need another array to store iBarShift also?
  1. Correct.
  2. You don't.
  3. Why do you need to store a shift? Why do you need time. What part of "Place the nth Order into the bar corresponding to the time" was unclear?
     BOpen_Price[n]=OrderOpenPrice();
    N is wrong. Find the bar index X corresponding to the time the order was open and store there.
To add comments, please log in or register