I am trying to get the up and down buy/sell arrows on the graph but not able to place it at every tick. Here is the code for my logic:
Kindly, suggest me what will make the code show up down arrow onTick function.
Where is the code in the OnTick()
you need to Create an Arrow by calling ArrowSellCreate(with parameters); in the OnTick()
Where is the code in the OnTick()
you need to Create an Arrow by calling ArrowSellCreate(with parameters); in the OnTick()
I simply did this:
void OnTick() { ArrowSellCreate(); ArrowBuyCreate(); }
It should give both arrows on each bar
There's a couple of libraries that do what you're attempting to write from scratch. I'd recommend the CChartObject classes. Here's a quickie example of repurposing the CChartObjectArrow class...
//+------------------------------------------------------------------+ //| TickArrows.mq5 | //| Copyright 2018, ;alskdjf;lakjsd | //| dasfasdf | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, ;alskdjf;lakjsd" #property link "dasfasdf" #property version "1.00" #property indicator_chart_window #include <ChartObjects\ChartObjectsArrows.mqh> class CTickArrow : public CChartObjectArrow { double m_last_bid; datetime m_last_time; public: void refresh(double bid,datetime bar_time); bool create(); }; //+------------------------------------------------------------------+ CTickArrow arrow; int OnInit() { if(!arrow.create()) return INIT_FAILED; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ 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[]) { arrow.refresh( close[rates_total-1], time[rates_total-1] ); return(rates_total); } //+------------------------------------------------------------------+ //src void CTickArrow::refresh(double bid,datetime bar_time) { if(!(bid != m_last_bid || TimeCurrent() > m_last_time + PeriodSeconds(_Period))) return; bool up = bid >= m_last_bid; m_last_bid = bid; m_last_time=bar_time; this.Price(0,bid); this.Time(0,bar_time+PeriodSeconds(_Period)); this.ArrowCode(up?(char)233:(char)234); this.Color(up?clrLime:clrRed); this.Anchor(up?ANCHOR_BOTTOM:ANCHOR_TOP); } //+------------------------------------------------------------------+ bool CTickArrow::create() { return this.Create(0,"display_arrow",0,0,0.0,char(233)); }
I simply did this:
It should give both arrows on each bar
This is because name of each arrow should be unique. In your case all the Sell arrows has the same name, "ArrowSell" , therefore you will encounter the error 4200..
A new arrow named "ArrowSell" cannot be made if there is an arrow already existing on the chart named "ArrowSell"... I suggest you to use loop to change the name of the arrows or if this is for an indicator(I know in this particular case you use OnTick() so it is for an EA) use buffers(arrays[]).. Hope that's clear.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am trying to get the up and down buy/sell arrows on the graph but not able to place it at every tick. Here is the code for my logic:
Kindly, suggest me what will make the code show up down arrow onTick function.