Coding help - page 237

 

Hi there,

I have some brief coding questions, my MT4 seems to have migrated towards MQL5.

Certain delete code blocks are not working anymore:

Underneath I get the error message:

'(' Object Pointer expected.

//+----------------------------------------------------------------------------+//| Close and delete |

//+----------------------------------------------------------------------------+

if(sell)if(oppositeclose)close(OP_BUY);

if(buy)if(oppositeclose)close(OP_SELL);

if(hidetp || hidesl){hideclose(OP_BUY);hideclose(OP_SELL);}

if(usetimeout && onetime){closetime(OP_BUY);closetime(OP_SELL);}

if(onecancelother){if(totalsell>0){delete(OP_BUYSTOP);delete(OP_BUYLIMIT);}if(totalbuy>0){delete(OP_SELLSTOP);delete(OP_SELLLIMIT);}}

Underneath I get the error messages: 'delete' - name expected and

'}' - expressions are not allowed on a global scope

void delete(int type){

if(OrdersTotal()>0){

for(i=OrdersTotal();i>=0;i--){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(type!=6){

if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==type){

OrderDelete(OrderTicket());

}

}

if(type==6){

if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP

|| OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT){

OrderDelete(OrderTicket());

}

}

}

}

}

Could someone please help?

Thank you in advance!

 

Hi fellow traders/coders!

I hope someone can help me out here.

Searching and trying the few EA's around, i still haven't found what i'm looking for.

Perhaps i'm looking for something that is hard to find or i'm not trying my hardest :-)

I trade also a SR system by drawing my lines and create temporary channels. Is there something that can execute positions when price reaches the lines? The thing is that it needs to be capable of opening positions every time the price hits the lines. Red lines for sell, blue for buy, yellow for SL and the green ones for TP. So no one time only deals or OCO.

Thanks in advance!!

Files:
sr.png  34 kb
 
daytrade:
Hi fellow traders/coders!

I hope someone can help me out here.

Searching and trying the few EA's around, i still haven't found what i'm looking for.

Perhaps i'm looking for something that is hard to find or i'm not trying my hardest :-)

I trade also a SR system by drawing my lines and create temporary channels. Is there something that can execute positions when price reaches the lines? The thing is that it needs to be capable of opening positions every time the price hits the lines. Red lines for sell, blue for buy, yellow for SL and the green ones for TP. So no one time only deals or OCO.

Thanks in advance!!

Did you check the EA from this thread : https://www.mql5.com/en/forum/176382 ?

 

Modify Stop Loss

Hello all,

Does anyone know why my modify stop loss order isn't working correctly?

The stop loss flicks very rapidly between the DonchianLowM5 and OrderOpenPrice when the DonchianLowM5 moves above the OrderOpenPrice.

