When my EA written with mql4 places an order using OrderSend(), the order is placed, but does not show on the chart - mql4

I wrote an EA in mql4. It places orders just fine using OrderSend(), but the horizontal lines showing the open price, SL and TP do not show up on the chart like it does when I manually place a trade. Not sure what I need to do to make it show the trade on the chart.
Here is the code I used to place the order:
OrderNumber = OrderSend(order_symbol, order_type, lots, ask, 0, sl, tp, comment, magic_number, 0, clrBlue);

I tried loading me EA on another PC and the trade lines show up. So on the PC that this wasn't working I uninstalled MT4 and reinstalled, working now.

Related

MQL4 gets different data than the MT4 History Center shows

I'm quite new to MQL so this may be a misunderstanding.
This code:
Print( TimeToStr( iTime(NULL,PERIOD_M5,i), TIME_DATE|TIME_MINUTES), iOpen(NULL,PERIOD_M5,i), iHigh(NULL,PERIOD_M5,i), iLow(NULL,PERIOD_M5,i), iClose(NULL,PERIOD_M5,i) );
Prints this:
2023.01.05 23:25, 0.91648, 0.91678, 0.91636, 0.91676
If I export data from the History Center I get slightly different numbers:
2023.01.05T23:25, 0.91646 ,0.91675, 0.91633 ,0.91675, 146
The values are just a tiny bit smaller. This is consistent - ALL of the values exported from the History Center are a bit lower than what I see when I examine the data with iOpen() etc. The difference seems to range from 0.1 to 0.3 pips.
I assume this is a Bid vs Ask thing. Is it? I understand the iOpen() etc returns Bid prices. But does the History database contain both Bid and Ask? Is there a way to see both prices?
Or it it just guessing? If so, it does not seem to be adjusting the prices consistently.
Edit: I am running in the Strategy Tester.
Edit2: Today I downloaded a bunch of M1 data from Dukascopy and imported it into MT4 History Center. Now I get exactly the results I expect from my program.
But my question stands, about the data MT4 downloads from the broker.

iFractals MLQ5 usage not understood

Here is the code that I thought and tried. I thought that it was the right way to buy and sell for the Fractals signals. But getting buy and sell signals simultaneously.
double UP[],DOWN[];
double fractal_output = iFractals(_Symbol,_Period);
ArraySetAsSeries(UP,true);
ArraySetAsSeries(DOWN,true);
CopyBuffer(fractal_output,0,0,5,UP);
CopyBuffer(fractal_output,1,0,5,DOWN);
if (UP[1])
{
Comment("BUY");
trade.Buy(0.1);
}
if (DOWN[1])
{
Comment("SELL");
trade.Sell(0.1);
}
I don't understand how I can plan to buy and sell using the iFractals function indicator in my MQL5. What improvements need to be done?
A double fractal_output should be int not double and initialized in the OnInit(){...} just once, not each tick.
Make sure you understand which fractal is obtained when accessing UP[1] - it seems to be 0,1,2,3,4 (left to right), so you are asking for fractal 3 bars before the current Bar.
Alternatively you can get a value before the current Bar (most probably it is zero until next bar after current starts).
Make sure that you have copied the buffer correctly (it is possible that it is not copied and UP[1] may throw out-of-range error - for that reason CopyBuffer returns a number of elements actually copied (so if CopyBuffer()!=5){print();return;})
What do you expect to see when calling if(UP[1]){} ?
A buffer might take both positive values and EMPTY_VALUE (== 2^31-1).
It is better to check the value of the buffer: if(UP[i]>0){} or if(UP[i]!=EMPTY_VALUE){...}
Do not forget about a special case, when some candle has both an upper and a lower fractal - What to do in that corner-case?
It will open a Long and then open a Short (so it may close the Buy by opening a Short).
Probably you need check the open orders before that or open bar - otherwise you'll have many positions opened during one candle.
Tester will help you find other problems that you could miss when planning the EA.

MQL create new candles

the bid price in my MT4 are roughly 1 pip below what my broker's trade prices are. The reason is that the price server serving the charts has a spread of 2.5 pips where my broker is much narrower in spreads (0.2 pips).
I need to redraw the candles on the fact that everything should be about 1 pip higher than what it is being drawn.
I've studied histogram drawing but it doesn't help me with the drawing of the entire candle.
Is it possible to redraw the candle in its entirety about 1 pip higher than what the price server is giving me?
If the candles could be drawn on the halfway mark between bid and ask, it would work close on correctly.
Add all candles in array (CopyRates or loop over them from Bars-1 to 0) then create a new symbol as it is shown in PeriodConverter and write all candles from 0 to last to have an offline chart, include your manipulations with price here. Then update the chart if you need to have live chart, or resave under existing name in order to backtest(do not forget to disconnect first, otherwise mt4 will upload quotes from the server and overwrite over your file)

Indicore SDK Strategy Development - How to draw simple dots on a chart?

I am trying to develop a simple Indicore SDK strategy (for FXCM Marketscope 2.0) with LuaEditor and I have a simple question. The Indicore SDK documentation is very poor and devoid of context and examples, so I can't figure out how to print a simple dot on the screen under a price bar. Basically what I am trying to do is show where my custom stop loss is under the price bar.
In indicator development, elements can be drawn by creating output streams (instance:addStream) in the Prepare function. Unfortunately, output streams don't seem to be a part of strategy development and give the runtime error "attempt to call 'addStream' (a nil value)" when I try to run it in Lua Strategy Debugger.
So in the ExtUpdate() function, how do you draw a simple dot under the closing price minus 10 pips?
function ExtUpdate(id, source, period)
if period > first and source:hasData(period) then
--HOW DO YOU DRAW A DOT HERE???
end
end
Strategies are not allowed to draw, only indicators can do it. Indicore 3.0 indicators now can trade, so you write an indicator and add all the trading functionality into it.

write a script in mql4 to edit symbol window

I am trying to write my first script in MQL4 and had hopefully a few basic questions.
1) I am aware that I can write a script and drag and drop it on a symbol window to execute the script. I was wondering though if there was a way to reference a symbol window through the code?
Is it just like the code below,
WindowHandle("EURUSD", PERIOD_M1)
2) Is there anyway to specify the time horizon of a symbol window. For example say I want the symbol window to show me the EURUSD 1 minute data from 4th March 2012 10:10 am to 4th December 2012 4pm? Can you also specify the number of bars to show on the chart at anyone time?
3) Can you draw a line on the chart using a script? I think I read you cannot - that you would need to write a custom indicator? I understand using a script however that you can annotate the chart with a text object though.
A3: Yes, you can
A2: No, any code is sub-ordinated to the pre-set MT4.Graph instance
In other words, your code ( any MQL4 ( well, valid as far as Build 711 )) cannot moderate the outer-container ( the MT4.Graph ), be it zoom, Y-scale, changing it's Period and other "given" features, some of which may be editable by user ( but not by the code )
A1: No, but ... might be you read about some
This is rather dangerous zone. Imagine a MT4 Terminal, that has a live-session, if there were such WindowHandle( "EURUSD", PERIOD_M1 ) and if there were six graphs for [EURUSD,M1]. Which way should the identification / execution follow? No, this is left intentionally as a "Human-step", because executing any kind of code is associated with risks and may create huge if not fatal losses ( as the code runs blind and deaf and VERY FAST ).
While there are some dirty techniques to identify/swap MT4-"window" these techniques are highly dependent on O/S services. For normal use, I would dare rely on any of those I have read about so far.

Resources