This line
double bearish = iClose(_Symbol,PERIOD_CURRENT,0) < iOpen(_Symbol,PERIOD_CURRENT,0)
is missing a closing semi-colon;
Here
for (int i=PositionsTotal()-1; i >=0; i--) } {
You have a closing bracket followed by opening, should be reversed, but also there is no code in the loop then.
Same thing here
if (PositionGetInteger(POSITION_TYPE)==ORDER_TYPE_SELL) } {
double bullish = iClose(_Symbol,PERIOD_CURRENT,0) > iOpen(_Symbol,PERIOD_CURRENT,0); double bearish = iClose(_Symbol,PERIOD_CURRENT,0) < iOpen(_Symbol,PERIOD_CURRENT,0);
The results are bools but you are assigning them to double variables????
Please indent your code properly. You can do this with the auto-indentation in your code editor (Tools - Styler).
hi lippmaje,
thanks for the help.
This line
is missing a closing semi-colon;
Here
You have a closing bracket followed by opening, should be reversed, but also there is no code in the loop then.
Same thing here
HI Arthur,
thanks for this great help, i am going to correct the code as you say.
The results are bools but you are assigning them to double variables????
HI Keith,
Thank you for correcting me. Infact i was a bit confused about bool variables, thanks to clarify.
You make one and the same gross mistake: you create a headlining indicator AT EVERY TICK!
Remember: in MQL5, the indicator handle is CREATED ONCE !!! And this is done in OnInit ()!
You make one and the same gross mistake: you create a headlining indicator AT EVERY TICK!
Remember: in MQL5, the indicator handle is CREATED ONCE !!! And this is done in OnInit ()!
HI Vladimir,
Thanks for your help.
double myMovingAverageArray[]; int movingAverageDefinition = iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE); ArraySetAsSeries(myMovingAverageArray,true); CopyBuffer(movingAverageDefinition,0,0,21,myMovingAverageArray); double myMovingAverageValue=myMovingAverageArray[0]; double bullish = iClose(_Symbol,PERIOD_CURRENT,0) > iOpen(_Symbol,PERIOD_CURRENT,0); double bearish = iClose(_Symbol,PERIOD_CURRENT,0) < iOpen(_Symbol,PERIOD_CURRENT,0)
so you means this part should be moved to the oninit. Would you please check if the trailing is well coded also.
thank you very much for the help
HI Vladimir,
Thanks for your help.
so you means this part should be moved to the oninit. Would you please check if the trailing is well coded also.
thank you very much for the help
First, please correct your code - move the creation of the indicator handle to OnInit (please start reading the Documentation - there are lots of examples there). After that show your code. And only then can I watch.
The parenthesis are correctly opened at line 41 and close at line 164, but there, you are confused :
if (PositionsTotal() == 0) { <---- OPENED OK for (int i = PositionsTotal() - 1; i >= 0; i--) <---- NO ";" ? Looping what ? NOT OK } <--- CLOSED OK //////////////////////////// { <--- Opening what ? NOT OK string symbol = PositionGetSymbol(i); if (_Symbol == symbol) if (PositionGetInteger(POSITION_TYPE) == ORDER_TYPE_BUY) <--- possible to use indentation that way but not to let it opened, NOT OK } <---- Closing what ? NOT OK /////////////////////////////// { <---- Opening what ? NOT OK ulong PositionTicket = PositionGetInteger(POSITION_TICKET); double TakeProfit = NormalizeDouble(Ask + 250 * _Point, Digits); double CurrentStopLoss == PositionGetDouble(POSITION_SL); if (CurrentStopLoss < SL) trade.PositionModify(PositionTicket, (currentStopLoss + 10 * _Point), 0); <----- Correct syntax with indentation, it is closed ";" OK } <--- Closing what ? NOT OK

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
I am unable to correct these two errors when compiling. Can anyone please help me to solve these two errors, thanks. Also i am new to MQl5 programming (Still learning and practicing), here is my code i would appreciated if anyone can correct if there is any error with a bit of explanation and showed me if there is better way to write it. It's a simple EA to take buy position when last candle open and close above moving average and sell position when last candle open and close below moving average with TakeProfit and StopLoss and TrailingStop.
thanks in advance