This is the code (sorry I don't know how to paste it properly).

//--- Movement of stop loss

if (OrdersTotal() > 0)

{

for (int i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderType() == OP_BUY)

{

if (OrderStopLoss() < OrderOpenPrice())

{

if (DonchianLowM5 > OrderStopLoss())

{

OrderModify(OrderTicket(), OrderOpenPrice(), DonchianLowM5, OrderTakeProfit(), OrderExpiration(), Green);

}

}

if (OrderStopLoss() > OrderOpenPrice())

{

if (DonchianLowH4 <= OrderOpenPrice())

{

OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration(), Green);

}

}

if (OrderStopLoss() >= OrderOpenPrice())

{

if (DonchianLowH4 > OrderStopLoss())

{

OrderModify(OrderTicket(), OrderOpenPrice(), DonchianLowH4, OrderTakeProfit(), OrderExpiration(), Green);

}

}

}

Some what puzzled.

The purpose of the code is to:

1. Modify the stop loss to track the lower Donchian Channel on the M5 Chart up to OrderOpenPrice. The stop loss is not to follow the Donchian Channel on the M5 chart beyond the OrderOpenPrice. It moves to break even.

2. Some times a large candle will close beyond the OrderOpenPrice and hence the second section of the code is to bring it back to break even only.

3. Stop loss is to track the Donchian Low on the H4 chart once the Donchian Channel on the H4 chart exceeds OrderOpenPrice.

The Donchian Channels are coded as follows:

DonchianLowM5 = iLow(NULL, TimingChart, iLowest(NULL, TimingChart, MODE_LOW, TimingDNCPeriod, TimingChartShift + 1));

DonchianHighM5 = iHigh(NULL, TimingChart, iHighest(NULL, TimingChart, MODE_HIGH, TimingDNCPeriod, TimingChartShift + 1));

I have checked the journal and the stop loss modifies to EXACTLY the OrderOpenPrice (its not below, even by a fraction pip which would cause it to track the Donchian Low on the M5 chart.

Does anyone know what it is doing this?

 
crsnape@btinternet.com:
Hello all,

Does anyone know why my modify stop loss order isn't working correctly?

The stop loss flicks very rapidly between the DonchianLowM5 and OrderOpenPrice when the DonchianLowM5 moves above the OrderOpenPrice.

This is the code (sorry I don't know how to paste it properly).

//--- Movement of stop loss

if (OrdersTotal() > 0)

{

for (int i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderType() == OP_BUY)

{

if (OrderStopLoss() < OrderOpenPrice())

{

if (DonchianLowM5 > OrderStopLoss())

{

OrderModify(OrderTicket(), OrderOpenPrice(), DonchianLowM5, OrderTakeProfit(), OrderExpiration(), Green);

}

}

if (OrderStopLoss() > OrderOpenPrice())

{

if (DonchianLowH4 <= OrderOpenPrice())

{

OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration(), Green);

}

}

if (OrderStopLoss() >= OrderOpenPrice())

{

if (DonchianLowH4 > OrderStopLoss())

{

OrderModify(OrderTicket(), OrderOpenPrice(), DonchianLowH4, OrderTakeProfit(), OrderExpiration(), Green);

}

}

}

Some what puzzled.

The purpose of the code is to:

1. Modify the stop loss to track the lower Donchian Channel on the M5 Chart up to OrderOpenPrice. The stop loss is not to follow the Donchian Channel on the M5 chart beyond the OrderOpenPrice. It moves to break even.

2. Some times a large candle will close beyond the OrderOpenPrice and hence the second section of the code is to bring it back to break even only.

3. Stop loss is to track the Donchian Low on the H4 chart once the Donchian Channel on the H4 chart exceeds OrderOpenPrice.

The Donchian Channels are coded as follows:

DonchianLowM5 = iLow(NULL, TimingChart, iLowest(NULL, TimingChart, MODE_LOW, TimingDNCPeriod, TimingChartShift + 1));

DonchianHighM5 = iHigh(NULL, TimingChart, iHighest(NULL, TimingChart, MODE_HIGH, TimingDNCPeriod, TimingChartShift + 1));

I have checked the journal and the stop loss modifies to EXACTLY the OrderOpenPrice (its not below, even by a fraction pip which would cause it to track the Donchian Low on the M5 chart.

Does anyone know what it is doing this?

You are using DonchianLowM5 and DonchianLowH4 (I am assuming that those are different values). That could cause you a problem

 

Hello Mladen,

Thanks for your reply.

DonchianLowM5 and DonchianLowH4 are different values but they each have their own purpose. The DonchianLowM5 is used to adjust the SL to break even in the early stages of a trade. The DonchianLowH4 adjusts the SL as a trailing stop mechanism. This should only come into effect once the DonchianLowH4 surpasses OrderOpenPrice.

I have looked into this issue a bit more and may have found the problem. I wanted to determine whether the OrderModify function was repositioning the SL exactly as OrderOpenPrice. But it isn't. OrderOpenPrice in my journal is stated to be 1.12224, 5 digit precision, and yet the Print function below states OrderOpenPrice is only 4 digits. So the SL will be using this 4 figure digit, and not the 5. I need it to use the 5 digits.

How can I have the ordermodify adjust SL to EXACTLY the orderopenprice at 5 digits?

This is my code:

{

OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration(), Green);

Print("SL modified to Order Open Price ", OrderOpenPrice());

}

I have tried this but it doesnt work:

OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice(), 5), OrderTakeProfit(), OrderExpiration(), Green);

Print("SL modified to Order Open Price ", OrderOpenPrice());

My broker has 5 digits because the journal confirms the price it opened the order at 1.12224.

I hope my explanation makes sense. Any ideas?

 
crsnape@btinternet.com:
Hello Mladen,

Thanks for your reply.

DonchianLowM5 and DonchianLowH4 are different values but they each have their own purpose. The DonchianLowM5 is used to adjust the SL to break even in the early stages of a trade. The DonchianLowH4 adjusts the SL as a trailing stop mechanism. This should only come into effect once the DonchianLowH4 surpasses OrderOpenPrice.

I have looked into this issue a bit more and may have found the problem. I wanted to determine whether the OrderModify function was repositioning the SL exactly as OrderOpenPrice. But it isn't. OrderOpenPrice in my journal is stated to be 1.12224, 5 digit precision, and yet the Print function below states OrderOpenPrice is only 4 digits. So the SL will be using this 4 figure digit, and not the 5. I need it to use the 5 digits.

How can I have the ordermodify adjust SL to EXACTLY the orderopenprice at 5 digits?

This is my code:

{

OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration(), Green);

Print("SL modified to Order Open Price ", OrderOpenPrice());

}

I have tried this but it doesnt work:

OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice(), 5), OrderTakeProfit(), OrderExpiration(), Green);

Print("SL modified to Order Open Price ", OrderOpenPrice());

My broker has 5 digits because the journal confirms the price it opened the order at 1.12224.

I hope my explanation makes sense. Any ideas?

The fact that you get the price printed with 4 digit precision is not the issue : simply use this Print(DoubleToStr(OrderOpenPrice(),Digits)); and you will get a correct printout. Something else is the issue and I thought that if you are comparing to two completely different prices could cause you those problems

 

Oh right.

What do you mean? Have I got my parenthesis structure wrong?

The code is supposed to choose either the DonchianLowM5 or DonchianLowH4 depending on the situation.

May be my parenthesis build up, build down is wrong for each code element.

 

Try simplifying the code. Something like the attached one

PS: check if that is the logic that you had in mind

Files:
 

hello, here I am two indicators, one based on the RSI and the other on the strength index, but the problem asks me rsi looking curves, it indicates not that I want, if you have the solution, obviously I can send you the file if needed thank you for your help ... sorry for the English "google traductor"

Reason: